customized products bug in cart



  • in TB 1.0.3: when you add say 3 text fields for customization in BO product and you add to cart, the sub-total line in cart shows the wrong price. however the total shows the correct amount:
    0_1515707933857_2018-01-12 10_58_22-Order - My Store.jpg



  • I dont see that problem in 1.0.x, so I assume it’s been fixed.
    0_1515785717140_Capture.PNG



  • the problem only happens when you have combinations. can you please test again with a product that has combinations?



  • sure…stand by



  • I have confirmed your issue. Lets hope they can find a solution for it soon. As a matter of fact I found another error on doing so. When I try to decrease the number of items, I get this…
    0_1515787546238_Capture.PNG



  • The problem lies in classes/Cart.php, when I take the one from ps1.6.1.17 it works fine. So…more looking into it.



  • Might be something minor just like the Webservice issue that was fixed the other day.



  • I’m getting close, the problem seems to be in the function _updateCustomizationQuantity…



  • This seems to have fixed it for me, give it a try…

    Replace the function in /classes/Cart.php, protected function _updateCustomizationQuantity, with the following code…

        protected function _updateCustomizationQuantity($quantityChange, $idCustomization, $idProduct, $idProductAttribute, $idAddressDelivery, $operator = 'up')
        {
            // Link customization to product combination when it is first added to cart
            if (empty($idCustomization)) {
                $customization = $this->getProductCustomization($idProduct, null, true);
                foreach ($customization as $field) {
                    if ($field['quantity'] == 0) {
                        Db::getInstance()->execute('
    					UPDATE `'._DB_PREFIX_.'customization`
    					SET `quantity` = '.(int) $quantityChange.',
    						`id_product_attribute` = '.(int) $idProductAttribute.',
    						`id_address_delivery` = '.(int) $idAddressDelivery.',
    						`in_cart` = 1
    					WHERE `id_customization` = '.(int) $field['id_customization']);
                    }
                }
            }
    
            /* Deletion */
            if (!empty($idCustomization) && (int) $quantityChange < 1) {
                return $this->_deleteCustomization((int) $idCustomization, (int) $idProduct, (int) $idProductAttribute);
            }
    
            /* Quantity update */
            if (!empty($idCustomization)) {
                $result = Db::getInstance()->getRow('SELECT `quantity` FROM `'._DB_PREFIX_.'customization` WHERE `id_customization` = '.(int) $idCustomization);
                if ($result && Db::getInstance()->NumRows()) {
                    if ($operator == 'down' && (int)$result['quantity'] - (int) $quantityChange < 1) {
                        return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customization` WHERE `id_customization` = '.(int) $idCustomization);
                    }
    
                    return Db::getInstance()->execute('
    					UPDATE `'._DB_PREFIX_.'customization`
    					SET
    						`quantity` = `quantity` '.($operator == 'up' ? '+ ' : '- ').(int) $quantityChange.',
    						`id_address_delivery` = '.(int) $idAddressDelivery.',
    						`in_cart` = 1
    					WHERE `id_customization` = '.(int) $idCustomization);
                } else {
                    Db::getInstance()->execute('
    					UPDATE `'._DB_PREFIX_.'customization`
    					SET `id_address_delivery` = '.(int) $idAddressDelivery.',
    					`in_cart` = 1
    					WHERE `id_customization` = '.(int) $idCustomization);
                }
            }
            // refresh cache of static::_products
            $this->_products = $this->getProducts(true);
            $this->update();
    
            return true;
        }
    

    if this works for everyone, I’ll make a pull request for it…



  • Does replacing it fix it for you? It only makes it worse here. I remember this function was changed to fix desynchronization issues with the customization tables.
    Adding a product without customizations, then adding the same with customizations and removing the one without would empty the cart, but leave the customizations in the database. Then there were a few extra steps, that I forgot, but they could crash the entire cart, because the store was trying to add a product with/without customizations while the customizations were already there in the database. I hope you guys are following this 😛

    Now, the latest changes seem to have fixed these issues for products without attributes. I think we just need to find a solution for the products with attributes, which should solve it for all cases.



  • 0_1515841623552_minusisthree.png

    The fact that this error shows when I click the button to decrease by just one makes me think that the customization table is okay, but the quantity calculation in the Cart.php file just is not.

    Another confirmation of this theory is the screen after a refresh:
    0_1515841720062_oneitem.png

    It removed the customization (1 - 1 = 0), but didn’t bother removing the product, because 4 - 1 = 3 > 0. Now I am not sure why it shows a quantity of 1, but this could have been a correction, since there is only 1 item in stock.



  • It seems like it works for me, I dont understand I guess what you’re saying. I can add, and delete items in the cart with no issue. If this fix isn’t the correct solution, at least we know the function causing the issue, and you can fix it. I made a video about it, but cant seem to share it here anymore. 😢
    Maybe this will work…



  • @mdekker I’ve commented on few lines in github on Cart.php.
    Check them when you have time, because I believe they might help.



  • How about this one, it only changes two lines from the original 1.0.x file

        protected function _updateCustomizationQuantity($quantityChange, $idCustomization, $idProduct, $idProductAttribute, $idAddressDelivery, $operator = 'up')
        {
            // Link customization to product combination when it is first added to cart
            if (empty($idCustomization) && $operator === 'up') {
                $customization = $this->getProductCustomization($idProduct, null, true);
                foreach ($customization as $field) {
                    if ((int) $field['quantity'] === 0) {
                        Db::getInstance()->update(
                            'customization',
                            [
                                'quantity'             => (int) $quantityChange,
                                'id_product'           => (int) $idProduct,
                                'id_product_attribute' => (int) $idProductAttribute,
                                'id_address_delivery'  => (int) $idAddressDelivery,
                                'in_cart'              => true,
                            ],
                            '`id_customization` = '.(int) $field['id_customization']
                        );
                    }
                }
            }
    
            /* Quantity update */
            if (!empty($idCustomization)) {
                $result = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
                    (new DbQuery())
                        ->select('`quantity`')
                        ->from('customization')
                        ->where('`id_customization` = '.(int) $idCustomization)
                );
    
                if ($operator === 'down' && ((int) $result - (int) $quantityChange) < 1) {
                    return Db::getInstance()->delete('customization', '`id_customization` = '.(int) $idCustomization);
                }
    
                return Db::getInstance()->update(
                    'customization',
                    [
                        'quantity'            => ['type' => 'sql', 'value' => '`quantity` '.($operator === 'up' ? '+' : '-').(int) $quantityChange],
                        'id_address_delivery' => (int) $idAddressDelivery,
                        'in_cart'             => true,
                    ],
                    '`id_customization` = '.(int) $idCustomization
                );
            }
            // refresh cache of static::_products
            $this->_products = $this->getProducts(true);
            $this->update();
    
            return true;
        }
    


  • yes, for me this fixes the problem with wrong sub totals in cart and also when you delete the customized product from the cart, it removes the product completely (as intended I guess…)



  • @yaniv14 and @SLiCK_303
    Thank you very much for the suggestions. They seemed to have fixed all the issues I had with them.



  • good deal!


 

Looks like your connection to thirty bees forum was lost, please wait while we try to reconnect.