magento2
객체 다시 쓰기 의존성 삽입 사용
수색…
비고
https://gielberkers.com/magento-2-why-use-rewrites-when-you-can-use-plugins/
http://devdocs.magento.com/guides/v2.0/extension-dev-guide/plugins.html
magento 2에서 함수를 수정하는 몇 가지 방법
다시 쓰기 클래스
파일 : Namespace/ModuleName/etc/di.xml
<?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\Catalog\Controller\Product\View" type="Namespace\ModuleName\Controller\Product\View" />
</config>
파일 : Namespace\ModuleName\Controller\Product\View.php
class View extends \Magento\Catalog\Block\Product\View
{
///Code logic here
}
객체에 플러그인.
파일 : Namespace/ModuleName/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Product">
<plugin name="name_of_plugin" type="Namespace\ModuleName\Plugin\Catalog\Model\Product" sortOrder="1" disabled="false" />
</type>
</config>
파일 : Namespace\ModuleName\Plugin\Catalog\Model\Product.php
namespace Namespace\ModuleName\Plugin\Catalog\Model;
class Product
{
public function beforeSetName(
\Magento\Catalog\Model\Product $product, string $name)
{
/// Code logic here
return $name;
}
public function afterGetName(
\Magento\Catalog\Model\Product $product, string $name)
{
/// Code logic here
return $name;
}
public function aroundSave(
\Magento\Catalog\Model\Product $product, \Closure $proceed)
{
$this->doSomethingBeforeSave();
$result = $proceed();
if ($result) {
$this->doSomethingAfterSave();
}
return $result;
}
}
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow