With prestashop 1.7 you can configuration to display the price of other combinations on the product page by following steps:
Step 1:
Open and edit the file /controllers/front/ProductController.php
– You may see line of code similar to this:
$combination_images = $this->product->getCombinationImages($this->context->language->id);
$combination_prices_set = [];
and add this code right after that line of code like photo:
$leo_current_selected_attributes = [];
– Next, find the line of code similar to this:
and add this code right after that line of code like photo:
if (isset($product_for_template['attributes'][$row['id_attribute_group']]['id_attribute']) && $product_for_template['attributes'][$row['id_attribute_group']]['id_attribute'] == $row['id_attribute']) {
$leo_current_selected_attributes[$row['id_attribute_group']] = $row['id_attribute'];
}
– Then find the line of code similar to this:
And add this code like photo:
$tax = (float) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$priceCurrent = DB::getInstance()->getValue('SELECT pa.`price`
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(',', $current_selected_attributes).')
GROUP BY pac.id_product_attribute
HAVING COUNT(id_product) = ' . count($current_selected_attributes));
foreach ($groups as $id_attribute_group => &$rows) {
foreach ($rows['attributes'] as $id_attribute => &$row) {
if (!$row['selected']){
$attr_remove = $leo_current_selected_attributes[$id_attribute_group];
$attr_combi = array_diff($current_selected_attributes, [$attr_remove]);
$attr_combi[] = $id_attribute;
$price = DB::getInstance()->getValue('SELECT pa.`price`
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(',', $attr_combi).')
GROUP BY pac.id_product_attribute
HAVING COUNT(id_product) = ' . count($attr_combi));
if ($price > $priceCurrent) {
$row['price'] = '+'.(Tools::displayPrice(($price - $priceCurrent)+($price - $priceCurrent)*$tax/100));
} else if ($price < $priceCurrent) {
$row['price'] = (Tools::displayPrice(($price - $priceCurrent)+($price - $priceCurrent)*$tax/100));
} else {
$row['price'] = '';
}
}
}
}
Step 2: Open and edit the file /themes/your_theme/templates/catalog/_partials/product-variants.tpl
Use this code to display the price (see photo):
{if isset($group_attribute.price) && $group_attribute.price}{$group_attribute.price}{/if}
Yes, it’s all about how to show price of other combinations on product page in Prestashop 1.7. If you need any help, feel free to leave your question in the comment box bellow.