Created
December 10, 2020 10:08
-
-
Save cdiacon/c5bf1d7c5a1eb3e138954f6e03b918ce to your computer and use it in GitHub Desktop.
ESW price plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Imagination Media | |
* | |
* @category ImaginationMedia | |
* @package ImaginationMedia_EshopWorld | |
* @author Calin Diacon <calin@imaginationmedia.com> | |
* @copyright Copyright (c) 2020 Imagination Media (https://www.imaginationmedia.com/) | |
* @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 | |
*/ | |
namespace ImaginationMedia\EshopWorld\Plugin; | |
use EShopWorld\Checkout\Pricing\Adjustment\RetailerAdjustment; | |
use Magento\Framework\Pricing\SaleableInterface; | |
use Magento\Store\Model\StoreManagerInterface; | |
class RetailerAdjustmentPlugin | |
{ | |
/** | |
* @var StoreManagerInterface | |
*/ | |
private $storeManager; | |
/** | |
* RetailerAdjustmentPlugin constructor. | |
* @param StoreManagerInterface $storeManager | |
*/ | |
public function __construct(StoreManagerInterface $storeManager) | |
{ | |
$this->storeManager = $storeManager; | |
} | |
/** | |
* @param RetailerAdjustment $subject | |
* @param callable $proceed | |
* @param $amount | |
* @param SaleableInterface $saleableItem | |
* @param array $context | |
* @return mixed | |
* @throws \Magento\Framework\Exception\LocalizedException | |
* @throws \Magento\Framework\Exception\NoSuchEntityException | |
*/ | |
public function aroundApplyAdjustment( | |
RetailerAdjustment $subject, | |
callable $proceed, | |
$amount, | |
SaleableInterface $saleableItem, | |
$context = [] | |
) { | |
$fromCurrency = $this->storeManager->getStore($saleableItem->getStoreId())->getBaseCurrency()->getCode(); | |
$toCurrency = $this->storeManager->getStore()->getCurrentCurrency()->getCode(); | |
if ($fromCurrency == 'USD' && $toCurrency == 'USD') { | |
return $amount; | |
} else { | |
return $proceed($amount, $saleableItem, $context); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment