Ai đó có thể vui lòng cho tôi biết làm thế nào tôi có thể ẩn SKU khỏi trang sản phẩm trong Magento 2 không?
Ai đó có thể vui lòng cho tôi biết làm thế nào tôi có thể ẩn SKU khỏi trang sản phẩm trong Magento 2 không?
Câu trả lời:
Tạo tập tin bố cục của riêng bạn cho trang sản phẩm:
app\design\frontend\VENDOR\THEME\Magento_Catalog\layout\catalog_product_view.xml
Sau đó, dán mã này vào tệp:
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.sku" remove="true" />
</body>
</page>
Bằng cách này, bạn có thể xóa khối SKU mà không cần sao chép toàn bộ tệp. Sử dụng remove
thuộc tính Bố cục cũng là cách tốt nhất!
Giải pháp từ MagentoOdoo.com sẽ không hoạt động vì bạn không thể xóa các thuộc tính hệ thống. Ngoài ra nếu nó hoạt động, nó sẽ loại bỏ hoàn toàn thuộc tính, và không chỉ từ chế độ xem.
Để xóa nó khỏi chế độ xem, sao chép tệp sau:
vendor\magento\module-catalog\view\frontend\layout\catalog_product_view.xml
vào thư mục mẫu của bạn, sẽ là một cái gì đó như thế này:
app\design\frontend\**your_theme**\theme\Magento_Catalog\layout\catalog_product_view.xml
Sau đó xóa khối mã sau (nên ở đâu đó quanh dòng 36)
<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.sku" template="product/view/attribute.phtml" after="product.info.type">
<arguments>
<argument name="at_call" xsi:type="string">getSku</argument>
<argument name="at_code" xsi:type="string">sku</argument>
<argument name="css_class" xsi:type="string">sku</argument>
<argument name="at_label" xsi:type="string">default</argument>
<argument name="add_attribute" xsi:type="string">itemprop="sku"</argument>
</arguments>
</block>
Và thay thế nó bằng:
<referenceBlock name="product.info.sku" remove="true"/>
xóa bộ nhớ cache và SKU cần được xóa khỏi chế độ xem sản phẩm.
Trong mô-đun của bạn, hãy tạo một bố cục có tên là catalog_product_view.xml (Không cần bộ điều khiển)
{venor_name} / {module_name} /view/frontend/layout/catalog_product_view.xml
Đặt mã này
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.sku" remove="true" />
</body>
</page>
Xóa bộ nhớ cache
Php bin/magento cache:flush
Hy vọng nó sẽ giúp bạn.