I have a third-party module with a file I want to override so I don't loss my changes when upgrading the third-party extension.
Vendor\Module\Plugin\Quote\UpdateItem.php
namespace Vendor\Module\Plugin\Quote;
use Vendor\Module\Model\Product\Type\GiftCard;
class UpdateItem {
/**
* @var \Magento\Catalog\Model\ProductRepository
*/
private $productRepository;
public function __construct(\Magento\Catalog\Model\ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}
/**
* save
*
* @param \Magento\Quote\Model\Quote $subject
* @param callable $proceed
* @param int $itemId
* @param \Magento\Framework\DataObject $buyRequest
* @param null|array|\Magento\Framework\DataObject $params
* @return \Magento\Quote\Model\Quote\Item
*/
public function aroundUpdateItem($subject, callable $proceed, $item, $buyRequest, $params = null)
{
// some code
return $proceed($itemId, $buyRequest, $params = null);
}
}
Vendor\Module\etc\di.xml
<type name="Magento\Quote\Model\Quote">
<plugin name="Vendor_Module::UpdateItem" type="Vendor\Module\Plugin\Quote\UpdateItem"/>
</type>
I tried to add this file to my theme but it doesn't override the third-party file:
\app\design\frontend\Mytheme\custom\Vendor_Module\Plugin\Quote\UpdateItem.php
UPDATE
Vendor\Module
and Vendor_Module
is the third-party module name. So above code is the code I want to override.
UPDATE 2
The accepted answer got me on the right track. I did the following:
Myvendor\Mymodule
and Myvendor_Mymodule
is a custom module I created.
Myvendor\Mymodule\etc\di.xml
<type name="Magento\Quote\Model\Quote">
<plugin name="Vendor_Module::UpdateItem" type="Vendor\Module\Plugin\Quote\UpdateItem" disabled="true" />
</type>
<type name="Magento\Quote\Model\Quote">
<plugin name="Myvendor_Mymodule::UpdateItem" type="Myvendor\Mymodule\Plugin\Quote\UpdateItem"/>
</type>
Myvendor\Mymodule\Plugin\Quote\UpdateItem.php
namespace Myvendor\Mymodule\Plugin\Quote;
use Vendor\Module\Model\Product\Type\GiftCard;
class UpdateItem {
/**
* @var \Magento\Catalog\Model\ProductRepository
*/
private $productRepository;
public function __construct(\Magento\Catalog\Model\ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}
/**
* save
*
* @param \Magento\Quote\Model\Quote $subject
* @param callable $proceed
* @param int $itemId
* @param \Magento\Framework\DataObject $buyRequest
* @param null|array|\Magento\Framework\DataObject $params
* @return \Magento\Quote\Model\Quote\Item
*/
public function aroundUpdateItem($subject, callable $proceed, $item, $buyRequest, $params = null)
{
// some code
return $proceed($itemId, $buyRequest, $params = null);
}
}