Jump to content

Ajout de 2 fonctions dans le module crossselling [Résolu]


Recommended Posts

Bonjour à tous,

 

Dans le module crossselling de prestashop j'aimerai ajouter 2 choses :

 

- la description du produit

 

- un bouton ajouter au panier

 

Est ce que quelqu'un peut m'aiguiller sur les variables smarty a utiliser pour se faire ?

 

Merci d'avance, Thierry

Edited by Thierry Création (see edit history)
Link to comment
Share on other sites

Hello Thierry,

 

Activer le module Ventes Croisées.

Editer le fichier /modules/crossselling/crossselling.php dans la fonction public function hookProductFooter($params) :

public function hookProductFooter($params)
	{
		$cache_id = 'crossselling|productfooter|'.(int)$params['product']->id;
		if (!$this->isCached('crossselling.tpl', $this->getCacheId($cache_id)))
		{
			$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
				'
							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 = '.(int)$params['product']->id
			);

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

				$order_products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
					'
										SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13
										FROM '._DB_PREFIX_.'order_detail od
					LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
					'.Shop::addSqlAssociation('product', 'p').'
					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)
					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 != '.(int)$params['product']->id.'
						AND i.cover = 1
						AND product_shop.active = 1
					ORDER BY RAND()
					LIMIT '.(int)Configuration::get('CROSSSELLING_NBR').'
				'
				);

				$tax_calc = Product::getTaxCalculationMethod();
				foreach ($order_products as &$order_product)
				{
					$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);
				}

				$this->smarty->assign(
					array(
						'order' => false,
						'orderProducts' => $order_products,
						'middlePosition_crossselling' => round(count($order_products) / 2, 0),
						'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE')
					)
				);
			}
		}

		return $this->display(__FILE__, 'crossselling.tpl', $this->getCacheId($cache_id));
	}

Tu dois avoir à la ligne 227 ceci après modification - j'ai ajouté ", pl.description" (table product_lang, champ description) :

SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, pl.description, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13

Ensuite, il te faut le dossier /crossselling/ dans le dossier de ton thème avec dedans le fichier crossselling.tpl pour avoir la surcouche visuelle et tu ajoutes la variable de description à la fin dans mon exemple et le bouton d'ajout panier avec les bonnes variables :

{if isset($orderProducts) && count($orderProducts)}
    <section id="crossselling" class="page-product-box">
    	<h3 class="productscategory_h2 page-product-heading">
            {if $page_name == 'product'}
                {l s='Customers who bought this product also bought:' mod='crossselling'}
            {else}
                {l s='We recommend' mod='crossselling'}
            {/if}
        </h3>
    	<div id="crossselling_list">
            <ul id="crossselling_list_car" class="clearfix">
                {foreach from=$orderProducts item='orderProduct' name=orderProduct}
                    <li class="product-box item" itemprop="isRelatedTo" itemscope itemtype="http://schema.org/Product">
                        <a class="lnk_img product-image" href="{$orderProduct.link|escape:'html':'UTF-8'}" title="{$orderProduct.name|htmlspecialchars}" >
                            <img itemprop="image" src="{$orderProduct.image}" alt="{$orderProduct.name|htmlspecialchars}" />
                        </a>
                        <p itemprop="name" class="product_name">
                            <a itemprop="url" href="{$orderProduct.link|escape:'html':'UTF-8'}" title="{$orderProduct.name|htmlspecialchars}">
                                {$orderProduct.name|truncate:15:'...'|escape:'html':'UTF-8'}
                            </a>
                        </p>
                        {if $crossDisplayPrice AND $orderProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
                            <p class="price_display">
                                <span class="price">{convertPrice price=$orderProduct.displayed_price}</span>
                                <br />
                                <a class="button ajax_add_to_cart_button btn btn-default" href="{$link->getPageLink('cart',false, NULL, 'add=1&id_product={$orderProduct.product_id|intval}', false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart' mod='crossselling'}" data-id-product="{$orderProduct.product_id|intval}">
                                    <span>{l s='Add to cart' mod='crossselling'}</span>
                                </a>
                            </p>
                        {/if}
                        <div>{$orderProduct.description}</div>
                    </li>
                {/foreach}
            </ul>
        </div>
    </section>
{/if}

Il faudrait néanmoins ajouter les conditions d'affichage du bouton d'ajout panier à mon sens mais en l'état ça fonctionne :)

++

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...