[英]How to display product quantity in Prestashop
請參閱Prestashop.com 論壇上的此主題。 看起來其他人問了類似的問題,並且能夠使用以下代碼使其正常工作:
{*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*}
在 Prestashop.com 上的另一個帖子中,有人報告說他們能夠使用這個 Prestashop 模塊顯示特定於產品尺寸屬性的數量。 { /如果}
基本上產品列表已經顯示了一些屬性 - 例如,顏色。 產品顏色有一種特殊的方法可以將顏色選擇附加到列表中的每個產品框。
因此,如果我們不想創建特定模塊,則應遵循此方法。
因為我們必須更改一些代碼,所以我們必須執行並覆蓋(因為我們不是在創建模塊)。
方法addColorsToProductList
作為變量 $product['color_list'] 到將顯示在列表中的每個產品。 我們應該並且可以在此處添加有關數量和組合的信息(這可能是最簡單的方法)。
要獲取有關組合的信息,我查看了AdminProductsController.php @ Line 4263
。 您應該查看此方法並addColorsToProductList
。 下面是一個偽代碼(不完全完整,我不能把它全部寫出來,但它顯示了這個想法):
覆蓋/類/控制器/ 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.
}
}
}
}
完成此操作后,您將能夠在模板中使用product_attributes
:
產品列表.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>
干杯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.