마젠토 2:제품 유형별로 블록 클래스 재정의
-
29-09-2020 - |
문제
죄송합니다. 질문을 정의하는 방법을 모르겠습니다. 코드를 보여드리겠습니다.
마젠토 1 :
<checkout_cart_index>
<reference name="checkout.cart">
<action method="addItemRender">
<type>simple</type>
<block>mymodule/checkout_cart_item_renderer_simple</block>
<template>checkout/cart/item/default.phtml</template>
</action>
</reference>
</checkout_cart_index>
위의 코드는 장바구니 페이지의 간단한 제품 입력을 무시하기 위한 것입니다.
이제 내 질문은 어떻게 같은 일을 달성할 수 있는지입니다. 마젠토 2.
감사합니다.
해결책
Magento에서 렌더러는 다음과 같이 정의됩니다. checkout_cart_item_renderers.xml
, 그중 몇 가지가 있습니다.
app/code/Magento/Checkout/view/frontend/layout/checkout_cart_item_renderers.xml
기본 및 단순 제품 렌더러용app/code/Magento/Bundle/view/frontend/layout/checkout_cart_item_renderers.xml
번들 제품 렌더러용app/code/Magento/Catalog/view/frontend/layout/checkout_cart_item_renderers.xml
가상 제품 렌더러용app/code/Magento/ConfigurableProduct/view/frontend/layout/checkout_cart_item_renderers.xml
구성 가능한 제품 렌더러용app/code/Magento/Grouped/view/frontend/layout/checkout_cart_item_renderers.xml
그룹화된 제품 렌더러용app/code/Magento/GiftMessage/view/frontend/layout/checkout_cart_item_renderers.xml
이것은 다른 렌더러에 선물 메시지 기능을 위한 추가 블록을 추가하므로 특별합니다.app/code/Magento/Wishlist/view/frontend/layout/checkout_cart_item_renderers.xml
이것은 다양한 렌더러에 위시리스트 기능을 위한 추가 블록을 추가하므로 특별합니다.
해당 렌더러를 확인한 후 재정의하려는 렌더러를 찾을 수 있습니다.
말씀하신 대로 간단한 제품 렌더러를 재정의하고 싶습니다. Magento\Checkout\Block\Cart\Item\Renderer
.
전체 블록을 재정의하려면 Magento 2 환경 설정을 사용해야 합니다.
모듈에서 다음을 생성할 수 있습니다. di.xml
아래 파일 etc
다음 내용이 포함된 폴더:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Checkout\Block\Cart\Item\Renderer" type="Vendor\ModuleName\Block\Checkout\Cart\Item\Renderer" />
</config>
그런 다음 app/code/Vendor/Module/Block/Checkout/Cart/Item/Renderer.php
다음 내용을 포함하는 수업:
<?php
namespace Vendor\Module\Block\Checkout\Cart\Item;
class Renderer extends \Magento\Checkout\Block\Cart\Item\Renderer
{
public function theFunctionYouWantToRewrite()
{
// Do your custom stuff
}
}
그러나 전체 클래스 수준이 아닌 메서드 수준에서 작업하려면 플러그인을 사용해야 합니다.
매우 구체적일 수 있으므로 예를 들기는 어렵지만 여기에서 플러그인에 대한 유용한 리소스를 찾을 수 있습니다.
제휴하지 않습니다 magento.stackexchange