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