quote_payflowpro.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Magento\Catalog\Api\Data\ProductInterface;
  7. use Magento\Catalog\Api\ProductRepositoryInterface;
  8. use Magento\CatalogInventory\Api\Data\StockItemInterface;
  9. use Magento\Framework\ObjectManagerInterface;
  10. use Magento\Quote\Model\Quote;
  11. use Magento\Quote\Model\Quote\Address;
  12. use Magento\Quote\Model\QuoteRepository;
  13. use Magento\TestFramework\Helper\Bootstrap;
  14. require 'fixed_discount.php';
  15. /** @var ObjectManagerInterface $objectManager */
  16. $objectManager = Bootstrap::getObjectManager();
  17. $addressData = [
  18. 'firstname' => 'John',
  19. 'lastname' => 'Doe',
  20. 'company' => '',
  21. 'email' => 'test@com.com',
  22. 'street' => [
  23. 0 => 'test1',
  24. ],
  25. 'city' => 'Test',
  26. 'region_id' => '1',
  27. 'region' => '',
  28. 'postcode' => '9001',
  29. 'country_id' => 'US',
  30. 'telephone' => '11111111',
  31. ];
  32. /** @var Address $billingAddress */
  33. $billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
  34. $billingAddress->setAddressType('billing');
  35. $shippingAddress = clone $billingAddress;
  36. $shippingAddress->setAddressType('shipping')
  37. ->setId(null);
  38. /** @var Quote $quote */
  39. $quote = $objectManager->create(Quote::class);
  40. $quote->setCustomerIsGuest(true)
  41. ->setReservedOrderId('100000015')
  42. ->setBillingAddress($billingAddress)
  43. ->setShippingAddress($shippingAddress);
  44. /** @var ProductRepositoryInterface $productRepository */
  45. $productRepository = $objectManager->get(ProductRepositoryInterface::class);
  46. for ($i = 1; $i <= 3; $i++) {
  47. /** @var ProductInterface $product */
  48. $product = $objectManager->create(ProductInterface::class);
  49. $product->setTypeId('simple')
  50. ->setName('Simple ' . $i)
  51. ->setSku('simple' . $i)
  52. ->setAttributeSetId(4)
  53. ->setPrice(5.69 + $i * 2)
  54. ->setWeight(1);
  55. /** @var StockItemInterface $stockItem */
  56. $stockItem = $objectManager->create(StockItemInterface::class);
  57. $stockItem->setQty(10)
  58. ->setIsInStock(true);
  59. $extensionAttributes = $product->getExtensionAttributes();
  60. $extensionAttributes->setStockItem($stockItem);
  61. $item = $productRepository->save($product);
  62. $quote->addProduct($item, $i);
  63. }
  64. $quote->setCouponCode($coupon->getCode());
  65. $quote->collectTotals();
  66. /** @var QuoteRepository $quoteRepository */
  67. $quoteRepository = $objectManager->get(QuoteRepository::class);
  68. $quoteRepository->save($quote);