Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - magento#20082: [Backport] issue resolved:Undefined Variable $itemsOrderItemId (by @milindsingh)
 - magento#19423: Fixed bug, when exception occurred on order with coupons cancel, made by guest after creating of customer account. (by @Winfle)
 - magento#19927: [Backport] [Framework] New Link is not correctly shown as Current if contains default parts (by @eduard13)


Fixed GitHub Issues:
 - magento#19940: Exception undefined variable itemsOrderItemId while creating shipment through MSI (reported by @mohammadzakir) has been fixed in magento#20082 by @milindsingh in 2.2-develop branch
   Related commits:
     1. 4802e00
     2. cb15b01

 - magento#19230: Can't Cancel Order (reported by @friendscottn) has been fixed in magento#19423 by @Winfle in 2.2-develop branch
   Related commits:
     1. cede04f
     2. 11480e8
     3. 10fbf40
     4. 1e2f3fb
     5. 5ea6e72
     6. 9a63dad
     7. 36c2329
     8. fdf7da4

 - magento#19099: New Link is not correctly shown as Current if contains default parts (reported by @eduard13) has been fixed in magento#19927 by @eduard13 in 2.2-develop branch
   Related commits:
     1. 0e027a0
     2. 1357888
     3. 83cbf32
     4. 02bc6fa
     5. cf1e877
     6. a03c156
  • Loading branch information
sidolov authored Jan 14, 2019
2 parents 56b9c6c + a132cac commit d20f927
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 42 deletions.
59 changes: 59 additions & 0 deletions app/code/Magento/Sales/Model/Order/CustomerAssignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Sales\Model\Order;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\Event\ManagerInterface;

class CustomerAssignment
{
/**
* @var ManagerInterface
*/
private $eventManager;

/**
* @var OrderRepositoryInterface
*/
private $orderRepository;

/**
* CustomerAssignment constructor.
*
* @param ManagerInterface $eventManager
* @param OrderRepositoryInterface $orderRepository
*/
public function __construct(
ManagerInterface $eventManager,
OrderRepositoryInterface $orderRepository
) {
$this->eventManager = $eventManager;
$this->orderRepository = $orderRepository;
}

/**
* @param OrderInterface $order
* @param CustomerInterface $customer
*/
public function execute(OrderInterface $order, CustomerInterface $customer)/*: void*/
{
$order->setCustomerId($customer->getId());
$order->setCustomerIsGuest(false);
$this->orderRepository->save($order);

$this->eventManager->dispatch(
'sales_order_customer_assign_after',
[
'order' => $order,
'customer' => $customer
]
);
}
}
23 changes: 16 additions & 7 deletions app/code/Magento/Sales/Observer/AssignOrderToCustomerObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order\CustomerAssignment;

/**
* Assign order to customer created after issuing guest order.
Expand All @@ -24,11 +25,22 @@ class AssignOrderToCustomerObserver implements ObserverInterface
private $orderRepository;

/**
* @var CustomerAssignment
*/
private $assignmentService;

/**
* AssignOrderToCustomerObserver constructor.
*
* @param OrderRepositoryInterface $orderRepository
* @param CustomerAssignment $assignmentService
*/
public function __construct(OrderRepositoryInterface $orderRepository)
{
public function __construct(
OrderRepositoryInterface $orderRepository,
CustomerAssignment $assignmentService
) {
$this->orderRepository = $orderRepository;
$this->assignmentService = $assignmentService;
}

/**
Expand All @@ -44,11 +56,8 @@ public function execute(Observer $observer)
if (array_key_exists('__sales_assign_order_id', $delegateData)) {
$orderId = $delegateData['__sales_assign_order_id'];
$order = $this->orderRepository->get($orderId);
if (!$order->getCustomerId()) {
//if customer ID wasn't already assigned then assigning.
$order->setCustomerId($customer->getId());
$order->setCustomerIsGuest(0);
$this->orderRepository->save($order);
if (!$order->getCustomerId() && $customer->getId()) {
$this->assignmentService->execute($order, $customer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Event\Observer;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order\CustomerAssignment;
use Magento\Sales\Observer\AssignOrderToCustomerObserver;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;
Expand All @@ -27,6 +28,9 @@ class AssignOrderToCustomerObserverTest extends TestCase
/** @var OrderRepositoryInterface|PHPUnit_Framework_MockObject_MockObject */
protected $orderRepositoryMock;

/** @var CustomerAssignment | PHPUnit_Framework_MockObject_MockObject */
protected $assignmentMock;

/**
* Set Up
*/
Expand All @@ -35,7 +39,12 @@ protected function setUp()
$this->orderRepositoryMock = $this->getMockBuilder(OrderRepositoryInterface::class)
->disableOriginalConstructor()
->getMock();
$this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock);

$this->assignmentMock = $this->getMockBuilder(CustomerAssignment::class)
->disableOriginalConstructor()
->getMock();

$this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock, $this->assignmentMock);
}

/**
Expand Down Expand Up @@ -69,13 +78,14 @@ public function testAssignOrderToCustomerAfterGuestOrder($customerId)
$orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)
->willReturn($orderMock);
if (!$customerId) {
$this->orderRepositoryMock->expects($this->once())->method('save')->with($orderMock);

if ($customerId) {
$this->assignmentMock->expects($this->once())->method('execute')->with($orderMock, $customerMock);
$this->sut->execute($observerMock);
return ;
return;
}

$this->orderRepositoryMock->expects($this->never())->method('save')->with($orderMock);
$this->assignmentMock->expects($this->never())->method('execute');
$this->sut->execute($observerMock);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\SalesRule\Observer;

use Magento\Framework\Event\Observer;
use Magento\SalesRule\Model\Coupon\UpdateCouponUsages;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Framework\Event\ObserverInterface;

class AssignCouponDataAfterOrderCustomerAssignObserver implements ObserverInterface
{
const EVENT_KEY_CUSTOMER = 'customer';

const EVENT_KEY_ORDER = 'order';

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

/**
* AssignCouponDataAfterOrderCustomerAssign constructor.
*
* @param UpdateCouponUsages $updateCouponUsages
*/
public function __construct(
UpdateCouponUsages $updateCouponUsages
) {
$this->updateCouponUsages = $updateCouponUsages;
}

/**
* @inheritDoc
*/
public function execute(Observer $observer)
{
$event = $observer->getEvent();
/** @var OrderInterface $order */
$order = $event->getData(self::EVENT_KEY_ORDER);

if ($order->getCustomerId()) {
$this->updateCouponUsages->execute($order, true);
}
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/SalesRule/etc/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
<event name="magento_salesrule_api_data_ruleinterface_load_after">
<observer name="legacy_model_load" instance="Magento\Framework\EntityManager\Observer\AfterEntityLoad" />
</event>
<event name="sales_order_customer_assign_after">
<observer name="sales_order_assign_customer_after" instance="Magento\SalesRule\Observer\AssignCouponDataAfterOrderCustomerAssignObserver" />
</event>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function getShipment()
* Configuration for popup window for packaging
*
* @return string
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
public function getConfigDataJson()
{
Expand All @@ -86,7 +87,7 @@ public function getConfigDataJson()
$itemsName = [];
$itemsWeight = [];
$itemsProductId = [];

$itemsOrderItemId = [];
if ($shipmentId) {
$urlParams['shipment_id'] = $shipmentId;
$createLabelUrl = $this->getUrl('adminhtml/order_shipment/createLabel', $urlParams);
Expand Down
Loading

0 comments on commit d20f927

Please sign in to comment.