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?

  • Did you got the solution? – aravind Oct 9 at 4:40
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();
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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