Skip to content

Commit e3d469f

Browse files
ENGCOM-8253: Fixed creating shipping labels in part-shipment #27672
2 parents 2d006d8 + 5b564c5 commit e3d469f

File tree

4 files changed

+157
-1
lines changed

4 files changed

+157
-1
lines changed

app/code/Magento/Shipping/view/adminhtml/templates/order/packaging/popup.phtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ $girthEnabled = $block->isDisplayGirthValue() && $block->isGirthAllowed() ? 1 :
5050
}
5151
});
5252
packaging.setItemQtyCallback(function(itemId){
53-
var item = $$('[name="shipment[items]['+itemId+']"]')[0];
53+
var item = $$('[name="shipment[items]['+itemId+']"]')[0],
54+
itemTitle = $('order_item_' + itemId + '_title');
55+
if (!itemTitle && !item) {
56+
return 0;
57+
}
5458
if (item && !isNaN(item.value)) {
5559
return item.value;
5660
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Shipping\Block\Adminhtml\Order;
7+
8+
use Magento\Backend\Block\Template;
9+
use Magento\Framework\Api\SearchCriteria;
10+
use Magento\Framework\Api\SearchCriteriaBuilder;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\Registry;
13+
use Magento\Sales\Api\Data\OrderInterface;
14+
use Magento\Sales\Api\Data\ShipmentTrackInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit\Framework\TestCase;
17+
use Magento\Sales\Api\OrderRepositoryInterface;
18+
19+
/**
20+
* Class verifies packaging popup.
21+
*
22+
* @magentoAppArea adminhtml
23+
*/
24+
class AddToPackageTest extends TestCase
25+
{
26+
/**
27+
* @var OrderRepositoryInterface
28+
*/
29+
private $orderRepository;
30+
31+
/** @var ObjectManagerInterface */
32+
private $objectManager;
33+
34+
/** @var Registry */
35+
private $registry;
36+
37+
protected function setUp(): void
38+
{
39+
$this->objectManager = Bootstrap::getObjectManager();
40+
$this->registry = $this->objectManager->get(Registry::class);
41+
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
42+
}
43+
44+
/**
45+
* Loads order entity by provided order increment ID.
46+
*
47+
* @param string $incrementId
48+
* @return OrderInterface
49+
*/
50+
private function getOrderByIncrementId(string $incrementId) : OrderInterface
51+
{
52+
/** @var SearchCriteria $searchCriteria */
53+
$searchCriteria = $this->objectManager->get(SearchCriteriaBuilder::class)
54+
->addFilter('increment_id', $incrementId)
55+
->create();
56+
57+
$items = $this->orderRepository->getList($searchCriteria)
58+
->getItems();
59+
60+
return array_pop($items);
61+
}
62+
63+
/**
64+
* Test that Packaging popup renders
65+
*
66+
* @magentoDataFixture Magento/Shipping/_files/shipping_with_carrier_data.php
67+
*/
68+
public function testGetCommentsHtml()
69+
{
70+
/** @var Template $block */
71+
$block = $this->objectManager->get(Packaging::class);
72+
73+
$order = $this->getOrderByIncrementId('100000001');
74+
75+
/** @var ShipmentTrackInterface $track */
76+
$shipment = $order->getShipmentsCollection()->getFirstItem();
77+
78+
$this->registry->register('current_shipment', $shipment);
79+
80+
$block->setTemplate('Magento_Shipping::order/packaging/popup.phtml');
81+
$html = $block->toHtml();
82+
$expectedNeedle = "packaging.setItemQtyCallback(function(itemId){
83+
var item = $$('[name=\"shipment[items]['+itemId+']\"]')[0],
84+
itemTitle = $('order_item_' + itemId + '_title');
85+
if (!itemTitle && !item) {
86+
return 0;
87+
}
88+
if (item && !isNaN(item.value)) {
89+
return item.value;
90+
}
91+
});";
92+
$this->assertStringContainsString($expectedNeedle, $html);
93+
}
94+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Sales\Api\Data\OrderInterfaceFactory;
10+
use Magento\Sales\Api\OrderRepositoryInterface;
11+
use Magento\Sales\Model\Order;
12+
use Magento\Sales\Model\Order\ShipmentFactory;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
15+
use Magento\Framework\DB\Transaction;
16+
17+
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/order_with_customer.php');
18+
19+
$objectManager = Bootstrap::getObjectManager();
20+
/** @var Transaction $transaction */
21+
$transaction = $objectManager->get(Transaction::class);
22+
/** @var ProductRepositoryInterface $productRepository */
23+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
24+
$product = $productRepository->get('simple');
25+
/** @var Order $order */
26+
$order = $objectManager->get(OrderInterfaceFactory::class)->create()->loadByIncrementId('100000001');
27+
$order->setShippingDescription('UPS Next Day Air')
28+
->setShippingMethod('ups_11')
29+
->setShippingAmount(0)
30+
->setCouponCode('1234567890')
31+
->setDiscountDescription('1234567890');
32+
33+
/** @var OrderRepositoryInterface $orderRepository */
34+
$orderRepository = $objectManager->create(OrderRepositoryInterface::class);
35+
$orderRepository->save($order);
36+
37+
$shipmentItems = [];
38+
foreach ($order->getItems() as $orderItem) {
39+
$shipmentItems[$orderItem->getId()] = $orderItem->getQtyOrdered();
40+
}
41+
$tracking = [
42+
'carrier_code' => 'ups',
43+
'title' => 'United Parcel Service',
44+
'number' => '987654321'
45+
];
46+
47+
$shipment = $objectManager->get(ShipmentFactory::class)->create($order, $shipmentItems, [$tracking]);
48+
$shipment->register();
49+
$transaction->addObject($shipment)->addObject($order)->save();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
8+
9+
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/order_with_customer_rollback.php');

0 commit comments

Comments
 (0)