Susi Posted July 28, 2011 Share Posted July 28, 2011 Hello everybody! That's it, I need to put an "Add to cart" button in my cross-selling module and also in some related products module. My question is: Is this have done before? does anyone knows or have some module integrated like this? (If it's free it's better as my client wont pay much more for this...) I want to know if I can find something before doing the code modifications Thanks in advance, Susana Link to comment Share on other sites More sharing options...
rocky Posted July 29, 2011 Share Posted July 29, 2011 Why don't you use the "Cross-selling" module that comes with PrestaShop? It's in the "Front Office Features" section and has a configuration page with the option to "Display price on products". Link to comment Share on other sites More sharing options...
Susi Posted July 29, 2011 Author Share Posted July 29, 2011 Alo! yes, it's there displaying the price but my client wants that also people can "add to cart" right there, in the suggestions list and even if they don't want to check the whole product info. I think I'm gonna end up coding this somehow, I'm not that good at php but lest see. If I manage to do this, I promisse to post it here. Cheers! Link to comment Share on other sites More sharing options...
Susi Posted July 29, 2011 Author Share Posted July 29, 2011 Hello again! I tried adding the cart button to the tpl file as I did with other module that worked fine but with crossselling nothing happens when you hit the button... well, it does the "ajax" thing with the main product image but it does not add anything to my cart, this when using only the button. When I add the conditional for the catalogue mod etc, it does show an unavailable 'add to cart' and the 'Out of stock' legend This 'add to cart' button code is taken literally from the accessories tab in the product.tpl file, I thought that would work as cross-selling is also related to this main product, but nahhh! Do I have to declare something else? (obviously but don't know exactly what) maybe telling to that button that it have to add that other product and not the main one? humm... Any ideas? Also I can tell that id product is not being filled up by crossselling... that can be told because when rendered, id_product={$orderProduct.id_product|intval}& is showing up like id_product=& I haven't moved anything in my crossselling.php file, here's what i'm trying to do in the crossseling.tpl file: {if isset($orderProducts) && count($orderProducts) > 0} <div id="crossselling"> <h2 class="productscategory_h2">{l s='Customers who bought this product also bought:' mod='crossselling'}</h2> <div id="crossselling_list"> <ul id="product_list_cross"> {foreach from=$orderProducts item='orderProduct' name=orderProduct} <li class="ajax_block_product {if $smarty.foreach.products.first}first_item{elseif $smarty.foreach.products.last}last_item{/if} {if $smarty.foreach.products.index % 2}alternate_item{else}item{/if} clearfix"> <a href="{$orderProduct.link}" title="{$orderProduct.name|htmlspecialchars}"> <img src="{$orderProduct.image}" alt="{$orderProduct.name|htmlspecialchars}" /> </a><br/> <a href="{$orderProduct.link}" title="{$orderProduct.name|htmlspecialchars}">{$orderProduct.name|escape:'htmlall':'UTF-8'} </a><br /> {if $crossDisplayPrice AND $orderProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE} <span class="price_display"> <span class="price">{convertPrice price=$orderProduct.displayed_price}</span></span><br /> {else} <br /> {/if} <a class="button" href="{$orderProduct.link|escape:'htmlall':'UTF-8'}" title="{l s='View'}">{l s='View'}</a> {if ($orderProduct.allow_oosp || $orderProduct.quantity > 0) AND $orderProduct.available_for_order AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE} <a class="exclusive button ajax_add_to_cart_button" href="{$link->getPageLink('cart.php')}?qty=1&id_product={$orderProduct.id_product|intval}&token={$static_token}&add" rel="ajax_id_product_{$orderProduct.id_product|intval}" title="{l s='Add to cart'}">{l s='Add to cart'}</a> {else} <span class="exclusive">{l s='Add to cart'}</span> <span class="availability">{if (isset($orderProduct.quantity_all_versions) && $orderProduct.quantity_all_versions > 0)}{l s='Product available with different options'}{else}{l s='Out of stock'}{/if}</span> {/if} </li> {/foreach} </ul> </div> </div> {else} {/if} Any suggestions are welcomed! thanks! Link to comment Share on other sites More sharing options...
rocky Posted July 30, 2011 Share Posted July 30, 2011 Looking at the code, it seems you must use {$orderProduct.product_id} instead of {$orderProduct.id_product}. Link to comment Share on other sites More sharing options...
Susi Posted August 1, 2011 Author Share Posted August 1, 2011 Looking at the code, it seems you must use {$orderProduct.product_id} instead of {$orderProduct.id_product}. Alo! I did that already, I made that change because I found that in crossselling.php that variable is called like that at some point. I hate not knowing php that much by now. I quit it for the weekend but I'm trying now again. Thanks! Link to comment Share on other sites More sharing options...
Susi Posted August 1, 2011 Author Share Posted August 1, 2011 Me again. How can I tell crossselling.php to fill up all variables I need for this to work? It says is out of stock and the reason is that each product is not supposed to have all data it need to be added. Here's the code again for crossselling.TPL {if isset($orderProducts) && count($orderProducts) > 0} <div id="crossselling"> <h2 class="productscategory_h2">{l s='Customers who bought this product also bought:' mod='crossselling'}</h2> <div id="crossselling_list"> <ul id="product_list_cross"> {foreach from=$orderProducts item='orderProduct' name=orderProduct} <li class="ajax_block_product {if $smarty.foreach.products.first}first_item{elseif $smarty.foreach.products.last}last_item{/if} {if $smarty.foreach.products.index % 2}alternate_item{else}item{/if} clearfix"> <a href="{$orderProduct.link}" title="{$orderProduct.name|htmlspecialchars}"> <img src="{$orderProduct.image}" alt="{$orderProduct.name|htmlspecialchars}" /> </a><br/> <a href="{$orderProduct.link}" title="{$orderProduct.name|htmlspecialchars}"> {$orderProduct.name|escape:'htmlall':'UTF-8'} </a><br /> {if $crossDisplayPrice AND $orderProduct.allow_oosp AND $orderProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE} <span class="price_display"> <span class="price">{convertPrice price=$orderProduct.displayed_price}</span> </span><br /> <a class="exclusive button ajax_add_to_cart_button" href="{$link->getPageLink('cart.php')}?qty=1&id_product={$orderProduct.product_id|intval}&token={$static_token}&add" rel="ajax_id_product_{$orderProduct.product_id|intval}" title="{l s='Add to cart' mod='crosssellings'}">{l s='Add to cart' mod='crossselling'}</a> {else} <span class="availability">{if (isset($orderproduct.quantity_all_versions) && $orderProduct.quantity_all_versions > 0)}{l s='Product available with different options' mod='crossselling'}{else}{l s='Out of stock' mod='crossselling'}{/if}</span> {/if} </li> {/foreach} </ul> </div> </div> {else} {/if} Then, the crossselling.php not modified yet, is the native one... if (!defined('_CAN_LOAD_FILES_')) exit; class CrossSelling extends Module { private $_html; public function __construct() { $this->name = 'crossselling'; $this->tab = 'front_office_features'; $this->version = 0.1; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Cross Selling'); $this->description = $this->l('Customers who bought this product also bought:'); if (!$this->isRegisteredInHook('header')) $this->registerHook('header'); } public function install() { if (!parent::install() OR !$this->registerHook('productFooter') OR !$this->registerHook('header') OR !Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', 0)) return false; return true; } public function uninstall() { if (!parent::uninstall() OR !Configuration::deleteByName('CROSSSELLING_DISPLAY_PRICE')) return false; return true; } public function getContent() { $this->_html = ''; if (Tools::isSubmit('submitCross') AND Tools::getValue('displayPrice') != 0 AND Tools::getValue('displayPrice') != 1) $this->_html .= $this->displayError('Invalid displayPrice'); elseif (Tools::isSubmit('submitCross')) { Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', Tools::getValue('displayPrice')); $this->_html .= $this->displayConfirmation($this->l('Settings updated successfully')); } $this->_html .= ' <form action="'.$_SERVER['REQUEST_URI'].'" method="post"> <fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend> <label>'.$this->l('Display price on products').'</label> <div class="margin-form"> <input type="radio" name="displayPrice" id="display_on" value="1" '.(Configuration::get('CROSSSELLING_DISPLAY_PRICE') ? 'checked="checked" ' : '').'/> <label class="t" for="display_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label> <input type="radio" name="displayPrice" id="display_off" value="0" '.(!Configuration::get('CROSSSELLING_DISPLAY_PRICE') ? 'checked="checked" ' : '').'/> <label class="t" for="display_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label> <p class="clear">'.$this->l('Show the price on the products in the block.').'</p> </div> <center><input type="submit" name="submitCross" value="'.$this->l('Save').'" class="button" /></center> </fieldset> </form>'; return $this->_html; } public function hookHeader() { Tools::addCSS(($this->_path).'crossselling.css', 'all'); } /** * Returns module content for left column */ public function hookProductFooter($params) { global $smarty, $cookie, $link; $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 (sizeof($orders)) { $list = ''; foreach ($orders AS $order) $list .= (int)$order['id_order'].','; $list = rtrim($list, ','); $orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, p.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) LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id) LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = p.id_category_default) LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id) WHERE od.id_order IN ('.$list.') AND pl.id_lang = '.(int)($cookie->id_lang).' AND cl.id_lang = '.(int)($cookie->id_lang).' AND od.product_id != '.(int)$params['product']->id.' AND i.cover = 1 AND p.active = 1 ORDER BY RAND() LIMIT 10'); $taxCalc = Product::getTaxCalculationMethod(); foreach ($orderProducts AS &$orderProduct) { $orderProduct['image'] = $link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], 'medium'); $orderProduct['link'] = $link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']); if (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND ($taxCalc == 0 OR $taxCalc == 2)) $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL); elseif (Configuration::get('CROSSSELLING_DISPLAY_PRICE') AND $taxCalc == 1) $orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL); } $smarty->assign(array('orderProducts' => $orderProducts, 'middlePosition_crossselling' => round(sizeof($orderProducts) / 2, 0), 'crossDisplayPrice' => Configuration::get('CROSSSELLING_DISPLAY_PRICE'))); } return $this->display(__FILE__, 'crossselling.tpl'); } } Then, a screenshot... I cannot send you my website link because is closed Any help or ideas are thankfully welcomed! Link to comment Share on other sites More sharing options...
donnytkc Posted October 17, 2012 Share Posted October 17, 2012 (edited) hi so glad that i found someone in the same situation here, thanks Susi i add <a class="exclusive button ajax_add_to_cart_button" href="{$link->getPageLink('cart.php')}?qty=1&id_product={$orderProduct.product_id|intval}&token={$static_token}&add" rel="ajax_id_product_{$orderProduct.product_id|intval}" title="{l s='Add to cart' mod='crosssellings'}">{l s='Add to cart' mod='crossselling'}</a> into my tpl and it works. only the little flaw is that, when i click on add to cart button, the animation that a picture of product flys to shopping cart dosent shows properly....it shows the product from the page instead of the crosselling product that i have clicked... Edited October 17, 2012 by donnytkc (see edit history) Link to comment Share on other sites More sharing options...
donnytkc Posted October 17, 2012 Share Posted October 17, 2012 am still finding out the solutions..... Link to comment Share on other sites More sharing options...
Berlindoor Posted November 8, 2012 Share Posted November 8, 2012 you can use add_to_cart_button instead of ajax_add_to_cart_button but it pretty sucks since the user will be redirected to the checkout page Link to comment Share on other sites More sharing options...
Baltazar Posted February 10, 2013 Share Posted February 10, 2013 (edited) Solution: in crossselling.php AFTER $orderProduct['link'] = $link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']); ADD $orderProduct['id'] = ((int)$orderProduct['product_id']); in crossselling.tpl use $orderProduct.id Edited February 10, 2013 by Baltazar (see edit history) Link to comment Share on other sites More sharing options...
geotargetplus Posted February 21, 2014 Share Posted February 21, 2014 THX! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now