Jump to content

Edit History

Keron83

Keron83


code improvements

Sure.
Note that I only use the lowest specific price for a product. I dont use the getUnitPrice() function, so deleted it.
I only show the lowest price in the product-list view.
So this example is suitable for me, but should help you :).

Product.php (in override/classes)
 

class Product extends ProductCore {

    public static function getMinSpecificPrice($id_product) {

        $query = '
            SELECT
                price,
                from_quantity
            FROM
                '._DB_PREFIX_.'specific_price
            WHERE
                id_product = '.$id_product.'
                AND price = (
                    SELECT
                        MIN(price)
                    FROM
                        '._DB_PREFIX_.'specific_price
                    WHERE
                        id_product = '.$id_product.'
                );
        ';
        $lowestPrice = Db::getInstance()->executeS($query);

        if ($lowestPrice && !empty($lowestPrice)) {
            return Tools::displayPrice($lowestPrice[0]['price']);          
        }

    } //end of function

} //end of class override

and for the product-listgrid.tpl (located at: themes/theme_folder/templates/catalog/_partials/miniatures/product-listgrid.tpl)
or product.tpl located at: (themes/classic/templates/catalog/_partials/miniatures/product.tpl).

search for: product_price_and_shipping and add the code.

    <!-- search for this --> {block name='product_price_and_shipping'}
 
<!-- add this code to your template file -->
        {* assign lowest price when product has specific price *}
        {assign var=specificPrice value=Product::getMinSpecificPrice($product.id_product)}

        {if $product.show_price}
          	<div class="product-price-and-shipping">
            	{if $specificPrice}
            	  	<span itemprop="price" class="price">from: {$specificPrice} </span>
            	{else}
              		<span class="price">{$product.price}</span>
            	{/if}
			</div>
      	{/if}



 

Keron83

Keron83

Sure.
Note that I only use the lowest specific price for a product. I dont use the getUnitPrice() function, so deleted it.
I only show the lowest price in the product-list view.
So this example is suitable for me, but should help you :).

Product.php (in override/classes)

<?php
/**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * 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 [email protected] 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 https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <[email protected]>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 */

class Product extends ProductCore {

    public static function getMinSpecificPrice($id_product) {

        $lowestPrice = Db::getInstance()->ExecuteS('
            SELECT
                price,
                from_quantity
            FROM
                '._DB_PREFIX_.'specific_price
            WHERE
                id_product = '.$id_product.'
                    AND price = (
                        SELECT
                            MIN(price)
                        FROM
                            '._DB_PREFIX_.'specific_price
                        WHERE
                            id_product = '.$id_product.'
                    );
        ');

        if ($lowestPrice && !empty($lowestPrice)) {
            foreach ($lowestPrice as $data) {
                if ($data['from_quantity'] > 0) {
                    return Tools::displayPrice($data['price']);
                }
            }
        }

    } //end function

} //end class override

and for the product-listgrid.tpl (located at: themes/theme_folder/templates/catalog/_partials/miniatures/product-listgrid.tpl)
or product.tpl located at: (themes/classic/templates/catalog/_partials/miniatures/product.tpl).

search for: product_price_and_shipping and add the code.

    <!-- search for this --> {block name='product_price_and_shipping'}
 
<!-- add this code to your template file -->
        {* assign lowest price when product has specific price *}
        {assign var=specificPrice value=Product::getMinSpecificPrice($product.id_product)}

        {if $product.show_price}
          	<div class="product-price-and-shipping">
            	{if $specificPrice}
            	  	<span itemprop="price" class="price">from: {$specificPrice} </span>
            	{else}
              		<span class="price">{$product.price}</span>
            	{/if}
			</div>
      	{/if}



 

×
×
  • Create New...