Skip to content

Commit 69761ae

Browse files
committed
MC-6420: Ship Order API. Two bundle products with ship bundle items set to separately in order
1 parent f70c7d1 commit 69761ae

File tree

4 files changed

+68
-39
lines changed

4 files changed

+68
-39
lines changed

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ public function testPartialShipOrderWithBundleShippedSeparately()
236236
*/
237237
public function testPartialShipOrderWithTwoBundleShippedSeparatelyContainsSameSimple()
238238
{
239-
/** @var Order $order */
240239
$order = $this->getOrder('order_bundle_separately_shipped');
241240

242241
$requestData = [
@@ -246,7 +245,7 @@ public function testPartialShipOrderWithTwoBundleShippedSeparatelyContainsSameSi
246245
'comment' => 'Test Comment',
247246
'is_visible_on_front' => 1,
248247
],
249-
'tracks' => []
248+
'tracks' => [],
250249
];
251250

252251
$shippedItemId = null;
@@ -274,7 +273,6 @@ public function testPartialShipOrderWithTwoBundleShippedSeparatelyContainsSameSi
274273

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

277-
/** @var Order $existingOrder */
278276
$order = $this->getOrder('order_bundle_separately_shipped');
279277

280278
foreach ($order->getAllItems() as $item) {

dev/tests/integration/testsuite/Magento/Bundle/_files/order_with_2_bundles_shipping_separately.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,35 @@
55
*/
66
declare(strict_types=1);
77

8-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
use Magento\Bundle\Model\Option;
9+
use Magento\Bundle\Model\Product\Type as BundleProductType;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Checkout\Model\Cart;
12+
use Magento\Checkout\Model\Session;
13+
use Magento\Quote\Api\CartManagementInterface;
14+
use Magento\Quote\Model\Quote\Address;
15+
use Magento\Quote\Model\Quote\Payment;
16+
use Magento\Quote\Model\QuoteManagement;
17+
use Magento\TestFramework\Helper\Bootstrap;
918

1019
require __DIR__ . '/two_bundle_products_with_separate_shipping.php';
1120
$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
1221

13-
$billingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class, ['data' => $addressData]);
22+
$objectManager = Bootstrap::getObjectManager();
23+
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
1424
$billingAddress->setAddressType('billing');
1525

1626
$shippingAddress = clone $billingAddress;
17-
$shippingAddress->setId(null)->setAddressType('shipping')->setShippingMethod('flatrate_flatrate');
27+
$shippingAddress->setId(null)
28+
->setAddressType('shipping')
29+
->setShippingMethod('flatrate_flatrate');
1830

19-
/** @var \Magento\Quote\Model\Quote\Payment $payment */
20-
$payment = $objectManager->create(\Magento\Quote\Model\Quote\Payment::class);
31+
/** @var Payment $payment */
32+
$payment = $objectManager->create(Payment::class);
2133
$payment->setMethod('checkmo');
2234

23-
/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
24-
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
35+
/** @var ProductRepositoryInterface $productRepository */
36+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
2537

2638
$bundleProduct = $productRepository->get('bundle-product-separate-shipping-1');
2739
$bundleProduct2 = $productRepository->get('bundle-product-separate-shipping-2');
@@ -30,21 +42,22 @@
3042
$bundleProduct2->getId() => [11, 13],
3143
];
3244

33-
/** @var $cart \Magento\Checkout\Model\Cart */
34-
$cart = $objectManager->create(\Magento\Checkout\Model\Cart::class);
45+
/** @var Cart $cart */
46+
$cart = $objectManager->create(Cart::class);
3547

