Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. $delivery = $quote->getShippingAddress();
  2. $delivery->setSameAsBilling(true)
  3. ->setCollectShippingRates(true)
  4. ->collectShippingRates()
  5. ->setShippingMethod('flatrate_flatrate');
  6.  
  7. public function apply($cartId, $carrierCode, $methodCode)
  8. {
  9. /** @var MagentoQuoteModelQuote $quote */
  10. $quote = $this->quoteRepository->getActive($cartId);
  11. if (0 == $quote->getItemsCount()) {
  12. throw new InputException(__('Shipping method is not applicable for empty cart'));
  13. }
  14. if ($quote->isVirtual()) {
  15. throw new NoSuchEntityException(
  16. __('Cart contains virtual product(s) only. Shipping method is not applicable.')
  17. );
  18. }
  19. $shippingAddress = $quote->getShippingAddress();
  20. if (!$shippingAddress->getCountryId()) {
  21. throw new StateException(__('Shipping address is not set'));
  22. }
  23. $shippingAddress->setShippingMethod($carrierCode . '_' . $methodCode);
  24. }
  25.  
  26. object(MagentoFrameworkExceptionStateException)[1380]
  27. protected 'phrase' =>
  28. object(MagentoFrameworkPhrase)[1382]
  29. private 'text' => string 'Shipping address is not set' (length=27)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement