如何在Prestashop中显示产品数量

时间:2015-01-07 02:44:38

标签: php prestashop prestashop-1.6

我正在使用中包含的默认主题之一。是否可以根据主页上产品框中的尺寸和颜色显示产品的产品数量值?

2 个答案:

答案 0 :(得分:2)

this thread on Prestashop.com forum。看起来其他人问过类似的问题,并且能够使用此代码:

{*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*} 

this other post also on Prestashop.com,有人报告说他们能够使用this Prestashop module显示特定于产品尺寸属性的数量。 { /如果}

答案 1 :(得分:1)

基本上,产品列表已经显示了一些属性 - 例如,颜色。产品颜色有一种特殊的方法可以将颜色选择附加到列表中的每个产品框中。

因此,如果我们不想创建特定的模块,我们应该遵循这个方法。

因为我们必须更改一些代码,所以我们必须执行并覆盖(因为我们没有创建模块)。

方法addColorsToProductList作为将在列表中显示的每个产品的变量$ product [&#39; color_list&#39;]。我们应该并且可以在这里添加有关数量和组合的信息(这可能是最简单的方法)。

要了解有关这些组合的信息,我查看了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

产品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>

干杯

相关问题