How to display the number of products in Prestashop
I am using one of the standard themes included in prestashop-1.6... Is it possible to display product quantity values ββfor a product based on size and color in the product window on the home page?
source to share
Watch this thread on the Prestashop.com forum . It looks like someone asked a similar question and was able to get it to work with this code:
{*Added quantity in stock*}
<!-- availability -->
<p id="availability_statut"{if ($product.quantity <= 0 && !$product.available_later && $allow_oosp) OR ($product.quantity > 0 && !$product.available_now) OR !$product.available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>
<span id="availability_label">{l s='Availability:'}</span>
<span id="availability_value"{if $product.quantity <= 0} class="warning_inline"{/if}>
{if $product.quantity <= 0}{if $allow_oosp}{$product.available_later}{else}{l s='This product is no longer in stock'}{/if}{else}{$product.available_now}{/if}
</span>
</p>
<!-- number of item in stock -->
{*if ($display_qties == 1 && !$PS_CATALOG_MODE && $product.available_for_order) *}
<p id="pQuantityAvailable"{if $product.quantity <= 0} style="display: none;"{/if}>
<span id="quantityAvailable">{$product.quantity|intval}</span>
<span {if $product.quantity > 1} style="display: none;"{/if} id="quantityAvailableTxt">{l s='item in stock'}</span>
<span {if $product.quantity == 1} style="display: none;"{/if} id="quantityAvailableTxtMultiple">{l s='items in stock'}</span>
</p>
<!-- Out of stock hook -->
<p id="oosHook"{if $product.quantity > 0} style="display: none;"{/if}>
{$HOOK_PRODUCT_OOS}
</p>
<p class="warning_inline" id="last_quantities"{if ($product.quantity > $last_qties OR $product.quantity <= 0) OR $allow_oosp OR !$product.available_for_order OR $PS_CATALOG_MODE} style="display: none"{/if} >{l s='Warning: Last items in stock!'}</p>
{*End Added quantity in stock*}
and in this other post also on Prestashop.com , someone reported that they can display quantities specific to the product size attribute using this Prestashop module . {/, If a}
source to share
Basically, the product list already shows some attributes - for example, colors. Product colors have a special way of adding a color pick to each product field in the list.
Therefore, we must follow this method if we do not want to create a specific module.
Since we need to change some code, we have to do and override (because we are not creating a module).
Method addColorsToProductList
as variable $ product ['color_list'] for each product to be displayed in the list. We must and can add information on quantities and combinations here (this is probably the easiest way).
For information on combinations, I looked at AdminProductsController.php @ Line 4263
. You should look at this method as well addColorsToProductList
. Below is the pseudocode (not completely complete, I can't write the whole thing for years, but it does show the idea):
override / classes / controller / FrontController.php
FrontController extends FrontControllerCore {
public function addColorsToProductList(&$products)
{
// You may need to modify the parent code if the caching ignores your changes
// Disable this if you dont want to add colors seperately;
parent::addColorsToProductList($products);
// @see AdminProductsController.php @ Line 4263
foreach($products as &$p)
{
$attributes = $p->getAttributesResume($this->context->language->id);
foreach ($attributes as $attribute)
{
// You may check if product_attribute is color + size here
$id_product_attribute = $attribute['id_product_attribute'];
$qty = StockAvailable::getQuantityAvailableByProduct((int)$obj->id, id_product_attribute);
$p['product_attributes'][$id_product_attribute]['qty'] = $qty;
$p['product_attributes'][$id_product_attribute]['name'] = $attribute['attribute_designation'];
// If you need individual color + size and their data, you will probably have to do some SQL,
// because getAttributesResume doesn SQL to get this data too.
}
}
}
}
After that, you can use product_attributes
inside your templates:
product-list.tpl
{if isset($product.color_list)}
<div class="color-list-container">{$product.color_list}</div>
{/if}
<p>
{foreach $product.product_attributes as $pa}
{$pa.qty} - {$pa.name} <br>
{/foreach}
</p>
Greetings
source to share