symfony Shopware 6插件-无法访问Product DetailRouteResponse在Product DetailResponse页面上的扩展属性

smtd7mpg  于 12个月前  发布在  PWA
关注(0)|答案(1)|浏览(158)

我目前正在使用Shopware 6插件。我有一个MyCustomProductDetailRoute.php。我插件目录中的自定义文件将变量$expectedShippingCosts变量设置为扩展名,如下所示:

$productDetailResponse->getResult()->addExtension(
                'expectedShippingCosts', $expectedShippingCosts);

但是当我无法从twig模板中的page.extensions.expectedShippingCosts访问expectedShippingCosts属性时。我的dump(page)显示:

Shopware\Storefront\Page\Product\ProductPage {#8164 ▼
  #extensions: []
  #header: Shopware\Storefront\Pagelet\Header\HeaderPagelet {#7759 ▶}
  #footer: Shopware\Storefront\Pagelet\Footer\FooterPagelet {#7739 ▶}
  #salesChannelShippingMethods: Shopware\Core\Checkout\Shipping\ShippingMethodCollection {#8083 ▶}
  #salesChannelPaymentMethods: Shopware\Core\Checkout\Payment\PaymentMethodCollection {#8233 ▶}
  #metaInformation: Shopware\Storefront\Page\MetaInformation {#7953 ▶}
  #product: Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity {#6490 ▶}
  #cmsPage: null
  #navigationId: "01898d65262070718a76e2a12169ea79"
  #configuratorSettings: Shopware\Core\Content\Property\PropertyGroupCollection {#5563 ▶}
  #reviewLoaderResult: Shopware\Storefront\Page\Product\Review\ReviewLoaderResult {#7964 ▶}
  #selectedOptions: Shopware\Core\Content\Property\Aggregate\PropertyGroupOption\PropertyGroupOptionCollection {#8324 ▶}
  #crossSellings: Shopware\Core\Content\Product\SalesChannel\CrossSelling\CrossSellingElementCollection {#8357 ▶}
}

如何访问twig模板中的扩展名?
问候,Lodhi

gfttwv5a

gfttwv5a1#

将其更改为

$productDetailResponse->getProduct()->addExtension(
    'expectedShippingCosts', 
    $expectedShippingCosts
);
{{ dump(page.product.extensions.expectedShippingCosts) }}

相关问题