Jump to content

Issues with changing attributes


ComGrafPL

Recommended Posts

Issues with changing attributes. Attributes not changing, sometimes after clicking other attribute it switching to different product.

8.1.7 / PHP 8.1

EDIT 2: If we disable cache, attributes works fine. If we enable cache, same issues. Hosting  logs only shows something with "trackingClient.bundle.js:12". Cant find more info on that anywhere.

Console showing this:

 

 

combination.png

Edited by ComGrafPL (see edit history)
Link to comment
Share on other sites

  • ComGrafPL changed the title to Issues with changing attributes

I have found override by module. But we cant remove it. Most probably this cause the issue.

 

        if (!Module::isEnabled('groupinc')) {
            return parent::assignAttributesGroups($product_for_template);
        }
        $colors = [];
        $groups = [];
        $this->combinations = [];
        $attributes_groups = $this->product->getAttributesGroups($this->context->language->id);
        if (is_array($attributes_groups) && $attributes_groups) {
            $combination_images = $this->product->getCombinationImages($this->context->language->id);
            $combination_prices_set = [];
            foreach ($attributes_groups as $k => $row) {
                if (isset($row['is_color_group']) && $row['is_color_group'] && isset($row['attribute_color']) && $row['attribute_color'] || file_exists(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) {
                    $colors[$row['id_attribute']]['value'] = $row['attribute_color'];
                    $colors[$row['id_attribute']]['name'] = $row['attribute_name'];
                    if (!isset($colors[$row['id_attribute']]['attributes_quantity'])) {
                        $colors[$row['id_attribute']]['attributes_quantity'] = 0;
                    }
                    $colors[$row['id_attribute']]['attributes_quantity'] += (int) $row['quantity'];
                }
                if (!isset($groups[$row['id_attribute_group']])) {
                    $groups[$row['id_attribute_group']] = [
                        'group_name' => $row['group_name'],
                        'name' => $row['public_group_name'],
                        'group_type' => $row['group_type'],
                        'default' => -1,
                    ];
                }
                $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = [
                    'name' => $row['attribute_name'],
                    'html_color_code' => $row['attribute_color'],
                    'texture' => (@filemtime(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) ? _THEME_COL_DIR_ . $row['id_attribute'] . '.jpg' : '',
                    'selected' => (isset($product_for_template['attributes'][$row['id_attribute_group']]['id_attribute']) && $product_for_template['attributes'][$row['id_attribute_group']]['id_attribute'] == $row['id_attribute']) ? true : false,
                ];
                if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) {
                    $groups[$row['id_attribute_group']]['default'] = (int) $row['id_attribute'];
                }
                if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) {
                    $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0;
                }
                $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int) $row['quantity'];
                $this->combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name'];
                $this->combinations[$row['id_product_attribute']]['attributes'][] = (int) $row['id_attribute'];
                $this->combinations[$row['id_product_attribute']]['price'] = (float) $row['price'];
                if (!isset($combination_prices_set[(int) $row['id_product_attribute']])) {
                    $combination_specific_price = null;
                    Product::getPriceStatic((int) $this->product->id, false, $row['id_product_attribute'], 6, null, false, true, 1, false, null, null, null, $combination_specific_price);
                    $combination_prices_set[(int) $row['id_product_attribute']] = true;
                    $this->combinations[$row['id_product_attribute']]['specific_price'] = $combination_specific_price;
                }
                if (Module::isEnabled('groupinc')) {
                    $id_customer = $this->context->cart->id_customer;
                    include_once _PS_MODULE_DIR_ . 'groupinc/classes/GroupincConfiguration.php';
                    $groupinc = new GroupincConfiguration();
                    $id_shop = $this->context->cart->id_shop;
                    $id_currency = $this->context->cart->id_currency;
                    $id_address_delivery = $this->context->cart->id_address_delivery;
                    $address = new Address($id_address_delivery);
                    $id_country = $address->id_country;
                    if ($id_country == 0) {
                        $id_country = $this->context->country->id;
                    }
                    $id_state = $address->id_state;
                    $id_product = $this->product->id;
                    $onsaleconf = $groupinc->getGIConfigurations($id_shop, $id_product, $id_customer, $id_country, $id_state, $id_currency, $this->context->language->id, true, true, $row['id_product_attribute'], false, true);
                    if (!empty($onsaleconf)) {
                        $this->combinations[$row['id_product_attribute']]['on_sale'] = 1;
                        $this->combinations[$row['id_product_attribute']]['id_attribute'] = $row['id_attribute'];
                    }
                    $tax_manager = TaxManagerFactory::getManager($address, Product::getIdTaxRulesGroupByIdProduct((int) $id_product, $this->context));
                    $ptc = $tax_manager->getTaxCalculator();
                    $product = new Product($id_product);
                    $product_price_without_tax = $product->price;
                    $product_price_with_tax = $ptc->addTaxes($product_price_without_tax);
                    $configs_qd = $groupinc->getGIConfigurations($id_shop, $id_product, $id_customer, $id_country, $id_state, $id_currency, $this->context->language->id, false, true, 0, true);
                    if (!empty($configs_qd)) {
                        $qds = $groupinc->getQuantityDiscounts($configs_qd, $id_product, false, $product_price_with_tax, $product_price_without_tax, $ptc);
                        if (!empty($qds)) {
                            $this->combinations[$row['id_product_attribute']]['quantities'] = 1;
                            foreach ($qds as $c) {
                                if ((int) $c['id_product_attribute'] == (int) $row['id_product_attribute'] || (int) $c['id_product_attribute'] == 0) {
                                    $this->combinations[$row['id_product_attribute']]['on_sale'] = 1;
                                    $this->combinations[$row['id_product_attribute']]['id_attribute'] = $row['id_attribute'];
                                    if ($this->combinations[$row['id_product_attribute']]['quantities'] > 1 && $c['from_quantity'] < $this->combinations[$row['id_product_attribute']]['quantities']) {
                                        $this->combinations[$row['id_product_attribute']]['quantities'] = $c['from_quantity'];
                                    } elseif ($this->combinations[$row['id_product_attribute']]['quantities'] == 1) {
                                        $this->combinations[$row['id_product_attribute']]['quantities'] = $c['from_quantity'];
                                    }
                                }
                            }
                        }
                    }
                }
                $this->combinations[$row['id_product_attribute']]['ecotax'] = (float) $row['ecotax'];
                $this->combinations[$row['id_product_attribute']]['weight'] = (float) $row['weight'];
                $this->combinations[$row['id_product_attribute']]['quantity'] = (int) $row['quantity'];
                $this->combinations[$row['id_product_attribute']]['reference'] = $row['reference'];
                $this->combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact'];
                $this->combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity'];
                if ($row['available_date'] != '0000-00-00' && Validate::isDate($row['available_date'])) {
                    $this->combinations[$row['id_product_attribute']]['available_date'] = $row['available_date'];
                    $this->combinations[$row['id_product_attribute']]['date_formatted'] = Tools::displayDate($row['available_date']);
                } else {
                    $this->combinations[$row['id_product_attribute']]['available_date'] = $this->combinations[$row['id_product_attribute']]['date_formatted'] = '';
                }
                if (!isset($combination_images[$row['id_product_attribute']][0]['id_image'])) {
                    $this->combinations[$row['id_product_attribute']]['id_image'] = -1;
                } else {
                    $this->combinations[$row['id_product_attribute']]['id_image'] = $id_image = (int) $combination_images[$row['id_product_attribute']][0]['id_image'];
                    if ($row['default_on']) {
                        foreach ($this->context->smarty->tpl_vars['product']->value['images'] as $image) {
                            if ($image['cover'] == 1) {
                                $current_cover = $image;
                            }
                        }
                        if (!isset($current_cover)) {
                            $current_cover = array_values($this->context->smarty->tpl_vars['product']->value['images'])[0];
                        }
                        if (is_array($combination_images[$row['id_product_attribute']])) {
                            foreach ($combination_images[$row['id_product_attribute']] as $tmp) {
                                if ($tmp['id_image'] == $current_cover['id_image']) {
                                    $this->combinations[$row['id_product_attribute']]['id_image'] = $id_image = (int) $tmp['id_image'];
                                    break;
                                }
                            }
                        }
                        if ($id_image > 0) {
                            if (isset($this->context->smarty->tpl_vars['images']->value)) {
                                $product_images = $this->context->smarty->tpl_vars['images']->value;
                            }
                            if (isset($product_images) && is_array($product_images) && isset($product_images[$id_image])) {
                                $product_images[$id_image]['cover'] = 1;
                                $this->context->smarty->assign('mainImage', $product_images[$id_image]);
                                if (count($product_images)) {
                                    $this->context->smarty->assign('images', $product_images);
                                }
                            }
                            $cover = $current_cover;
                            if (isset($cover) && is_array($cover) && isset($product_images) && is_array($product_images)) {
                                $product_images[$cover['id_image']]['cover'] = 0;
                                if (isset($product_images[$id_image])) {
                                    $cover = $product_images[$id_image];
                                }
                                $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id . '-' . $id_image) : (int) $id_image);
                                $cover['id_image_only'] = (int) $id_image;
                                $this->context->smarty->assign('cover', $cover);
                            }
                        }
                    }
                }
            }
            $current_selected_attributes = [];
            $count = 0;
            foreach ($groups as &$group) {
                ++$count;
                if ($count > 1) {
                    $id_attributes = Db::getInstance()->executeS('SELECT `id_attribute` FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac2
                        WHERE `id_product_attribute` IN (
                            SELECT pac.`id_product_attribute`
                                FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac
                                INNER JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON pa.id_product_attribute = pac.id_product_attribute
                                WHERE id_product = ' . $this->product->id . ' AND id_attribute IN (' . implode(',', array_map('intval', $current_selected_attributes)) . ')
                                GROUP BY id_product_attribute
                                HAVING COUNT(id_product) = ' . count($current_selected_attributes) . '
                        ) AND id_attribute NOT IN (' . implode(',', array_map('intval', $current_selected_attributes)) . ')');
                    foreach ($id_attributes as $k => $row) {
                        $id_attributes[$k] = (int) $row['id_attribute'];
                    }
                    foreach ($group['attributes'] as $key => $attribute) {
                        if (!in_array((int) $key, $id_attributes)) {
                            unset($group['attributes'][$key]);
                            unset($group['attributes_quantity'][$key]);
                        }
                    }
                }
                $index = 0;
                $current_selected_attribute = 0;
                foreach ($group['attributes'] as $key => $attribute) {
                    if ($index === 0) {
                        $current_selected_attribute = $key;
                    }
                    if ($attribute['selected']) {
                        $current_selected_attribute = $key;
                        break;
                    }
                }
                if ($current_selected_attribute > 0) {
                    $current_selected_attributes[] = $current_selected_attribute;
                }
            }
            if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) {
                foreach ($groups as &$group) {
                    foreach ($group['attributes_quantity'] as $key => &$quantity) {
                        if ($quantity <= 0) {
                            unset($group['attributes'][$key]);
                        }
                    }
                }
                foreach ($colors as $key => $color) {
                    if ($color['attributes_quantity'] <= 0) {
                        unset($colors[$key]);
                    }
                }
            }
            foreach ($this->combinations as $id_product_attribute => $comb) {
                $attribute_list = '';
                foreach ($comb['attributes'] as $id_attribute) {
                    $attribute_list .= '\'' . (int) $id_attribute . '\',';
                }
                $attribute_list = rtrim($attribute_list, ',');
                $this->combinations[$id_product_attribute]['list'] = $attribute_list;
            }
            $this->context->smarty->assign([
                'groups' => $groups,
                'colors' => (count($colors)) ? $colors : false,
                'combinations' => $this->combinations,
                'combinationImages' => $combination_images,
            ]);
        } else {
            $this->context->smarty->assign([
                'groups' => [],
                'colors' => false,
                'combinations' => [],
                'combinationImages' => [],
            ]);
        }
    }

 

