Skip to content

Commit

Permalink
Merge branch '2.4-develop' of https://github.com/mage-os/mirror-magento2
Browse files Browse the repository at this point in the history
 into 2.4-develop
  • Loading branch information
mage-os-ci committed Jun 4, 2024
2 parents 2d831e4 + 4745100 commit abb184c
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $attributes = $block->getProductAttributes();
<?php $dataScope = /* @noEscape */ $block->getData('config/dataScope');
$nameStep = /* @noEscape */ $block->getData('config/nameStepWizard');
$scriptString = <<<script
require(['jquery', 'uiRegistry', 'underscore'], function ($, registry, _) {
require(['jquery', 'uiRegistry', 'underscore', 'Magento_Ui/js/lib/step-wizard'], function ($, registry, _) {
$('body').trigger('contentUpdated');
$('.{$dataScope}[data-role=steps-wizard-main]').applyBindings();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/************************************************************************
*
* Copyright 2023 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\SalesRule\Plugin;

use Closure;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\SalesRule\Model\Coupon\Quote\UpdateCouponUsages;
use Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderDefault;
use Throwable;
use Magento\Quote\Api\CartRepositoryInterface;

/**
* Increments number of coupon usages before placing order
*/
class CouponUsagesIncrementMultishipping
{

/**
* @var UpdateCouponUsages
*/
private UpdateCouponUsages $updateCouponUsages;

/**
* @var CartRepositoryInterface
*/
private CartRepositoryInterface $cartRepositoryInterface;

/**
* @param UpdateCouponUsages $updateCouponUsages
* @param CartRepositoryInterface $cartRepositoryInterface
*/
public function __construct(
UpdateCouponUsages $updateCouponUsages,
CartRepositoryInterface $cartRepositoryInterface
) {
$this->updateCouponUsages = $updateCouponUsages;
$this->cartRepositoryInterface = $cartRepositoryInterface;
}

/**
* Increments number of coupon usages before placing order
*
* @param PlaceOrderDefault $subject
* @param Closure $proceed
* @param array $order
* @return array
* @throws NoSuchEntityException|Throwable
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundPlace(PlaceOrderDefault $subject, Closure $proceed, array $order): array
{
$quoteId = $order[0]->getQuoteId();
$quote = $this->cartRepositoryInterface->get($quoteId);
/* if coupon code has been canceled then need to notify the customer */
if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) {
throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again."));
}

$this->updateCouponUsages->execute($quote, true);
try {
return $proceed($order);
} catch (Throwable $e) {
$this->updateCouponUsages->execute($quote, false);
throw $e;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/************************************************************************
*
* Copyright 2023 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\SalesRule\Test\Unit\Plugin;

use Magento\Quote\Model\Quote;
use Magento\Quote\Api\CartRepositoryInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\SalesRule\Model\Coupon\Quote\UpdateCouponUsages;
use Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderDefault;
use Magento\Sales\Model\Order;
use Magento\SalesRule\Plugin\CouponUsagesIncrementMultishipping;

class CouponUsageIncreamentForMultishippingTest extends TestCase
{
/**
* @var PlaceOrderDefault|MockObject
*/
private $subjectMock;

/**
* @var UpdateCouponUsages|MockObject
*/
private $updateCouponUsagesMock;

/**
* @var CartRepositoryInterface|MockObject
*/
private $cartRepositoryInterfaceMock;

/**
* @var Order[]|MockObject
*/
private $orderMock;

/**
* @var CouponUsagesIncrementMultishipping
*/
private $plugin;

/**
* Set Up
*/
protected function setUp(): void
{
$this->subjectMock = $this->getMockBuilder(PlaceOrderDefault::class)
->disableOriginalConstructor()
->getMock();
$this->updateCouponUsagesMock = $this->getMockBuilder(UpdateCouponUsages::class)
->disableOriginalConstructor()
->onlyMethods(['execute'])
->getMock();
$this->cartRepositoryInterfaceMock = $this->getMockBuilder(CartRepositoryInterface::class)
->disableOriginalConstructor()
->getMock();
$this->orderMock = $this->getMockBuilder(Order::class)
->onlyMethods(['getQuoteId'])
->disableOriginalConstructor()
->getMock();
$this->plugin = new CouponUsagesIncrementMultishipping(
$this->updateCouponUsagesMock,
$this->cartRepositoryInterfaceMock
);
}
/**
* Testing Increments number of coupon usages before placing order
*/
public function testAroundPlace()
{
$couponCode = 'coupon code';
$proceed = function ($orderMock) {
return $orderMock;
};
/** @var Quote|MockObject $quote */
$quoteMock = $this->getMockBuilder(Quote::class)
->disableOriginalConstructor()
->addMethods(['getCouponCode'])
->onlyMethods(['dataHasChangedFor'])
->getMock();
$this->orderMock->expects($this->once())->method('getQuoteId')
->willReturn(1);

$this->cartRepositoryInterfaceMock->expects($this->once())->method('get')->with(1)->willReturn($quoteMock);
$quoteMock->expects($this->once())->method('getCouponCode')->willReturn($couponCode);
$quoteMock->expects($this->any())->method('dataHasChangedFor')->with($couponCode)->willReturn(true);
$this->updateCouponUsagesMock
->expects($this->once())
->method('execute');
$this->assertSame(
[$this->orderMock],
$this->plugin->aroundPlace($this->subjectMock, $proceed, [$this->orderMock])
);
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/SalesRule/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"magento/module-captcha": "*",
"magento/module-checkout": "*",
"magento/module-authorization": "*",
"magento/module-asynchronous-operations": "*"
"magento/module-asynchronous-operations": "*",
"magento/module-multishipping": "*"
},
"suggest": {
"magento/module-sales-rule-sample-data": "*"
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/SalesRule/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
<type name="\Magento\Quote\Model\QuoteManagement">
<plugin name="coupon_uses_increment_plugin" type="Magento\SalesRule\Plugin\CouponUsagesIncrement" sortOrder="20"/>
</type>
<type name="\Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderDefault">
<plugin name="coupon_uses_increment_multishipping_plugin" type="Magento\SalesRule\Plugin\CouponUsagesIncrementMultishipping" sortOrder="30"/>
</type>
<preference
for="Magento\SalesRule\Model\Spi\CodeLimitManagerInterface"
type="Magento\SalesRule\Model\Coupon\CodeLimitManager" />
Expand Down

0 comments on commit abb184c

Please sign in to comment.