예제 #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;
 }
예제 #2
0
 /**
  * @param Cart $cart
  * @param Customer $customer
  * @param CartValuesTransformer $cartValuesTransformer
  * @param CartItemValuesTransformer $cartItemValuesTransformer
  * @param array $params
  * @return Order
  */
 public function fromCart(Cart $cart, Customer $customer, CartValuesTransformer $cartValuesTransformer, CartItemValuesTransformer $cartItemValuesTransformer, $params)
 {
     if (isset($params['shippingaddressId']) && $params['shippingaddressId'] > 0) {
         $shippingAddress = $customer->getAddressFromAddressId($params['shippingaddressId']);
     } else {
         $data = ['address1' => $params['shippingaddress1'], 'address2' => $params['shippingaddress2'], 'address3' => $params['shippingaddress3'], 'city' => $params['shippingcity'], 'state' => $params['shippingstate'], 'postcode' => $params['shippingpostcode'], 'countryId' => $params['shippingcountryId']];
         $shippingAddress = new Address($data);
     }
     if (isset($params['billingAddressSameAsShipping']) && $params['billingAddressSameAsShipping']) {
         $billingAddress = $shippingAddress;
     } else {
         if (isset($params['billingaddressId']) && $params['billingaddressId'] > 0) {
             $billingAddress = $customer->getAddressFromAddressId($params['billingaddressId']);
         } else {
             $data = ['address1' => $params['billingaddress1'], 'address2' => $params['billingaddress2'], 'address3' => $params['billingaddress3'], 'city' => $params['billingcity'], 'state' => $params['billingstate'], 'postcode' => $params['billingpostcode'], 'countryId' => $params['billingcountryId']];
             $billingAddress = new Address($data);
         }
     }
     if (isset($params['billingAddressSameAsShipping'])) {
         $data['billing_address_same_as_shipping'] = true;
     }
     $items = [];
     foreach ($cart->getItems() as $item) {
         /* @var $item CartItem */
         $sku = $item->getSku();
         $cartItemValues = $item->getValues($cartItemValuesTransformer);
         $items[] = new OrderItem(NULL, $item->getVariationId(), $item->getTaxRate(), $cartItemValues['totalBeforeTax'], $item->getQuantity(), $item->getProductName(), $sku, 0, 0);
     }
     // add order item for shipping
     $cartValues = $cart->getValues($cartValuesTransformer);
     if ($cartValues['shipping'] > 0) {
         $items[] = new OrderItem(NULL, NULL, $cart->getDefaultTaxRate(), $cartValues['shipping'] - $cartValues['shippingTax'], 1, $cart->getShippingType(), 'SHIPPING', 1, 0);
     }
     $order = new Order($customer, $billingAddress, $shippingAddress, $items, $cart->getShippingType());
     return $order;
 }