Jump to content
Céline13240

Module Cross Selling - afficher prix barré + pourcentage ou montant réduction

Recommended Posts

Bonsoir,

 

Dans la perspective de mettre à jour ma boutique de la version 1.5.6.1 vers la version 1.6.1.11, je développe un nouveau thème en local sous wamp.

 

Je souhaite optimiser la visibilité des produits en promotions sur les différents modules/pages de la boutique en affichant le prix barré + le pourcentage ou le montant de la réduction ainsi qu'un bandeau avec le % ou le montant de la réduction. J'ai réussi à le faire pour la plupart des modules et pages, non sans mal, mais je bloque vraiment sur le module Crossselling/Vente Croisée.

 

J'ai modifié le fichier template du module dans mon thème en m'inspirant de ce que j'avais déjà fait mais sans succès. Je n'obtiens absolument aucun changement. Seul le prix s'affiche, ce qui ne permet pas d'identifier que le produit en question est en promotion.

 

Voici le code que j'ai modifié pour l'affichage du prix barré et du montant ou du pourcentage de la réduction sous la photo (je n'ai pas encore essayé d'ajouter le bandeau) :

{if $crossDisplayPrice AND $orderProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
                           
	<span class="price_display">
						   
        {if isset($orderProduct.specific_prices) && $orderProduct.specific_prices
					&& ($orderProduct.displayed_price|number_format:2 !== $orderProduct.price_without_reduction|number_format:2)}
            <span class="price special-price">{convertPrice price=$orderProduct.displayed_price}</span>
	    <span class="old-price">{displayWtPrice p=$orderProduct.price_without_reduction}</span>
						
	   {if $orderProduct.specific_prices.reduction && $orderProduct.specific_prices.reduction_type == 'percentage'}
	       <span class="price-percent-reduction small">-{$orderProduct.specific_prices.reduction * 100}%</span>
	  {/if}
						
	  {if $orderProduct.specific_prices.reduction && $orderProduct.specific_prices.reduction_type == 'amount'}
		<span class="price-amount-reduction small">{$orderProductPriceWithoutReduction-$orderProduct.specific_prices.reduction|floatval} €</span>
	  {/if}
	  {else}
	      <span class="price">{convertPrice price=$orderProduct.displayed_price}</span><br />
	  {/if}
	</span>
	{else}
	<br />
{/if}

Edited by Céline13240 (see edit history)

Share this post


Link to post
Share on other sites

Bonjour à vous,

 

Le sujet date je sais, j'avais le même soucis.

 

Le module Cross Selling, ne retourne pas les prix spécifique, il faut faire un override du module et dans le fonction "getOrderProducts" il vous faut chercher le prix spécifique dans la requette sql.

 

Voici comment j'ai fait, je suis encore débutant en dev, donc excusez moi si je choque certain sur ma maniére de faire  :D

 

Pour mon Select :

SELECT DISTINCT od.product_id, pl.name, pl.description_short, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price,
                    cl.link_rewrite category, p.ean13, stock.out_of_stock, sp.reduction, IFNULL(stock.quantity, 0) as quantity

Pour mon Left Join :

LEFT JOIN '._DB_PREFIX_.'specific_price sp ON (sp.id_product = p.id_product)

Et enfin dans mon foreach : 

if (!empty($order_product['reduction']))
                {
                  $order_product['reduction'] = $order_product['reduction'];
                } else {
                  $order_product['reduction'] = '0';
                }

En gros ça donne ceci :

<?php
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2016 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

if (!defined('_PS_VERSION_')) {
    exit;
}

class CrossSellingOverride extends CrossSelling
{

    /**
     * @param array $products_id an array of product ids
     * @return array
     */
    protected function getOrderProducts(array $products_id)
    {
        $q_orders = 'SELECT o.id_order
        FROM '._DB_PREFIX_.'orders o
        LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
        WHERE o.valid = 1 AND od.product_id IN ('.implode(',', $products_id).')';
        $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($q_orders);

        $final_products_list = array();

        if (count($orders) > 0) {
            $list = '';
            foreach ($orders as $order) {
                $list .= (int)$order['id_order'].',';
            }
            $list = rtrim($list, ',');

            $list_product_ids = join(',', $products_id);

            if (Group::isFeatureActive()) {
                $sql_groups_join = '
                LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = product_shop.id_category_default
                    AND cp.id_product = product_shop.id_product)
                LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category`)';
                $groups = FrontController::getCurrentCustomerGroups();
                $sql_groups_where = 'AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '='.(int)Group::getCurrent()->id);
            }

            $order_products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                SELECT DISTINCT od.product_id, pl.name, pl.description_short, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price,
                    cl.link_rewrite category, p.ean13, stock.out_of_stock, sp.reduction, IFNULL(stock.quantity, 0) as quantity
                FROM '._DB_PREFIX_.'order_detail od
                LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
                '.Shop::addSqlAssociation('product', 'p').
                (Combination::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
                ON (p.`id_product` = pa.`id_product`)
                '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').'
                '.Product::sqlStock('p', 'product_attribute_shop', false, $this->context->shop) :  Product::sqlStock('p', 'product', false,
                    $this->context->shop)).'
                LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
                LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'
                    .Shop::addSqlRestrictionOnLang('cl').')
                LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
                '.(Group::isFeatureActive() ? $sql_groups_join : '').'
                LEFT JOIN '._DB_PREFIX_.'specific_price sp ON (sp.id_product = p.id_product)
                WHERE od.id_order IN ('.$list.')
                AND pl.id_lang = '.(int)$this->context->language->id.'
                AND cl.id_lang = '.(int)$this->context->language->id.'
                AND od.product_id NOT IN ('.$list_product_ids.')
                AND i.cover = 1
                AND product_shop.active = 1
                '.(Group::isFeatureActive() ? $sql_groups_where : '').'
                ORDER BY RAND()
                LIMIT '.(int)Configuration::get('CROSSSELLING_NBR'));


            $tax_calc = Product::getTaxCalculationMethod();

            foreach ($order_products as &$order_product) {
              //ddd($order_product['reduction']);
                $order_product['id_product'] = (int)$order_product['product_id'];
                $order_product['image'] = $this->context->link->getImageLink($order_product['link_rewrite'],
                    (int)$order_product['product_id'].'-'.(int)$order_product['id_image'], ImageType::getFormatedName('home'));
                $order_product['link'] = $this->context->link->getProductLink((int)$order_product['product_id'], $order_product['link_rewrite'],
                    $order_product['category'], $order_product['ean13']);
                if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') && ($tax_calc == 0 || $tax_calc == 2)) {
                    $order_product['displayed_price'] = Product::getPriceStatic((int)$order_product['product_id'], true, null);
                } elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') && $tax_calc == 1) {
                    $order_product['displayed_price'] = Product::getPriceStatic((int)$order_product['product_id'], false, null);
                }
                $order_product['allow_oosp'] = Product::isAvailableWhenOutOfStock((int)$order_product['out_of_stock']);

                if (!empty($order_product['reduction']))
                {
                  $order_product['reduction'] = $order_product['reduction'];
                } else {
                  $order_product['reduction'] = '0';
                }

                if (!isset($final_products_list[$order_product['product_id'].'-'.$order_product['id_image']])) {
                    $final_products_list[$order_product['product_id'].'-'.$order_product['id_image']] = $order_product;
                }
            }
        }

        return $final_products_list;
    }

}

Edited by Beezkit (see edit history)

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More