quote_sec_website.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. use Magento\Catalog\Api\Data\ProductInterface;
  8. use Magento\Customer\Api\Data\CustomerInterface;
  9. use Magento\Quote\Api\CartRepositoryInterface;
  10. use Magento\Quote\Model\Quote;
  11. use Magento\Quote\Model\Quote\Address;
  12. use Magento\Store\Api\Data\StoreInterface;
  13. use Magento\TestFramework\Helper\Bootstrap;
  14. use Magento\TestFramework\ObjectManager;
  15. /**
  16. * @var CustomerInterface $customer
  17. * @var StoreInterface $store
  18. * @var ProductInterface $product
  19. */
  20. require __DIR__ . '/../../Customer/Fixtures/customer_sec_website.php';
  21. require __DIR__ . '/simple_product.php';
  22. /** @var ObjectManager $objectManager */
  23. $objectManager = Bootstrap::getObjectManager();
  24. $addressData = include __DIR__ . '/../../Customer/Fixtures/address_data.php';
  25. /** @var Address $shippingAddress */
  26. $shippingAddress = $objectManager->create(Address::class, ['data' => $addressData[0]]);
  27. $shippingAddress->setAddressType('shipping');
  28. $billingAddress = clone $shippingAddress;
  29. $billingAddress->setId(null)
  30. ->setAddressType('billing');
  31. /** @var Quote $quote */
  32. $quote = $objectManager->create(
  33. Quote::class,
  34. [
  35. 'data' => [
  36. 'customer_id' => $customer->getId(),
  37. 'store_id' => $store->getId(),
  38. 'reserved_order_id' => '0000032134',
  39. 'is_active' => true,
  40. 'is_multishipping' => false
  41. ]
  42. ]
  43. );
  44. $quote->setShippingAddress($shippingAddress)
  45. ->setBillingAddress($billingAddress)
  46. ->addProduct($product);
  47. $quote->getPayment()
  48. ->setMethod('checkmo');
  49. $quote->getShippingAddress()
  50. ->setShippingMethod('flatrate_flatrate')
  51. ->setCollectShippingRates(true);
  52. $quote->collectTotals();
  53. /** @var CartRepositoryInterface $repository */
  54. $repository = $objectManager->get(CartRepositoryInterface::class);
  55. $repository->save($quote);