コード例 #1
0
 /**
  * @param $items
  * @param null $countryId
  * @param string $shippingType
  * @return Cart
  */
 public function makeFromIds($items, $countryId = null, $shippingType = '')
 {
     $clientInfo = Config::get('clientInfo');
     $priceIncludesTax = $clientInfo->business_settings->tax->price_includes_tax;
     $taxes = ProductTaxOptionFactory::makeFromApi($clientInfo->business_settings->tax->country_tax_rates);
     $defaultTaxRate = TaxCalculator::calculateProductTaxRate($taxes, $countryId, $clientInfo->business_settings->tax->default_tax_rate);
     $params = ['ids' => $items, 'priceIncludesTax' => $priceIncludesTax, 'chargeTaxOnShipping' => $clientInfo->business_settings->tax->charge_tax_on_shipping, 'defaultTaxRate' => $defaultTaxRate, 'countryId' => $countryId, 'shippingType' => $shippingType ? $shippingType : null];
     $cart = new Cart($params);
     $cartItemFactory = new CartItemFactory($this->cartRepository, $cart);
     foreach ($cartItemFactory->makeFromIds($items, $priceIncludesTax, $cart->getDefaultTaxRate()) as $item) {
         $cart->add($item);
     }
     $cart->checkIdList();
     // check for free shipping
     if (isset($clientInfo->business_settings->free_shipping) && $clientInfo->business_settings->free_shipping->free_shipping_enabled) {
         $cart->updateForFreeShipping($this->cartValuesTransformer, $clientInfo->business_settings->free_shipping->free_shipping_minimum_order, $clientInfo->business_settings->free_shipping->free_shipping_countries);
     }
     return $cart;
 }