RateRequestProvider.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Test\Integration\Provider;
  6. use Magento\Directory\Model\Currency;
  7. use Magento\Quote\Model\Quote\Address\RateRequest;
  8. use Magento\Quote\Model\Quote\AddressFactory;
  9. use Magento\Quote\Model\Quote\ItemFactory;
  10. use Magento\Quote\Model\QuoteFactory;
  11. use Magento\TestFramework\Helper\Bootstrap;
  12. use Temando\Shipping\Api\Data\Order\OrderReferenceInterface;
  13. use Temando\Shipping\Api\Data\Order\ShippingExperienceInterface;
  14. use Temando\Shipping\Api\Data\Order\ShippingExperienceInterfaceFactory;
  15. use Temando\Shipping\Webservice\Response\Type\OrderResponseType;
  16. use Temando\Shipping\Webservice\Response\Type\QualificationResponseType;
  17. use Temando\Shipping\Webservice\Response\Type\QualificationResponseTypeFactory;
  18. class RateRequestProvider
  19. {
  20. /**
  21. * @return RateRequest[][]
  22. */
  23. public static function getRateRequest()
  24. {
  25. /** @var QuoteFactory $quoteFactory */
  26. $quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
  27. /** @var ItemFactory $quoteItemFactory */
  28. $quoteItemFactory = Bootstrap::getObjectManager()->get(ItemFactory::class);
  29. /** @var AddressFactory $quoteAddressFactory */
  30. $quoteAddressFactory = Bootstrap::getObjectManager()->get(AddressFactory::class);
  31. $updatedAt = '0000';
  32. $createdAt = '1999';
  33. $quoteId = 808;
  34. $addressCompany = 'Foo Customer';
  35. $addressLastname = 'Lastname';
  36. $addressFirstname = 'Foo';
  37. $addressEmail = 'foo@example.com';
  38. $addressTelephone = '1800';
  39. $addressFax = '';
  40. $addressCountryId = 'DE';
  41. $addressRegionId = '91';
  42. $addressRegionCode = 'SAS';
  43. $addressStreet = 'Nonnenstraße 11';
  44. $addressCity = 'Leipzig';
  45. $addressPostalCode = '04229';
  46. $address = $quoteAddressFactory->create(['data' => [
  47. 'company' => $addressCompany,
  48. 'lastname' => $addressLastname,
  49. 'firstname' => $addressFirstname,
  50. 'email' => $addressEmail,
  51. 'telephone' => $addressTelephone,
  52. 'fax' => $addressFax,
  53. 'country_id' => $addressCountryId,
  54. 'region_id' => $addressRegionId,
  55. 'region_code' => $addressRegionCode,
  56. 'street' => $addressStreet,
  57. 'city' => $addressCity,
  58. 'postcode' => $addressPostalCode,
  59. ]]);
  60. // replace by mock in test, address handling is hard to provide
  61. $quote = $quoteFactory->create(['data' => [
  62. 'id' => $quoteId,
  63. 'store_id' => 1,
  64. 'updated_at' => $updatedAt,
  65. 'created_at' => $createdAt,
  66. 'items_qty' => 1,
  67. 'shipping_address' => $address,
  68. 'billing_address' => $address,
  69. ]]);
  70. $quoteItem = $quoteItemFactory->create(['data' => ['qty' => 1]]);
  71. $quoteItem->setQuote($quote);
  72. $allItems = [$quoteItem];
  73. $currency = Bootstrap::getObjectManager()->create(Currency::class, ['data' => ['currency_code' => 'EUR']]);
  74. $rateRequest = new RateRequest([
  75. 'all_items' => $allItems,
  76. 'dest_country_id' => $addressCountryId,
  77. 'dest_region_id' => $addressRegionId,
  78. 'dest_region_code' => $addressRegionCode,
  79. 'dest_street' => $addressStreet,
  80. 'dest_city' => $addressCity,
  81. 'dest_postcode' => $addressPostalCode,
  82. 'package_currency' => $currency,
  83. 'store_id' => '1',
  84. 'website_id' => '1',
  85. ]);
  86. return [
  87. 'request_1' => [
  88. $rateRequest
  89. ]
  90. ];
  91. }
  92. /**
  93. * @return RateRequest|OrderResponseType[][]
  94. */
  95. public static function getRateRequestWithShippingExperience()
  96. {
  97. /** @var QuoteFactory $quoteFactory */
  98. $quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
  99. /** @var ItemFactory $quoteItemFactory */
  100. $quoteItemFactory = Bootstrap::getObjectManager()->get(ItemFactory::class);
  101. /** @var AddressFactory $quoteAddressFactory */
  102. $quoteAddressFactory = Bootstrap::getObjectManager()->get(AddressFactory::class);
  103. /** @var QualificationResponseTypeFactory $qualificationResponseTypeFactory */
  104. $qualificationResponseTypeFactory = Bootstrap::getObjectManager()->get(QualificationResponseTypeFactory::class);
  105. /** @var ShippingExperienceInterfaceFactory $shippingExperienceFactory */
  106. $shippingExperienceFactory = Bootstrap::getObjectManager()->get(ShippingExperienceInterfaceFactory::class);
  107. $updatedAt = '0000';
  108. $createdAt = '1999';
  109. $quoteId = 808;
  110. $addressCountryId = 'DE';
  111. $addressRegionId = '91';
  112. $addressRegionCode = 'SAS';
  113. $addressStreet = 'Nonnenstraße 11';
  114. $addressCity = 'Leipzig';
  115. $addressPostalCode = '04229';
  116. $address = $quoteAddressFactory->create(['data' => [
  117. 'country_id' => $addressCountryId,
  118. 'region_id' => $addressRegionId,
  119. 'region_code' => $addressRegionCode,
  120. 'street' => $addressStreet,
  121. 'city' => $addressCity,
  122. 'postcode' => $addressPostalCode,
  123. ]]);
  124. // replace by mock in test, address handling is hard to provide
  125. $quote = $quoteFactory->create(['data' => [
  126. 'id' => $quoteId,
  127. 'store_id' => 1,
  128. 'updated_at' => $updatedAt,
  129. 'created_at' => $createdAt,
  130. 'items_qty' => 1,
  131. 'shipping_address' => $address,
  132. 'billing_address' => $address,
  133. ]]);
  134. $quoteItem = $quoteItemFactory->create(['data' => ['qty' => 1]]);
  135. $quoteItem->setQuote($quote);
  136. $allItems = [$quoteItem];
  137. $currency = Bootstrap::getObjectManager()->create(Currency::class, ['data' => ['currency_code' => 'EUR']]);
  138. $rateRequest = new RateRequest([
  139. 'all_items' => $allItems,
  140. 'dest_country_id' => $addressCountryId,
  141. 'dest_region_id' => $addressRegionId,
  142. 'dest_region_code' => $addressRegionCode,
  143. 'dest_street' => $addressStreet,
  144. 'dest_city' => $addressCity,
  145. 'dest_postcode' => $addressPostalCode,
  146. 'package_currency' => $currency,
  147. 'store_id' => '1',
  148. 'website_id' => '1',
  149. ]);
  150. /** @var ShippingExperienceInterface $shippingExperience */
  151. $shippingExperience = $shippingExperienceFactory->create([
  152. ShippingExperienceInterface::CODE => 'foo',
  153. ShippingExperienceInterface::COST => '9.09',
  154. ShippingExperienceInterface::LABEL => 'Foo Bar',
  155. ]);
  156. /** @var QualificationResponseType $qualificationResponseType */
  157. $qualificationResponseType = $qualificationResponseTypeFactory->create(['data' => [
  158. OrderReferenceInterface::SHIPPING_EXPERIENCES => [$shippingExperience],
  159. ]]);
  160. return [
  161. 'request_1' => [
  162. $rateRequest,
  163. $qualificationResponseType,
  164. ]
  165. ];
  166. }
  167. }