prestalearn Posted March 1, 2013 Share Posted March 1, 2013 Does someone know a way to get prestashop (1.5.3) to show "from X$" instead of showing the highest price on productlist, home featured and product page when I have quantity discount enabled? The customer is usually interested in the lowest possible price instead of the highest. THanks in advance! Link to comment Share on other sites More sharing options...
NemoPS Posted March 2, 2013 Share Posted March 2, 2013 (edited) Hi there, i did it for a customer some time ago. Quantity discounts are not assigned in the product list, therefore you need to get them with a function in a categorycontroller.php override. For each cat_products there after processing the parent process() function, use something like this $qty_discounts = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT id_group, price, from_quantity, reduction, reduction_type FROM '._DB_PREFIX_.'specific_price WHERE id_product ='.$product['id_product'].' AND from_quantity > 1 AND id_group '.$sqlGroups.' ORDER BY from_quantity ASC'); You can further process them and remove quantity. This is the most flexible way, since also takes percentages in consideration (you can't just use a SQL query with MIN/MAX in this case!). Then, in the template, you can use something like this: {foreach from=$product.qty_discounts item=qt_disc} <tr> <td>{$qt_disc.from_quantity} {l s='Units'}</td> {$qty_taxed = ($qt_disc.price/100)*$product.rate} {math equation= "a + b" a=$qt_disc.price b=$qty_taxed assign=correct_disc} <td>{convertPrice price=$correct_disc}</td> {if $correct_disc < $product.price} {$product.price = $correct_disc}{$product.price_tax_exc = $correct_disc}{/if} </tr> {/foreach} To basically assign the lowest price to the product price. It's just copied/pasted from mine, you'll of course need to adapt it. It's just meant to show you the process vaguely Edited March 2, 2013 by Nemo1 (see edit history) 1 Link to comment Share on other sites More sharing options...
NemoPS Posted March 11, 2013 Share Posted March 11, 2013 Here is a better way with prestashop 1.5.3.1 http://nemops.com/lowest-price-prestashop-product-list/ Link to comment Share on other sites More sharing options...
prestalearn Posted March 13, 2013 Author Share Posted March 13, 2013 Here is a better way with prestashop 1.5.3.1 http://nemops.com/lo...p-product-list/ Has someone tried this for 1.5.3.1? It doesnt seem to make any difference for me :/ Link to comment Share on other sites More sharing options...
NemoPS Posted March 14, 2013 Share Posted March 14, 2013 I created it UPON 1.5.3.1, so I'm pretty much sure it works on that version Link to comment Share on other sites More sharing options...
prestalearn Posted March 15, 2013 Author Share Posted March 15, 2013 Thanks great, got it to work now Is it hard to modify this to work when the products is shown on home featured module also? Link to comment Share on other sites More sharing options...
NemoPS Posted March 15, 2013 Share Posted March 15, 2013 Not at all, you simply have to copy/paste the code, and change variable names accordingly (cat_products must be turned into $products only if I can recall it...) Link to comment Share on other sites More sharing options...
prestalearn Posted March 15, 2013 Author Share Posted March 15, 2013 Great! Do you mean the code from product-list only? Or do I need to make some new override file also? Link to comment Share on other sites More sharing options...
NemoPS Posted March 15, 2013 Share Posted March 15, 2013 From the override you copy the snippet, and paste it into hookDisplayHome of the module, from the list you can copy the whole html i believe 1 Link to comment Share on other sites More sharing options...
prestalearn Posted February 7, 2014 Author Share Posted February 7, 2014 Im using this great script by Nemo but since upgrade to 1.5.6.2 I havent been able to get it to work on home featured products. Is there someone who have it on home featured and not only product-list and would like to be so kind to write their solution here? Would really appriciate it (This is the script im talking about: http://nemops.com/lowest-price-prestashop-product-list/#.UvPDg3ewbDE Link to comment Share on other sites More sharing options...
NemoPS Posted February 7, 2014 Share Posted February 7, 2014 Are you getting any error? Or is it simply not working? It works for me on the latest 1562 Link to comment Share on other sites More sharing options...
prestalearn Posted February 7, 2014 Author Share Posted February 7, 2014 No, no error at all. Its working flawlessly at product-list but I havent been able to come up with the right solution to apply the rule to the price variable in home featured also :/ Step 3 in your guide is not exactly doable in the same way since home feautred price looks a bit different. I dont really get wich parts I need to add to the override controller to :/ Link to comment Share on other sites More sharing options...
NemoPS Posted February 7, 2014 Share Posted February 7, 2014 wait, did you clear smarty cache? that module is cached Link to comment Share on other sites More sharing options...
prestalearn Posted February 7, 2014 Author Share Posted February 7, 2014 yes I did. But is it just to apply the same code: {if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)} <span class="price" style="display: inline;"> {if isset($product.qt_disc)} {l s='From'} {/if} {if !$priceDisplay} {convertPrice price=$product.price} {else} {convertPrice price=$product.price_tax_exc} {/if} </span><br /> {/if} to homefeatured.tpl? I guess its these lines I should replace then? {if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE} <p class="price_container"> <a href="{$product.link|escape:'html'}" title="{$product.name|escape:html:'UTF-8'}" class="price" > {if !$priceDisplay} {convertPrice price=$product.price} {else} {convertPrice price=$product.price_tax_exc} {/if} Is there any additional lines that needs to be added to override except the ones mentioned in your guide? Link to comment Share on other sites More sharing options...
NemoPS Posted February 7, 2014 Share Posted February 7, 2014 Of course not, you have to apply the php part as well Link to comment Share on other sites More sharing options...
prestalearn Posted February 7, 2014 Author Share Posted February 7, 2014 (edited) Of course not, you have to apply the php part as well Forgive me for being a newbie at coding, but wich php part do you mean? :/ Do you mean to duplicate the whole override controller code? Should I change any parameters? Edited February 7, 2014 by prestalearn (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted February 8, 2014 Share Posted February 8, 2014 No worries, I mean part 1 and 2. copy it inside the hookHome function after products are retrieved, and simply swap the name from $this->cat_products to products Link to comment Share on other sites More sharing options...
prestalearn Posted February 8, 2014 Author Share Posted February 8, 2014 (edited) No worries, I mean part 1 and 2. copy it inside the hookHome function after products are retrieved, and simply swap the name from $this->cat_products to products <?php class CategoryController extends CategoryControllerCore { public function initContent() { parent::initContent(); if($this->cat_products) { $id_customer = (isset($this->context->customer) ? (int)$this->context->customer->id : 0); $id_group = (isset($this->context->customer) ? $this->context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_); $id_country = (int)$id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'); $id_currency = (int)$this->context->cookie->id_currency; $id_shop = $this->context->shop->id; foreach ($this->cat_products as $key => $product) { $prices_array = array(); /* For each product, grab quantity discounts */ $quantity_discounts = SpecificPrice::getQuantityDiscounts($product['id_product'], $id_shop, $id_currency, $id_country, $id_group, null, true); /* TRYING TO APPLY TO HOME FEATURED ALSO */ if($this->products) { $id_customer = (isset($this->context->customer) ? (int)$this->context->customer->id : 0); $id_group = (isset($this->context->customer) ? $this->context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_); $id_country = (int)$id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'); $id_currency = (int)$this->context->cookie->id_currency; $id_shop = $this->context->shop->id; foreach ($this->products as $key => $product) { $prices_array = array(); /* For each product, grab quantity discounts */ $quantity_discounts = SpecificPrice::getQuantityDiscounts($product['id_product'], $id_shop, $id_currency, $id_country, $id_group, null, true); } } /* Process quantity discounts to get the real price */ if ($quantity_discounts) { foreach ($quantity_discounts as $qkey => $discount) { if (!(float)$discount['reduction']) $price = $discount['price']; else { if ($discount['reduction_type'] == 'percentage') { $price = $product['price_without_reduction'] - ($product['price_without_reduction'] * $discount['reduction']); } else { $price = $product['price_without_reduction'] - $discount['reduction']; } } $prices_array[] = $price; } $this->cat_products[$key]['price'] = min($prices_array); $this->cat_products[$key]['qt_disc'] = true; } // end if quantity discounts $this->context->smarty->assign('products', $this->cat_products); /* trying to apply step 2 to homefeatured also */ /* Process quantity discounts to get the real price */ if ($quantity_discounts) { foreach ($quantity_discounts as $qkey => $discount) { if (!(float)$discount['reduction']) $price = $discount['price']; else { if ($discount['reduction_type'] == 'percentage') { $price = $product['price_without_reduction'] - ($product['price_without_reduction'] * $discount['reduction']); } else { $price = $product['price_without_reduction'] - $discount['reduction']; } } $prices_array[] = $price; } $this->products[$key]['price'] = min($prices_array); $this->products[$key]['qt_disc'] = true; } // end if quantity discounts $this->context->smarty->assign('products', $this->products); } // close the foreach } } } Ive tried to add step 1 and step 2. Step 1 works fine (if I try to save and reload the page). However after adding step 2 it breaks the layout of for example product-list.tpl and prevents it from loading correctly. Did I add step 2 incorrect in some way? Huge thanks for helping me Edited February 8, 2014 by prestalearn (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted February 8, 2014 Share Posted February 8, 2014 No no no. You have to put that 'trying to apply code' inside homefeatured.php, hookHome function Link to comment Share on other sites More sharing options...
prestalearn Posted February 8, 2014 Author Share Posted February 8, 2014 No no no. You have to put that 'trying to apply code' inside homefeatured.php, hookHome function Oh thank you I finally got it to work now Since prestashop has some kind of bug and displays quantity discount set for each currency (to avoid negative price on quantity products) all my quantity prices "from xxx" is displayed ex vat. Is it easy to show this with vat? (Just to clarify: If I add a general discount in my default currency it shows inc vat. But to avoid negative price on currency discounts I need to set discount for each currency individually and then it doesnt display inc vat) Link to comment Share on other sites More sharing options...
NemoPS Posted February 8, 2014 Share Posted February 8, 2014 I have to be honest, I am clueless about this vat thing! Link to comment Share on other sites More sharing options...
prestalearn Posted February 8, 2014 Author Share Posted February 8, 2014 I understand. Do you think one of these options perhaps could be a workaround? 1. Make the price parameter (lowest possible price) in home featured and product-list get multiplied with the current VAT? For example my VAT is 25% so it should take price*1,25? or 2. Make the price parameter (lowest possible price) in home featured and product-list get hardcoded and multiplied with 1,25? This will cause wrong price for countries i sell without vat to but at least its better than all pricec wrong Link to comment Share on other sites More sharing options...
NemoPS Posted February 10, 2014 Share Posted February 10, 2014 Maybe the first one, multiply ad add, only if it's the problematic type of reduction you mentioned (with a conditional if) Link to comment Share on other sites More sharing options...
Ranima Posted February 20, 2014 Share Posted February 20, 2014 Here is a better way with prestashop 1.5.3.1 http://nemops.com/lowest-price-prestashop-product-list/ Hello, thanks for that code, do you know which function have to be changed in blockbestsellers.php and blocksearch.php with that code in order to get the array quantity_discount in modules Bestsellers and Search? I thank in advance 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