Skip to content

Commit

Permalink
Merge branch '2.4-develop' into ACQE-6192_mainline_PR_deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsharma-adobe authored Mar 22, 2024
2 parents 734d929 + 57a3231 commit 3b89967
Show file tree
Hide file tree
Showing 17 changed files with 491 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright 2024 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Category\Attribute\Backend;

class DefaultSortby extends Sortby
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright 2024 Adobe
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe and its suppliers, if any. The intellectual
* and technical concepts contained herein are proprietary to Adobe
* and its suppliers and are protected by all applicable intellectual
* property laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe.
*/
declare(strict_types=1);

namespace Magento\Catalog\Setup\Patch\Data;

use Magento\Catalog\Setup\CategorySetup;
use Magento\Catalog\Setup\CategorySetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchInterface;

class UpdateDefaultSortyByBackendType implements DataPatchInterface
{
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;

/**
* @var CategorySetupFactory
*/
private $categorySetupFactory;

/**
* PatchInitial constructor.
* @param ModuleDataSetupInterface $moduleDataSetup
* @param CategorySetupFactory $categorySetupFactory
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CategorySetupFactory $categorySetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->categorySetupFactory = $categorySetupFactory;
}

/**
* @inheritdoc
*/
public function apply(): UpdateDefaultSortyByBackendType
{
$mediaBackendModel = \Magento\Catalog\Model\Category\Attribute\Backend\DefaultSortby::class;
/** @var CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
$categorySetup->updateAttribute(
'catalog_category',
'default_sort_by',
'backend_model',
$mediaBackendModel
);

return $this;
}

/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}

/**
* @inheritdoc
*/
public function getAliases()
{
return [];
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Test/Fixture/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Category implements RevertibleDataFixtureInterface
'include_in_menu' => true,
'available_sort_by' => [],
'custom_attributes' => [
'default_sort_by' => ['name']
'default_sort_by' => 'position'
],
'extension_attributes' => [],
'created_at' => null,
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@
<item name="Magento\Catalog\Model\Product\Attribute\Backend\Category" xsi:type="string">int[]</item>
<item name="Magento\Catalog\Model\Product\Attribute\Backend\Stock" xsi:type="string">Magento\CatalogInventory\Api\Data\StockItemInterface[]</item>
<item name="Magento\Catalog\Model\Category\Attribute\Backend\Sortby" xsi:type="string">string[]</item>
<item name="Magento\Catalog\Model\Category\Attribute\Backend\DefaultSortby" xsi:type="string">string</item>
</argument>
</arguments>
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@

namespace Magento\CheckoutAgreements\Model\Checkout\Plugin;

use Magento\Checkout\Api\AgreementsValidatorInterface;
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface;
use Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface;
use Magento\CheckoutAgreements\Model\AgreementsProvider;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Quote\Api\GuestCartRepositoryInterface;
use Magento\Store\Model\App\Emulation;
use Magento\Store\Model\ScopeInterface;
use Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter;

Expand Down Expand Up @@ -40,62 +50,85 @@ class GuestValidation
private $activeStoreAgreementsFilter;

/**
* @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration
* @param \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList
* @var GuestCartRepositoryInterface
*/
private GuestCartRepositoryInterface $quoteRepository;

/**
* @var Emulation
*/
private Emulation $storeEmulation;

/**
* @param AgreementsValidatorInterface $agreementsValidator
* @param ScopeConfigInterface $scopeConfiguration
* @param CheckoutAgreementsListInterface $checkoutAgreementsList
* @param ActiveStoreAgreementsFilter $activeStoreAgreementsFilter
* @param GuestCartRepositoryInterface $quoteRepository
* @param Emulation $storeEmulation
*/
public function __construct(
\Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration,
\Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList,
\Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter $activeStoreAgreementsFilter
\Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter $activeStoreAgreementsFilter,
GuestCartRepositoryInterface $quoteRepository,
Emulation $storeEmulation
) {
$this->agreementsValidator = $agreementsValidator;
$this->scopeConfiguration = $scopeConfiguration;
$this->checkoutAgreementsList = $checkoutAgreementsList;
$this->activeStoreAgreementsFilter = $activeStoreAgreementsFilter;
$this->quoteRepository = $quoteRepository;
$this->storeEmulation = $storeEmulation;
}

/**
* Validates agreements before save payment information and order placing.
*
* @param \Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject
* @param GuestPaymentInformationManagementInterface $subject
* @param string $cartId
* @param string $email
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @param PaymentInterface $paymentMethod
* @param AddressInterface|null $billingAddress
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @throws CouldNotSaveException|NoSuchEntityException
*/
public function beforeSavePaymentInformationAndPlaceOrder(
\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
GuestPaymentInformationManagementInterface $subject,
$cartId,
$email,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
PaymentInterface $paymentMethod,
AddressInterface $billingAddress = null
) {
if ($this->isAgreementEnabled()) {
$this->validateAgreements($paymentMethod);
$quote = $this->quoteRepository->get($cartId);
$storeId = $quote->getStoreId();
$this->validateAgreements($paymentMethod, $storeId);
}
}

/**
* Validates agreements.
*
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @param PaymentInterface $paymentMethod
* @param int $storeId
* @return void
* @throws CouldNotSaveException
*/
private function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
private function validateAgreements(PaymentInterface $paymentMethod, int $storeId)
{
$agreements = $paymentMethod->getExtensionAttributes() === null
? []
: $paymentMethod->getExtensionAttributes()->getAgreementIds();

if (!$this->agreementsValidator->isValid($agreements)) {
throw new \Magento\Framework\Exception\CouldNotSaveException(
$this->storeEmulation->startEnvironmentEmulation($storeId);
$isValid = $this->agreementsValidator->isValid($agreements);
$this->storeEmulation->stopEnvironmentEmulation();

if (!$isValid) {
throw new CouldNotSaveException(
__(
"The order wasn't placed. "
. "First, agree to the terms and conditions, then try placing your order again."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@

namespace Magento\CheckoutAgreements\Model\Checkout\Plugin;

use Magento\Checkout\Api\AgreementsValidatorInterface;
use Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface;
use Magento\CheckoutAgreements\Model\AgreementsProvider;
use Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter;
use Magento\CheckoutAgreements\Model\EmulateStore;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Store\Model\App\Emulation;
use Magento\Store\Model\ScopeInterface;

/**
Expand Down Expand Up @@ -37,31 +44,37 @@ class Validation
private $activeStoreAgreementsFilter;

/**
* Quote repository.
*
* @var \Magento\Quote\Api\CartRepositoryInterface
*/
private $quoteRepository;

/**
* @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration
* @param \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList
* @var Emulation
*/
private Emulation $storeEmulation;

/**
* @param AgreementsValidatorInterface $agreementsValidator
* @param ScopeConfigInterface $scopeConfiguration
* @param CheckoutAgreementsListInterface $checkoutAgreementsList
* @param ActiveStoreAgreementsFilter $activeStoreAgreementsFilter
* @param CartRepositoryInterface $quoteRepository
* @param Emulation $storeEmulation
*/
public function __construct(
\Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration,
\Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList,
\Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter $activeStoreAgreementsFilter,
CartRepositoryInterface $quoteRepository
CartRepositoryInterface $quoteRepository,
Emulation $storeEmulation
) {
$this->agreementsValidator = $agreementsValidator;
$this->scopeConfiguration = $scopeConfiguration;
$this->checkoutAgreementsList = $checkoutAgreementsList;
$this->activeStoreAgreementsFilter = $activeStoreAgreementsFilter;
$this->quoteRepository = $quoteRepository;
$this->storeEmulation = $storeEmulation;
}

/**
Expand All @@ -82,24 +95,31 @@ public function beforeSavePaymentInformationAndPlaceOrder(
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
if ($this->isAgreementEnabled()) {
$this->validateAgreements($paymentMethod);
$quote = $this->quoteRepository->get($cartId);
$storeId = $quote->getStoreId();
$this->validateAgreements($paymentMethod, $storeId);
}
}

/**
* Validate agreements base on the payment method
*
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @param PaymentInterface $paymentMethod
* @param int $storeId
* @return void
* @throws CouldNotSaveException
*/
protected function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
private function validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod, int $storeId)
{
$agreements = $paymentMethod->getExtensionAttributes() === null
? []
: $paymentMethod->getExtensionAttributes()->getAgreementIds();

if (!$this->agreementsValidator->isValid($agreements)) {
$this->storeEmulation->startEnvironmentEmulation($storeId);
$isValid = $this->agreementsValidator->isValid($agreements);
$this->storeEmulation->stopEnvironmentEmulation();

if (!$isValid) {
throw new \Magento\Framework\Exception\CouldNotSaveException(
__(
"The order wasn't placed. "
Expand Down
Loading

0 comments on commit 3b89967

Please sign in to comment.