3648
foreach ([$bundleProduct, $bundleProduct2] as $product) {
3749

38-
/** @var $typeInstance \Magento\Bundle\Model\Product\Type */
50+
/** @var BundleProductType $typeInstance */
3951
$typeInstance = $product->getTypeInstance();
4052
$typeInstance->setStoreFilter($product->getStoreId(), $product);
4153
$optionCollection = $typeInstance->getOptionsCollection($product);
4254

4355
$bundleOptions = [];
4456
$bundleOptionsQty = [];
4557
$optionsData = [];
58+
59+
/** @var Option $option */
4660
foreach ($optionCollection as $option) {
47-
/** @var $option \Magento\Bundle\Model\Option */
4861
$selectionsCollection = $typeInstance->getSelectionsCollection([$option->getId()], $product);
4962
$selectionIds = $selectionProducts[$product->getId()];
5063
$selectionsCollection->addIdFilter($selectionIds);
@@ -73,12 +86,12 @@
7386
->setReservedOrderId('order_bundle_separately_shipped')
7487
->setBillingAddress($billingAddress)
7588
->setShippingAddress($shippingAddress)
76-
->setCheckoutMethod(\Magento\Quote\Api\CartManagementInterface::METHOD_GUEST)
89+
->setCheckoutMethod(CartManagementInterface::METHOD_GUEST)
7790
->setPayment($payment);
7891
$cart->save();
7992

80-
/** @var \Magento\Quote\Model\QuoteManagement $quoteManager */
81-
$quoteManager = $objectManager->get(\Magento\Quote\Model\QuoteManagement::class);
93+
/** @var QuoteManagement $quoteManager */
94+
$quoteManager = $objectManager->get(QuoteManagement::class);
8295
$orderId = $quoteManager->placeOrder($cart->getQuote()->getId());
8396

84-
$objectManager->removeSharedInstance(\Magento\Checkout\Model\Session::class);
97+
$objectManager->removeSharedInstance(Session::class);

dev/tests/integration/testsuite/Magento/Bundle/_files/two_bundle_products_with_separate_shipping.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,44 @@
55
*/
66
declare(strict_types=1);
77

8+
use Magento\Bundle\Api\Data\LinkInterfaceFactory;
9+
use Magento\Bundle\Api\Data\OptionInterfaceFactory;
10+
use Magento\Bundle\Model\Product\Price as BundlePrice;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
13+
use Magento\Catalog\Model\Product\Type as BundleProductType;
14+
use Magento\Catalog\Model\Product\Visibility;
15+
use Magento\Catalog\Model\ProductFactory;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
818
require __DIR__ . '/multiple_products.php';
919

10-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
20+
$objectManager = Bootstrap::getObjectManager();
21+
22+
/** @var ProductRepositoryInterface $productRepository */
23+
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
24+
25+
/** @var ProductFactory $productFactory */
26+
$productFactory = $objectManager->create(ProductFactory::class);
27+
28+
/** @var OptionInterfaceFactory $bundleOptionFactory */
29+
$bundleOptionFactory = $objectManager->create(OptionInterfaceFactory::class);
1130

12-
/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
13-
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
14-
/** @var \Magento\Catalog\Model\ProductFactory $productFactory */
15-
$productFactory = $objectManager->create(\Magento\Catalog\Model\ProductFactory::class);
16-
/** @var \Magento\Bundle\Api\Data\OptionInterfaceFactory $bundleOptionFactory */
17-
$bundleOptionFactory = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class);
18-
/** @var \Magento\Bundle\Api\Data\LinkInterfaceFactory $bundleLinkFactory */
19-
$bundleLinkFactory = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class);
31+
/** @var LinkInterfaceFactory $bundleLinkFactory */
32+
$bundleLinkFactory = $objectManager->create(LinkInterfaceFactory::class);
2033

21-
/** @var $bundleProduct \Magento\Catalog\Model\Product */
2234
$bundleProduct = $productFactory->create();
23-
$bundleProduct->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
24-
->setAttributeSetId(4)
35+
$attributeSetId = $bundleProduct->getDefaultAttributeSetId();
36+
$bundleProduct->setTypeId(BundleProductType::TYPE_BUNDLE)
37+
->setAttributeSetId($attributeSetId)
2538
->setWebsiteIds([1])
2639
->setName('Bundle Product With Separate Items Shipping')
2740
->setSku('bundle-product-separate-shipping-1')
28-
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
29-
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
41+
->setVisibility(Visibility::VISIBILITY_BOTH)
42+
->setStatus(Status::STATUS_ENABLED)
3043
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
3144
->setPriceView(1)
32-
->setPriceType(1)
45+
->setPriceType(BundlePrice::PRICE_TYPE_FIXED)
3346
->setPrice(10.0)
3447
->setShipmentType(1)
3548
->setBundleOptionsData(

dev/tests/integration/testsuite/Magento/Bundle/_files/two_bundle_products_with_separate_shipping_rollback.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
55
*/
66
declare(strict_types=1);
77

8-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
912

10-
/** @var \Magento\Framework\Registry $registry */
11-
$registry = $objectManager->get(\Magento\Framework\Registry::class);
13+
$objectManager = Bootstrap::getObjectManager();
14+
15+
/** @var Registry $registry */
16+
$registry = $objectManager->get(Registry::class);
1217

1318
$registry->unregister('isSecureArea');
1419
$registry->register('isSecureArea', true);
1520

16-
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
17-
$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
21+
/** @var ProductRepositoryInterface $productRepository */
22+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
1823

1924
try {
2025
$productRepository->deleteById('bundle-product-separate-shipping-1');
2126
$productRepository->deleteById('bundle-product-separate-shipping-2');
22-
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
27+
} catch (NoSuchEntityException $exception) {
2328
// When DbIsolation is used products can be already removed by rollback main transaction
2429
}
2530

0 commit comments

Comments
 (0)