0

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?

1
  • Did you got the solution?
    – aravind
    Oct 9, 2019 at 4:40

1 Answer 1

0

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();
}
}
2
  • Thank you. The di.xml was the missing part! Oct 15, 2019 at 9:37
  • @AndreaCrevola Please approve my answer... Oct 15, 2019 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.