Skip to content

Instantly share code, notes, and snippets.

@wpoortman
Last active May 6, 2020 19:14
Show Gist options
  • Save wpoortman/13f2b55f5574592fb94534ebdff073c1 to your computer and use it in GitHub Desktop.
Save wpoortman/13f2b55f5574592fb94534ebdff073c1 to your computer and use it in GitHub Desktop.
Magento 2 - Plugin
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- Plugin after/before/around DocBlock method description here -->
<type name="Magento\Catalog\Model\Product">
<plugin name="Vendor_Namespace_Plugin_Magento_Catalog_Model_Product"
type="Vendor\Namespace\Plugin\Magento\Catalog\Model\Product"/>
</type>
</config>
<!-- Plugin namespace is always unique using your module vendor & namespace as a prefix -->
<!-- Use the path and class-name of the original type as your /Plugin/ path -->
<!-- Just copy the path of your Plugin class en replace all forward slashes with underscores -->
<!-- Copy/paste the class method docblock as your Plugin description -->
<?php
declare(strict_types=1);
namespace Vendor\Namespace\Plugin\Magento\Catalog\Model;
use Magento\Catalog\Model\Product as Subject;
/**
* Class Product
*
* @package Vendor\Namespace\Plugin\Magento\Catalog\Model
*/
class Product
{
public function beforeGetFinalPrice(Subject $subject, $qty = null): array
{
return [$qty];
}
public function aroundGetFinalprice(Subject $subject, callable $proceed)
{
return $proceed();
}
public function afterGetFinalPrice(Subject $subject, float $result): float
{
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment