Skip to content
Advertisement

Problem with ajax price update when changing options

I got a problem on a Prestashop website (1.7.7.8) , with updating price when changing options. In some particular cases, an error occured and the price is not displayed.

You can see the bug here : https://bacom.lebonweb.fr/accueil/32-bache.html

This append in a specific scenario, when we have several options ; and not all are availables for all others options (not sure to be clear..). In this case :

  • the type “Roll up” has only 1 dimension available (200cm and 85cm).
  • the type “Bache” has others dimensions available, but not the same as the type ROLL UP

So to see the bug, you can follow those steps :

1/ go to https://bacom.lebonweb.fr/accueil/32-bache.html

2/ by default TYPE is rollup. Change the type select, choosing “Bache”

3/ the selects Hauteur and Largeur are well updated, with the available values for BACHE type (different from the ROLLUP type values). But the price disapears, and the error is “Can not retrieve the id_product_attribute” (debug mode is on)

If you reload the page, the bug disapear.

Some tests confirms the problem comes from the theme ; with classic default theme the same scenario works fine (http://www.lebonweb.fr/dev/bacom-test/femmes/2-42-brown-bear-printed-sweater.html)

I’ve tried, file by file (tpl and js) , to replace custom theme code with default theme code. But impossible to solve this error….

I’m probably missing something with ajax & JS. I’ve noticed this warning on console : “jQuery(window).on(‘load’…) called after load event occurred”…

But after 2 days of searching, reading, and testings, still unable to find a solution. Would you have advice or suggestion on where I should investigate more ?

Thanks a lot


EDIT : To explain diferently (and shortlier ^^) the problem with combinations I’m encountering :

EXEMPLE : We got 3 combinations of a t-shirt :

T shirt – RED – Size : 1

T-shirt – RED – Size 2

T-shirt – BLACK – Size 1

Changing one option may automatically change another option value :

step 1 : choose options : color : RED / Size 2

step 2 : change option color to BLACK = Size change automatically to 1

In my case, it seems that the default combination datas (the one loaded automatically in this exemple scenario) is not sent to the ajax request that gets the price datas. Wheras in other place in the page, those default datas are well get.

Maybe something like the ajax call to get price is called BEFORE another call that calculate the default combination according to option changes…?

Hope this other presentation of my problem will help 🙂

Thanks !

Advertisement

Answer

I finally found how to solve the problem (but didn’t understand why) : dis-activate the ttcountdown module and clean ALL caches. The informations given by Patrick were very helpful, so thanks again Patrick for taking time to help ! This solution is okay, because my client doesn’t need any countdown functionality.

But very frustrating, cause I did not clearly understand where and what in the code provocates the bug ; whereas we had quite a lot of elements and datas about it.

Maybe there’s a link with changes on prestashop 1.7 about attributes (see : PrestaShop 1.7 How to get id_product_attribute on product page?) :

In PrestaShop 1.7.x versions, product attributes (size, color, etc.) IDs selected by the buyer are stored in the group variable within an array, however this variable no longer contains the related id_product_attribute itself.

With those informations, I’ve supposed maybe the bugging theme author didn’t make clean and stable adaptation of his script after this change…? So I’ve tried some corrections on ttproductcountdown.php code, just for better understanding, around those lines (function hookPSPC at line 1360 of module/ttproductcountdown/ttproductcountdown.php)

// Get id_product_attribute
        $id_product_attribute = null;
        if (isset($params['id_product_attribute'])) {
            $id_product_attribute = $params['id_product_attribute'];
        } elseif (Tools::getValue('group')) {
            $groups = Tools::getValue('group');

            if (!empty($groups) && method_exists('Product', 'getIdProductAttributesByIdAttributes')) {
                $id_product_attribute = (int) Product::getIdProductAttributesByIdAttributes(
                    $id_product,
                    $groups
                );
            }
        }
        if ($id_product_attribute === null) {
            $id_product_attribute = Tools::getValue('id_product_attribute');
        }
        $has_attributes = $this->checkProductHasAttributes($id_product);
        if (!$id_product_attribute && $has_attributes) {
            $id_product_attribute = $this->getDefaultIdProductAttribute($id_product);
        }

        $hook = (isset($params['hook']) ? $params['hook'] : '');

        // render timers for all combinations at once at the product page in PS1.6
        if ($has_attributes && $this->getPSVersion() < 1.7 && $this->context->controller->php_self == 'product') {
            $ipas = Product::getProductAttributesIds($id_product, true);
            foreach ($ipas as $ipa) {
                $return .= $this->renderCountdown($id_product, $ipa['id_product_attribute'], $hook);
            }
        } else {
            $return = $this->renderCountdown($id_product, $id_product_attribute, $hook);
        }

Without success… So as long as I don’t plan to work often with prestashop ; and a day gets only 24h ; I will “give up” try to understand the problem.

Patrick, just for information, Prestashop is already using Boostrap. I’d like to make all by myself, but creating a theme for prestashop is quite long cause it covers a lots of pages and functionality (cart, catalog, user account etc..).

As I said, I avoid to work with CMS… Cause correcting a bug by clicking on a button without learning anything is not the way I like to work.

Thanks Patrick !

Advertisement