-
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.
Merge pull request #7254 from magento-l3/PR-2-2021-25-11
PR-2-2021-25-11
- Loading branch information
Showing
33 changed files
with
982 additions
and
74 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
app/code/Magento/Catalog/Model/Product/ReservedAttributeCheckerAdapter.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,43 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Model\Product; | ||
|
||
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; | ||
use Magento\Eav\Model\ReservedAttributeCheckerInterface; | ||
|
||
/** | ||
* Adapter for \Magento\Catalog\Model\Product\ReservedAttributeList | ||
* | ||
* Is created to implement proper interface and to use api class ReservedAttributeList | ||
* while keeping it backward compatible | ||
* @see \Magento\Catalog\Model\Product\ReservedAttributeList | ||
*/ | ||
class ReservedAttributeCheckerAdapter implements ReservedAttributeCheckerInterface | ||
{ | ||
/** | ||
* @var ReservedAttributeList | ||
*/ | ||
private $reservedAttributeList; | ||
|
||
/** | ||
* @param ReservedAttributeList $reservedAttributeList | ||
*/ | ||
public function __construct( | ||
ReservedAttributeList $reservedAttributeList | ||
) { | ||
$this->reservedAttributeList = $reservedAttributeList; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function isReservedAttribute(AbstractAttribute $attribute): bool | ||
{ | ||
return $this->reservedAttributeList->isReservedAttribute($attribute); | ||
} | ||
} |
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
98 changes: 98 additions & 0 deletions
98
app/code/Magento/Checkout/Model/Plugin/RecollectQuoteOnCustomerGroupChange.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,98 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Checkout\Model\Plugin; | ||
|
||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use Magento\Customer\Model\Customer; | ||
use Magento\Customer\Model\ResourceModel\Customer as CustomerResource; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\Model\AbstractModel; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Model\Quote; | ||
|
||
/** | ||
* Recollect quote when customer group updated through API | ||
*/ | ||
class RecollectQuoteOnCustomerGroupChange | ||
{ | ||
/** | ||
* @var CartRepositoryInterface | ||
*/ | ||
private $cartRepository; | ||
|
||
/** | ||
* @var CustomerRepositoryInterface | ||
*/ | ||
private $customerRepository; | ||
|
||
/** | ||
* Initialize Constructor | ||
* | ||
* @param CartRepositoryInterface $cartRepository | ||
* @param CustomerRepositoryInterface $customerRepository | ||
*/ | ||
public function __construct( | ||
CartRepositoryInterface $cartRepository, | ||
CustomerRepositoryInterface $customerRepository | ||
) { | ||
$this->cartRepository = $cartRepository; | ||
$this->customerRepository = $customerRepository; | ||
} | ||
|
||
/** | ||
* Plugin around create customer that triggers to update and recollect all customer cart | ||
* | ||
* @param CustomerResource $subject | ||
* @param callable $proceed | ||
* @param AbstractModel $customer | ||
* @return CustomerResource | ||
* | ||
* @throws LocalizedException | ||
* @throws NoSuchEntityException | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function aroundSave( | ||
CustomerResource $subject, | ||
callable $proceed, | ||
AbstractModel $customer | ||
): CustomerResource { | ||
$customerId = $customer->getId() ?: $customer->getEntityId(); | ||
/** @var Customer $customer */ | ||
if ($customerId && empty($customer->getTaxvat())) { | ||
try { | ||
$prevCustomerData = $this->customerRepository->getById($customerId); | ||
$previousCustomerData = $prevCustomerData->__toArray(); | ||
} catch (NoSuchEntityException $e) { | ||
$previousCustomerData = []; | ||
} | ||
} | ||
|
||
$result = $proceed($customer); | ||
|
||
if (!empty($previousCustomerData) | ||
&& $previousCustomerData['group_id'] !== null | ||
&& $previousCustomerData['group_id'] != $customer->getGroupId() | ||
&& empty($previousCustomerData['taxvat']) | ||
) { | ||
try { | ||
/** @var Quote $quote */ | ||
$quote = $this->cartRepository->getActiveForCustomer($customer->getId()); | ||
$quote->setCustomerGroupId($customer->getGroupId()); | ||
$quote->collectTotals(); | ||
$this->cartRepository->save($quote); | ||
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock | ||
} catch (NoSuchEntityException $e) { | ||
//no active cart for customer | ||
} | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Eav\Model; | ||
|
||
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; | ||
use Magento\Framework\Exception\LocalizedException; | ||
|
||
/** | ||
* Composite Reserved Attribute Checker | ||
* | ||
* Iterates through individual Reserved Attribute Checkers to check whether attribute is reserved by system | ||
*/ | ||
class ReservedAttributeChecker implements ReservedAttributeCheckerInterface | ||
{ | ||
/** | ||
* @var ReservedAttributeCheckerInterface[][] | ||
*/ | ||
private $validators; | ||
|
||
/** | ||
* @param array $validators | ||
*/ | ||
public function __construct( | ||
array $validators = [] | ||
) { | ||
$this->validators = $validators; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function isReservedAttribute(AbstractAttribute $attribute): bool | ||
{ | ||
$isReserved = false; | ||
$validators = $this->validators[$attribute->getEntityType()->getEntityTypeCode()] ?? []; | ||
foreach ($validators as $validator) { | ||
$isReserved = $validator->isReservedAttribute($attribute); | ||
if ($isReserved === true) { | ||
break; | ||
} | ||
} | ||
|
||
return $isReserved; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/code/Magento/Eav/Model/ReservedAttributeCheckerInterface.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,27 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Eav\Model; | ||
|
||
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; | ||
|
||
/** | ||
* Checks whether attribute is reserved by system | ||
*/ | ||
interface ReservedAttributeCheckerInterface | ||
{ | ||
/** | ||
* Check whether attribute is reserved by system. | ||
* | ||
* Check that given user defined EAV attribute doesn't contain the attribute code | ||
* that matches to a getter field related to related model (e.g. product, category, customer...) | ||
* | ||
* @param AbstractAttribute $attribute | ||
* @return bool | ||
*/ | ||
public function isReservedAttribute(AbstractAttribute $attribute): bool; | ||
} |
Oops, something went wrong.