Link to comment
Share on other sites

Hi

Since you mentioned that the override cannot be removed directly, you can temporarily disable it to see if it resolves the issue:

1. Navigate to the specific override file and rename it, for example, by adding '_disabled' to the filename. This prevents PrestaShop from loading it.
2. After renaming the file, clear the PrestaShop cache by going to Advanced Parameters > Performance > Clear Cache.

If you’ve confirmed that the module’s override is causing the issue but you cannot remove or edit the override, the best course of action is to contact the module developer.
Provide them with details about the issue, including how the override affects your site, and ask for an update or a fix.

Regards.

Link to comment
Share on other sites

20 hours ago, Knowband Plugins said:

Hi

Since you mentioned that the override cannot be removed directly, you can temporarily disable it to see if it resolves the issue:

1. Navigate to the specific override file and rename it, for example, by adding '_disabled' to the filename. This prevents PrestaShop from loading it.
2. After renaming the file, clear the PrestaShop cache by going to Advanced Parameters > Performance > Clear Cache.

If you’ve confirmed that the module’s override is causing the issue but you cannot remove or edit the override, the best course of action is to contact the module developer.
Provide them with details about the issue, including how the override affects your site, and ask for an update or a fix.

Regards.

Seems it wasnt related to it.  If we disable cache, attributes works fine. If we enable cache, same issues. Hosting  logs only shows something with "trackingClient.bundle.js:12". Cant find more info on that anywhere.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...