Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $delivery = $quote->getShippingAddress();
- $delivery->setSameAsBilling(true)
- ->setCollectShippingRates(true)
- ->collectShippingRates()
- ->setShippingMethod('flatrate_flatrate');
- public function apply($cartId, $carrierCode, $methodCode)
- {
- /** @var MagentoQuoteModelQuote $quote */
- $quote = $this->quoteRepository->getActive($cartId);
- if (0 == $quote->getItemsCount()) {
- throw new InputException(__('Shipping method is not applicable for empty cart'));
- }
- if ($quote->isVirtual()) {
- throw new NoSuchEntityException(
- __('Cart contains virtual product(s) only. Shipping method is not applicable.')
- );
- }
- $shippingAddress = $quote->getShippingAddress();
- if (!$shippingAddress->getCountryId()) {
- throw new StateException(__('Shipping address is not set'));
- }
- $shippingAddress->setShippingMethod($carrierCode . '_' . $methodCode);
- }
- object(MagentoFrameworkExceptionStateException)[1380]
- protected 'phrase' =>
- object(MagentoFrameworkPhrase)[1382]
- private 'text' => string 'Shipping address is not set' (length=27)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement