Skip to content

Commit

Permalink
Merge pull request #1668 from magento-plankton/MAGETWO-80191
Browse files Browse the repository at this point in the history
[Plankton] Fixes
 - MAGETWO-80191: [2.2.x] - Fixes #10255: base_shipping_discount_tax_compensation_amnt was empty from order onwards #10435
 - MAGETWO-80203 [2.2.x]: - FIX for issue 9930 - Asymmetric Transaction Error with ElasticSearch #10610
 - MAGETWO-62981: Cannot save category position after drag&drop (second attempt)
 - MAGETWO-82339: Duplicate Shipment getting created
  • Loading branch information
ishakhsuvarov authored Nov 7, 2017
2 parents 0483421 + 0b2196e commit df73677
Show file tree
Hide file tree
Showing 17 changed files with 614 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public function addImage(
$mediaGalleryData['images'][] = [
'file' => $fileName,
'position' => $position,
'media_type' => 'image',
'label' => '',
'disabled' => (int)$exclude,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
}
};

var treeRoot = '#tree-div';

/**
* Fix ext compatibility with prototype 1.6
*/
Expand Down Expand Up @@ -491,7 +493,7 @@
if (data.error) {
reRenderTree();
} else {
$(obj.tree.container.dom).trigger('categoryMove.tree');
$(treeRoot).trigger('categoryMove.tree');
}
$('.page-main-actions').next('.messages').remove();
$('.page-main-actions').next('#messages').remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ class OrderRegistrar implements \Magento\Sales\Model\Order\Shipment\OrderRegistr
*/
public function register(OrderInterface $order, ShipmentInterface $shipment)
{
/** @var \Magento\Sales\Api\Data\ShipmentItemInterface|\Magento\Sales\Model\Order\Shipment\Item $item */
$totalQty = 0;
/** @var \Magento\Sales\Model\Order\Shipment\Item $item */
foreach ($shipment->getItems() as $item) {
if ($item->getQty() > 0) {
$item->register();

if (!$item->getOrderItem()->isDummy(true)) {
$totalQty += $item->getQty();
}
}
}
$shipment->setTotalQty($totalQty);

return $order;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private function getQuantitiesFromOrderItems(array $items)
{
$shipmentItems = [];
foreach ($items as $item) {
if (!$item->getIsVirtual() && !$item->getParentItem()) {
if (!$item->getIsVirtual() && (!$item->getParentItem() || $item->isShipSeparately())) {
$shipmentItems[$item->getItemId()] = $item->getQtyOrdered();
}
}
Expand Down
70 changes: 62 additions & 8 deletions app/code/Magento/Sales/Model/Order/ShipmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ protected function prepareItems(
\Magento\Sales\Model\Order $order,
array $items = []
) {
$totalQty = 0;
$shipmentItems = [];
foreach ($order->getAllItems() as $orderItem) {
if (!$this->canShipItem($orderItem, $items)) {
if ($this->validateItem($orderItem, $items) === false) {
continue;
}

/** @var \Magento\Sales\Model\Order\Shipment\Item $item */
$item = $this->converter->itemToShipmentItem($orderItem);
if ($orderItem->getIsVirtual() || $orderItem->getParentItemId()) {
if ($orderItem->getIsVirtual() || ($orderItem->getParentItemId() && !$orderItem->isShipSeparately())) {
$item->isDeleted(true);
}

Expand All @@ -124,8 +124,7 @@ protected function prepareItems(
$qty = min($qty, $orderItem->getSimpleQtyToShip());

$item->setQty($this->castQty($orderItem, $qty));
$shipment->addItem($item);

$shipmentItems[] = $item;
continue;
} else {
$qty = 1;
Expand All @@ -144,10 +143,65 @@ protected function prepareItems(
}
}

$totalQty += $qty;

$item->setQty($this->castQty($orderItem, $qty));
$shipment->addItem($item);
$shipmentItems[] = $item;
}
return $this->setItemsToShipment($shipment, $shipmentItems);
}

/**
* Validate order item before shipment
*
* @param Item $orderItem
* @param array $items
* @return bool
*/
private function validateItem(\Magento\Sales\Model\Order\Item $orderItem, array $items)
{
if (!$this->canShipItem($orderItem, $items)) {
return false;
}

// Remove from shipment items without qty or with qty=0
if (!$orderItem->isDummy(true)
&& (!isset($items[$orderItem->getId()]) || $items[$orderItem->getId()] <= 0)
) {
return false;
}
return true;
}

/**
* Set prepared items to shipment document
*
* @param \Magento\Sales\Api\Data\ShipmentInterface $shipment
* @param array $shipmentItems
* @return \Magento\Sales\Api\Data\ShipmentInterface
*/
private function setItemsToShipment(\Magento\Sales\Api\Data\ShipmentInterface $shipment, $shipmentItems)
{
$totalQty = 0;

/**
* Verify that composite products shipped separately has children, if not -> remove from collection
*/
/** @var \Magento\Sales\Model\Order\Shipment\Item $shipmentItem */
foreach ($shipmentItems as $key => $shipmentItem) {
if ($shipmentItem->getOrderItem()->getHasChildren()
&& $shipmentItem->getOrderItem()->isShipSeparately()
) {
$containerId = $shipmentItem->getOrderItem()->getId();
$childItems = array_filter($shipmentItems, function ($item) use ($containerId) {
return $containerId == $item->getOrderItem()->getParentItemId();
});

if (count($childItems) <= 0) {
unset($shipmentItems[$key]);
continue;
}
}
$totalQty += $shipmentItem->getQty();
$shipment->addItem($shipmentItem);
}
return $shipment->setTotalQty($totalQty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,20 @@ protected function setUp()
public function testRegister()
{
$item1 = $this->getShipmentItemMock();
$item1->expects($this->once())
->method('getQty')
->willReturn(0);
$item1->expects($this->never())
->method('register');
$item1->expects($this->once())->method('getQty')->willReturn(0);
$item1->expects($this->never())->method('register');
$item1->expects($this->never())->method('getOrderItem');

$item2 = $this->getShipmentItemMock();
$item2->expects($this->once())
->method('getQty')
->willReturn(0.5);
$item2->expects($this->once())
->method('register');
$item2->expects($this->atLeastOnce())->method('getQty')->willReturn(0.5);
$item2->expects($this->once())->method('register');

$orderItemMock = $this->createMock(\Magento\Sales\Model\Order\Item::class);
$orderItemMock->expects($this->once())->method('isDummy')->with(true)->willReturn(false);
$item2->expects($this->once())->method('getOrderItem')->willReturn($orderItemMock);

$items = [$item1, $item2];
$this->shipmentMock->expects($this->once())
->method('getItems')
->willReturn($items);
$this->shipmentMock->expects($this->once())->method('getItems')->willReturn($items);
$this->assertEquals(
$this->orderMock,
$this->model->register($this->orderMock, $this->shipmentMock)
Expand All @@ -67,7 +64,7 @@ private function getShipmentItemMock()
{
return $this->getMockBuilder(\Magento\Sales\Api\Data\ShipmentItemInterface::class)
->disableOriginalConstructor()
->setMethods(['register'])
->setMethods(['register', 'getOrderItem'])
->getMockForAbstractClass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@ public function testCreate($tracks)
$orderItem->expects($this->any())->method('getParentItemId')->willReturn(false);
$orderItem->expects($this->any())->method('getIsVirtual')->willReturn(false);

$shipmentItem = $this->createPartialMock(\Magento\Sales\Model\Order\Shipment\Item::class, ['setQty']);
$shipmentItem = $this->createPartialMock(
\Magento\Sales\Model\Order\Shipment\Item::class,
['setQty', 'getOrderItem', 'getQty']
);
$shipmentItem->expects($this->once())
->method('setQty')
->with(5);
$shipmentItem->expects($this->once())
->method('getQty')
->willReturn(5);

$shipmentItem->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($orderItem);

$order = $this->createPartialMock(\Magento\Sales\Model\Order::class, ['getAllItems']);
$order->expects($this->any())
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/etc/fieldset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
<aspect name="to_order" />
</field>
<field name="base_shipping_discount_tax_compensation_amount">
<aspect name="to_order" />
<aspect name="to_order" targetField="base_shipping_discount_tax_compensation_amnt"/>
</field>
<field name="prefix">
<aspect name="to_order_address" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</tr>
</thead>
<?php $_items = $block->getShipment()->getAllItems() ?>
<?php $_i = 0; foreach ($_items as $_item): $_i++ ?>
<?php $_i = 0; foreach ($_items as $_item): if ($_item->getOrderItem()->getParentItem()): continue; endif; $_i++ ?>
<tbody class="<?= /* @escapeNotVerified */ $_i%2 ? 'odd' : 'even' ?>">
<?= $block->getItemHtml($_item) ?>
<?= $block->getItemExtraInfoHtml($_item->getOrderItem()) ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</tr>
</thead>
<?php $_items = $block->getShipment()->getAllItems() ?>
<?php $_i = 0; foreach ($_items as $_item): $_i++ ?>
<?php $_i = 0; foreach ($_items as $_item): if ($_item->getOrderItem()->getParentItem()): continue; endif; $_i++ ?>
<tbody class="<?= /* @escapeNotVerified */ $_i%2 ? 'odd' : 'even' ?>">
<?= $block->getItemHtml($_item) ?>
<?= $block->getItemExtraInfoHtml($_item->getOrderItem()) ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,11 @@ public function testConfigurableShipOrder()
$existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
->loadByIncrementId('100000001');

$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/ship',
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_READ_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_READ_NAME . 'execute',
],
];

$requestData = [
'orderId' => $existingOrder->getId(),
];

$shipmentId = (int)$this->_webApiCall($serviceInfo, $requestData);
$shipmentId = (int)$this->_webApiCall($this->getServiceInfo($existingOrder), $requestData);
$this->assertNotEmpty($shipmentId);

try {
Expand Down Expand Up @@ -98,18 +86,6 @@ public function testShipOrder()
$existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
->loadByIncrementId('100000001');

$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/ship',
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_READ_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_READ_NAME . 'execute',
],
];

$requestData = [
'orderId' => $existingOrder->getId(),
'items' => [],
Expand All @@ -134,7 +110,7 @@ public function testShipOrder()
];
}

$result = $this->_webApiCall($serviceInfo, $requestData);
$result = $this->_webApiCall($this->getServiceInfo($existingOrder), $requestData);

$this->assertNotEmpty($result);

Expand All @@ -154,4 +130,85 @@ public function testShipOrder()
'Failed asserting that Order status was changed'
);
}

/**
* @magentoApiDataFixture Magento/Bundle/_files/order_with_bundle_shipped_separately.php
*/
public function testPartialShipOrderWithBundleShippedSeparately()
{
/** @var \Magento\Sales\Model\Order $existingOrder */
$existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
->loadByIncrementId('100000001');

$requestData = [
'orderId' => $existingOrder->getId(),
'items' => [],
'comment' => [
'comment' => 'Test Comment',
'is_visible_on_front' => 1,
],
'tracks' => [
[
'track_number' => 'TEST_TRACK_0001',
'title' => 'Simple shipment track',
'carrier_code' => 'UPS'
]
]
];

$shippedItemId = null;
foreach ($existingOrder->getAllItems() as $item) {
if ($item->getProductType() == 'simple') {
$requestData['items'][] = [
'order_item_id' => $item->getItemId(),
'qty' => $item->getQtyOrdered(),
];
$shippedItemId = $item->getItemId();
break;
}
}

$shipmentId = $this->_webApiCall($this->getServiceInfo($existingOrder), $requestData);
$this->assertNotEmpty($shipmentId);

try {
$shipment = $this->shipmentRepository->get($shipmentId);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$this->fail('Failed asserting that Shipment was created');
}

$this->assertEquals(1, $shipment->getTotalQty());

/** @var \Magento\Sales\Model\Order $existingOrder */
$existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
->loadByIncrementId('100000001');

foreach ($existingOrder->getAllItems() as $item) {
if ($item->getItemId() == $shippedItemId) {
$this->assertEquals(1, $item->getQtyShipped());
continue;
}
$this->assertEquals(0, $item->getQtyShipped());
}
}

/**
* @param \Magento\Sales\Model\Order $order
* @return array
*/
private function getServiceInfo(\Magento\Sales\Model\Order $order)
{
$serviceInfo = [
'rest' => [
'resourcePath' => '/V1/order/' . $order->getId() . '/ship',
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_READ_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_READ_NAME . 'execute',
],
];
return $serviceInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function isCategoryVisible(Category $category)
*/
public function assignCategory($parentCategoryName, $childCategoryName)
{
$this->_rootElement->find(sprintf($this->categoryInTree, $childCategoryName), Locator::SELECTOR_XPATH)->click();
$this->_rootElement->find(sprintf($this->categoryInTree, $childCategoryName), Locator::SELECTOR_XPATH)->hover();
$this->getTemplateBlock()->waitLoader();
$targetElement = $this->_rootElement->find(
sprintf($this->categoryInTree, $parentCategoryName),
Expand Down
Loading

0 comments on commit df73677

Please sign in to comment.