Prestashop - 结帐时的完整产品描述

Prestashop - Full-Product-Description in Checkout

我以为这会很容易,但事实证明这是一项艰巨的任务。

我的客户要求我在结帐时的订单确认 table 中实施完整的产品描述。

目前我们只有简短的描述:

File: themes/newtheme/templates/checkout/_partials/order-confirmation-table.tpl

  <div class="order-confirmation-table">
    {block name='order_confirmation_table'}
      {foreach from=$products item=product}
        <div class="order-line row">

          {$product->description_short nofilter}

        </div>
      {/foreach}
    {/block}
  </div>

我认为基于此我只需要更改我正在访问的属性,例如:{$product->description nofilter}

但后来发现收银台里的 $product class 不是正常的产品 class。它与抽象层 LazyArray 相结合。

正如 prestashop 的开发人员手册中所述,他们刚刚更新了 1.7.5 版中的 LazyArrays,您必须通过 -> 访问它们。遗憾的是已经尝试过:

File: themes/newtheme/templates/checkout/_partials/order-confirmation-table.tpl

  <div class="order-confirmation-table">
    {block name='order_confirmation_table'}
      {foreach from=$products item=product}
        <div class="order-line row">

          {$product->description nofilter}

        </div>
      {/foreach}
    {/block}
  </div>

不起作用

然后我调试 $product->description 属性。 它是一个空数组。

所以,如果有人能帮助我理解惰性数组并获得描述,我将非常高兴

"description"字段不在前面允许的属性"whitelist"中

如果您打开文件 "src/Core/Filter/frontEndObject/ProductFilter.php",您将没有 "description" 的白名单。

Src/core/ 文件不能被覆盖,所以你必须创建一个模块并注册到挂钩 "ActionFrontControllerAfterInit"

在你的钩子函数中,调用服务,获取过滤器并将描述添加到白名单:

public function hookActionFrontControllerAfterInit()
{
    $filterManager = $this->get('prestashop.core.filter.front_end_object.main');

    // get list of all filters applied to client-side data
    $filters = $filterManager->getFilters();

    // get list of all filters applied to the cart object
    $cartFilters = $filters['cart']->getFilters();

    // get list of filters applied to each product inside the cart object
    $productFilterQueue = $cartFilters['products']->getQueue();

    foreach ($productFilterQueue as $filter) {
        if ($filter instanceof PrestaShop\PrestaShop\Core\Filter\FrontEndObject\ProductFilter) {
            $filter->whitelist(array('description'));
        }
    }
}

您可以在此处找到一些文档 http://build.prestashop.com/news/exposing-data-with-confidence/