<?php /** * Copyright (c) 2019 TechDivision GmbH * All rights reserved * * This product includes proprietary software developed at TechDivision GmbH, Germany * For more information see http://www.techdivision.com/ * * To obtain a valid license for using this software please contact us at * license@techdivision.com */ declare(strict_types=1); use Magento\Catalog\Model\Product\Type; use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Address; use Magento\Sales\Model\Order\Item; use Magento\Sales\Model\Order\Payment; use Magento\Store\Model\StoreManagerInterface; use Magento\TestFramework\Helper\Bootstrap; $addressData = [ 'firstname' => 'guest', 'lastname' => 'guest', 'email' => 'customer@example.com', 'street' => 'street', 'city' => 'Los Angeles', 'region' => 'CA', 'postcode' => '1', 'country_id' => 'US', 'telephone' => '1' ]; $paymentMethods = [ 0 => 'checkmo', 1 => 'test_cc', 2 => 'test_cc', 3 => 'invoice', 4 => 'paypal_expr', 5 => 'paypal_expr', ]; $orderStatus = [ 0 => 'pending', 1 => 'pending', 2 => 'processing', 3 => 'pending', 4 => 'processing', 5 => 'processing', ]; for ($counter = 0; $counter <= 5; $counter++) { /** @var $billingAddress Address */ $billingAddress = Bootstrap::getObjectManager()->create(Address::class, ['data' => $addressData]); $billingAddress->setAddressType('billing'); $shippingAddress = clone $billingAddress; $shippingAddress->setId(null)->setAddressType('shipping'); /** @var $payment Payment */ $payment = Bootstrap::getObjectManager()->create(Payment::class); $payment->setMethod($paymentMethods[$counter]); /** @var $orderItem Item */ $orderItem = Bootstrap::getObjectManager()->create(Item::class); $orderItem->setProductId($counter) ->setProductType(Type::TYPE_SIMPLE) ->setName('product name') ->setSku('MET0000' . $counter) ->setBasePrice(100 + $counter) ->setQtyOrdered(1) ->setQtyShipped(1) ->setIsQtyDecimal(true); /** @var StoreManagerInterface $storeManager */ $storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class); /** @var $order Order */ $order = Bootstrap::getObjectManager()->create(Order::class); $order->addItem($orderItem) ->setIncrementId('METEXAMPLE-10' . $counter) ->setSubtotal(100 + $counter) ->setBaseSubtotal(100 + $counter) ->setCustomerIsGuest(true) ->setCustomerEmail('admin@example.com') ->setStatus($orderStatus[$counter]) ->setBillingAddress($billingAddress) ->setShippingAddress($shippingAddress) ->setStoreId($storeManager->getStore()->getId()) ->setPayment($payment); /** @var OrderRepositoryInterface $orderRepository */ $orderRepository = Bootstrap::getObjectManager()->get(OrderRepositoryInterface::class); $orderRepository->save($order); }