-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX][6244] Fix Issue with code label display in cart checkout.
- Loading branch information
1 parent
bdb0464
commit f133390
Showing
6 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
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
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
106 changes: 106 additions & 0 deletions
106
app/code/Magento/SalesRule/Plugin/CartTotalRepository.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\SalesRule\Plugin; | ||
|
||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Class CartTotalRepository | ||
* @package Magento\SalesRule\Plugin | ||
*/ | ||
class CartTotalRepository | ||
{ | ||
/** | ||
* @var \Magento\Quote\Api\Data\TotalsExtensionFactory | ||
*/ | ||
private $extensionFactory; | ||
|
||
/** | ||
* @var \Magento\SalesRule\Api\RuleRepositoryInterface | ||
*/ | ||
private $ruleRepository; | ||
|
||
/** | ||
* @var \Magento\SalesRule\Model\Coupon | ||
*/ | ||
private $coupon; | ||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* CartTotalRepository constructor. | ||
* @param \Magento\Quote\Api\Data\TotalsExtensionFactory $extensionFactory | ||
* @param \Magento\SalesRule\Api\RuleRepositoryInterface $ruleRepository | ||
* @param \Magento\SalesRule\Model\Coupon $coupon | ||
* @param StoreManagerInterface $storeManager | ||
*/ | ||
public function __construct( | ||
\Magento\Quote\Api\Data\TotalsExtensionFactory $extensionFactory, | ||
\Magento\SalesRule\Api\RuleRepositoryInterface $ruleRepository, | ||
\Magento\SalesRule\Model\Coupon $coupon, | ||
StoreManagerInterface $storeManager | ||
) { | ||
$this->extensionFactory = $extensionFactory; | ||
$this->ruleRepository = $ruleRepository; | ||
$this->coupon = $coupon; | ||
$this->storeManager = $storeManager; | ||
} | ||
|
||
/** | ||
* @param \Magento\Quote\Model\Cart\CartTotalRepository $subject | ||
* @param \Magento\Quote\Api\Data\TotalsInterface $result | ||
* @return \Magento\Quote\Api\Data\TotalsInterface | ||
*/ | ||
public function afterGet( | ||
\Magento\Quote\Model\Cart\CartTotalRepository $subject, | ||
\Magento\Quote\Api\Data\TotalsInterface $result | ||
) { | ||
if ($result->getExtensionAttributes() === null) { | ||
$extensionAttributes = $this->extensionFactory->create(); | ||
$result->setExtensionAttributes($extensionAttributes); | ||
} | ||
|
||
$extensionAttributes = $result->getExtensionAttributes(); | ||
$couponCode = $result->getCouponCode(); | ||
|
||
if (empty($couponCode)) { | ||
return $result; | ||
} | ||
|
||
$this->coupon->loadByCode($couponCode); | ||
$ruleId = $this->coupon->getRuleId(); | ||
|
||
if (empty($ruleId)) { | ||
return $result; | ||
} | ||
|
||
$storeId = $this->storeManager->getStore()->getId(); | ||
$rule = $this->ruleRepository->getById($ruleId); | ||
|
||
$storeLabel = $storeLabelFallback = null; | ||
|
||
/* @var $label \Magento\SalesRule\Model\Data\RuleLabel */ | ||
foreach ($rule->getStoreLabels() as $label) { | ||
|
||
if ($label->getStoreId() === 0) { | ||
$storeLabelFallback = $label->getStoreLabel(); | ||
} | ||
|
||
if ($label->getStoreId() == $storeId) { | ||
$storeLabel = $label->getStoreLabel(); | ||
break; | ||
} | ||
} | ||
|
||
$extensionAttributes->setCouponLabel(($storeLabel) ? $storeLabel : $storeLabelFallback); | ||
|
||
$result->setExtensionAttributes($extensionAttributes); | ||
|
||
return $result; | ||
} | ||
} |
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
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
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