How to override “gift card added to cart”
Question
I need to override the action fired when a customer sets a gift card in his cart. I need to apply a custom check against an external web service about the validity of the gift card applied.
Which is the file that I need to override?
Seems that I need to override this file:
vendor/magento/module-gift-card-account/Model/Service/GiftCardAccountManagement.php
Where I need to write my override inside my app folder?
Solution
Here is a small example how to override Core Model file in Magento 2
.
Step 1
Create a di.xml
file in a following directory Vendor/Module/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\Catalog\Model\Product" type="Vendor\Module\Model\Rewrite\Catalog\Product" />
</config>
Step 2
The step2 to overriding or rewriting Magento2 model is to create a Product.php
helper file in the following directory Vendor/Module/Model/Rewrite/Catalog
<?php
/**
* Catalog Product Rewrite Model
*
*
*/
namespace Vendor\Module\Model\Rewrite\Catalog;
class Product extends \Magento\Catalog\Model\Product
{
public function __construct()
{
echo "Overrding/ Rewrite Working"; die();
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange