如何设置与类别页面(以及可能的其他页面)不同的产品查看页面价格格式?
如果我更改我的子主题:
app/design/frontend/VENDOR/my_theme/Magento_Catalog/templates/product/price/final_price.phtml
两个页面(类别和产品)的价格都在变化;
我尝试了几种方法,但似乎这种价格呈现机制在 Magento2 中非常复杂。
谢谢!
最佳答案
<?php
try {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get(‘Magento\Framework\App\Action\Context’)->getRequest();
$currentPageXML = $request->getFullActionName();
echo $currentPageXML; //catalog_product_view is product detail page controller action
} catch (Exception $e) {}
?>
上面的代码会帮助你获取当前正在访问的环境区域,然后你可以应用一个逻辑
if ($currentPageXML=="catalog_product_view") {
// render my custom need
} else {
// keep the actual code intact.
}
您遇到了一个问题,因为目录和产品页面都在使用相同的 phtml
文件,所以此文件中的更改将反射(reflect)在所有地方。
希望对您有所帮助。
关于产品页面上的 Magento2 自定义价格呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38247790/