/** * @param Cart $cart */ public function updateShippingAndTax(Cart $cart) { $this->countryId = $cart->getCountryId(); $this->shippingType = $cart->getShippingType(); }
/** * @param Cart $cart * @return array */ public static function orderShippingCharge(Cart $cart) { $shippingCharge = null; $suppliers = []; if (count($cart->getItems()) == 0) { return $shippingCharge; } foreach ($cart->getItems() as $cartItem) { /* @var $cartItem CartItem */ $product = $cartItem->getProduct(); if (count($product->getShipping())) { foreach ($product->getShipping() as $sh) { /* @var $sh ProductShippingOption */ if ($sh->getMatch($cart->getCountryId(), $cart->getShippingType())) { if ($sh->getSupplierId()) { $suppliers[$sh->getSupplierId()] = $sh->getOrderPrice(); } else { $suppliers[0] = $sh->getOrderPrice(); } } } } } $shippingCharge = false; foreach ($suppliers as $supplierId => $value) { $shippingCharge += $value; } // return null if no shipping charge applies return $shippingCharge !== false ? $shippingCharge : NULL; }