public function run() { $this->init(); $this->preProcess(); if (Tools::getValue('ajax') == 'true') { if (Tools::getIsset('summary')) { if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { if (self::$cookie->id_customer) { $customer = new Customer((int) self::$cookie->id_customer); $groups = $customer->getGroups(); } else { $groups = array(1); } if ((int) self::$cart->id_address_delivery) { $deliveryAddress = new Address((int) self::$cart->id_address_delivery); } $result = array('carriers' => Carrier::getCarriersForOrder((int) Country::getIdZone((isset($deliveryAddress) and (int) $deliveryAddress->id) ? (int) $deliveryAddress->id_country : (int) Configuration::get('PS_COUNTRY_DEFAULT')), $groups)); } $result['summary'] = self::$cart->getSummaryDetails(); $result['customizedDatas'] = Product::getAllCustomizedDatas((int) self::$cart->id); $result['HOOK_SHOPPING_CART'] = Module::hookExec('shoppingCart', $result['summary']); $result['HOOK_SHOPPING_CART_EXTRA'] = Module::hookExec('shoppingCartExtra', $result['summary']); die(Tools::jsonEncode($result)); } else { $this->includeCartModule(); } } else { $this->setMedia(); $this->displayHeader(); $this->process(); $this->displayContent(); $this->displayFooter(); } }
/** * For a given {product, warehouse}, gets the carrier available * * @since 1.5.0 * * @param Product $product The id of the product, or an array with at least the package size and weight * @param int $id_warehouse Warehouse ID * @param int $id_address_delivery Delivery Address ID * @param int $id_shop Shop ID * @param Cart $cart Cart object * @param array &$error contain an error message if an error occurs * * @return array Available Carriers * @throws PrestaShopDatabaseException */ public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null, &$error = array()) { static $ps_country_default = null; if ($ps_country_default === null) { $ps_country_default = Configuration::get('PS_COUNTRY_DEFAULT'); } if (is_null($id_shop)) { $id_shop = Context::getContext()->shop->id; } if (is_null($cart)) { $cart = Context::getContext()->cart; } if (is_null($error) || !is_array($error)) { $error = array(); } $id_address = (int) (!is_null($id_address_delivery) && $id_address_delivery != 0 ? $id_address_delivery : $cart->id_address_delivery); if ($id_address) { $id_zone = Address::getZoneById($id_address); // Check the country of the address is activated if (!Address::isCountryActiveById($id_address)) { return array(); } } else { $country = new Country($ps_country_default); $id_zone = $country->id_zone; } // Does the product is linked with carriers? $cache_id = 'Carrier::getAvailableCarrierList_' . (int) $product->id . '-' . (int) $id_shop; if (!Cache::isStored($cache_id)) { $query = new DbQuery(); $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0 AND c.active = 1'); $query->where('pc.id_product = ' . (int) $product->id); $query->where('pc.id_shop = ' . (int) $id_shop); $carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); Cache::store($cache_id, $carriers_for_product); } else { $carriers_for_product = Cache::retrieve($cache_id); } $carrier_list = array(); if (!empty($carriers_for_product)) { //the product is linked with carriers foreach ($carriers_for_product as $carrier) { //check if the linked carriers are available in current zone if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) { $carrier_list[$carrier['id_carrier']] = $carrier['id_carrier']; } } if (empty($carrier_list)) { return array(); } //no linked carrier are available for this zone } // The product is not directly linked with a carrier // Get all the carriers linked to a warehouse if ($id_warehouse) { $warehouse = new Warehouse($id_warehouse); $warehouse_carrier_list = $warehouse->getCarriers(); } $available_carrier_list = array(); $cache_id = 'Carrier::getAvailableCarrierList_getCarriersForOrder_' . (int) $id_zone . '-' . (int) $cart->id; if (!Cache::isStored($cache_id)) { $customer = new Customer($cart->id_customer); $carrier_error = array(); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups(), $cart, $carrier_error); Cache::store($cache_id, array($carriers, $carrier_error)); } else { list($carriers, $carrier_error) = Cache::retrieve($cache_id); } $error = array_merge($error, $carrier_error); foreach ($carriers as $carrier) { $available_carrier_list[$carrier['id_carrier']] = $carrier['id_carrier']; } if ($carrier_list) { $carrier_list = array_intersect($available_carrier_list, $carrier_list); } else { $carrier_list = $available_carrier_list; } if (isset($warehouse_carrier_list)) { $carrier_list = array_intersect($carrier_list, $warehouse_carrier_list); } $cart_quantity = 0; $cart_weight = 0; foreach ($cart->getProducts(false, false) as $cart_product) { if ($cart_product['id_product'] == $product->id) { $cart_quantity += $cart_product['cart_quantity']; } if (isset($cart_product['weight_attribute']) && $cart_product['weight_attribute'] > 0) { $cart_weight += $cart_product['weight_attribute'] * $cart_product['cart_quantity']; } else { $cart_weight += $cart_product['weight'] * $cart_product['cart_quantity']; } } if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0 || $cart_weight > 0) { foreach ($carrier_list as $key => $id_carrier) { $carrier = new Carrier($id_carrier); // Get the sizes of the carrier and the product and sort them to check if the carrier can take the product. $carrier_sizes = array((int) $carrier->max_width, (int) $carrier->max_height, (int) $carrier->max_depth); $product_sizes = array((int) $product->width, (int) $product->height, (int) $product->depth); rsort($carrier_sizes, SORT_NUMERIC); rsort($product_sizes, SORT_NUMERIC); if ($carrier_sizes[0] > 0 && $carrier_sizes[0] < $product_sizes[0] || $carrier_sizes[1] > 0 && $carrier_sizes[1] < $product_sizes[1] || $carrier_sizes[2] > 0 && $carrier_sizes[2] < $product_sizes[2]) { $error[$carrier->id] = Carrier::SHIPPING_SIZE_EXCEPTION; unset($carrier_list[$key]); } if ($carrier->max_weight > 0 && ($carrier->max_weight < $product->weight * $cart_quantity || $carrier->max_weight < $cart_weight)) { $error[$carrier->id] = Carrier::SHIPPING_WEIGHT_EXCEPTION; unset($carrier_list[$key]); } } } return $carrier_list; }
/** * For a given {product, warehouse}, gets the carrier available * * @since 1.5.0 * @param Product $product The id of the product, or an array with at least the package size and weight * @return array */ public static function getAvailableCarrierList(Product $product, $id_warehouse, $id_address_delivery = null, $id_shop = null, $cart = null) { if (is_null($id_shop)) { $id_shop = Context::getContext()->shop->id; } if (is_null($cart)) { $cart = Context::getContext()->cart; } $id_address = (int) (!is_null($id_address_delivery) && $id_address_delivery != 0 ? $id_address_delivery : $cart->id_address_delivery); if ($id_address) { $address = new Address($id_address); $id_zone = Address::getZoneById($address->id); // Check the country of the address is activated if (!Address::isCountryActiveById($address->id)) { return array(); } } else { $country = new Country(Configuration::get('PS_COUNTRY_DEFAULT')); $id_zone = $country->id_zone; } // Does the product is linked with carriers? $query = new DbQuery(); $query->select('id_carrier'); $query->from('product_carrier', 'pc'); $query->innerJoin('carrier', 'c', 'c.id_reference = pc.id_carrier_reference AND c.deleted = 0'); $query->where('pc.id_product = ' . (int) $product->id); $query->where('pc.id_shop = ' . (int) $id_shop); $carriers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); if (!empty($carriers)) { //the product is linked with carriers $carrier_list = array(); foreach ($carriers as $carrier) { //check if the linked carriers are available in current zone if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) { $carrier_list[] = $carrier['id_carrier']; } } if (!empty($carrier_list)) { return $carrier_list; } else { return array(); } //no linked carrier are available for this zone } $carrier_list = array(); // The product is not dirrectly linked with a carrier // Get all the carriers linked to a warehouse if ($id_warehouse) { $warehouse = new Warehouse($id_warehouse); $warehouse_carrier_list = $warehouse->getCarriers(); } $available_carrier_list = array(); $customer = new Customer($cart->id_customer); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups(), $cart); foreach ($carriers as $carrier) { $available_carrier_list[] = $carrier['id_carrier']; } if (empty($warehouse_carrier_list)) { $carrier_list = $available_carrier_list; } else { $carrier_list = array_intersect($warehouse_carrier_list, $available_carrier_list); } if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0) { foreach ($carrier_list as $key => $id_carrier) { $carrier = new Carrier($id_carrier); if ($carrier->max_width > 0 && $carrier->max_width < $product->width || $carrier->max_height > 0 && $carrier->max_height < $product->height || $carrier->max_depth > 0 && $carrier->max_depth < $product->depth || $carrier->max_weight > 0 && $carrier->max_weight < $product->weight) { unset($carrier_list[$key]); } } } return $carrier_list; }
protected function _assignCarrier() { $customer = new Customer((int) self::$cookie->id_customer); $address = new Address((int) self::$cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups()); $checked = 0; if (Validate::isUnsignedInt(self::$cart->id_carrier) and self::$cart->id_carrier) { $carrier = new Carrier((int) self::$cart->id_carrier); if ($carrier->active and !$carrier->deleted) { $checked = (int) self::$cart->id_carrier; } } self::$smarty->assign(array('checked' => (int) $checked, 'carriers' => $carriers, 'default_carrier' => (int) Configuration::get('PS_CARRIER_DEFAULT'), 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)), 'HOOK_BEFORECARRIER' => Module::hookExec('beforeCarrier', array('carriers' => $carriers)))); }
protected function _getCarrierList() { $address_delivery = new Address(self::$cart->id_address_delivery); if (self::$cookie->id_customer) { $customer = new Customer((int) self::$cookie->id_customer); $groups = $customer->getGroups(); } else { $groups = array(1); } if (!Address::isCountryActiveById((int) self::$cart->id_address_delivery)) { $this->errors[] = Tools::displayError('This address is not in a valid area.'); } elseif (!Validate::isLoadedObject($address_delivery) or $address_delivery->deleted) { $this->errors[] = Tools::displayError('This address is invalid.'); } else { $carriers = Carrier::getCarriersForOrder((int) Address::getZoneById((int) $address_delivery->id), $groups); $result = array('checked' => $this->_setDefaultCarrierSelection($carriers), 'carriers' => $carriers, 'HOOK_BEFORECARRIER' => Module::hookExec('beforeCarrier', array('carriers' => $carriers)), 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address_delivery))); return $result; } if (sizeof($this->errors)) { return array('hasError' => true, 'errors' => $this->errors); } }
protected function _assignCarrier() { $customer = new Customer((int) self::$cookie->id_customer); $address = new Address((int) self::$cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups()); self::$smarty->assign(array('checked' => $this->_setDefaultCarrierSelection($carriers), 'carriers' => $carriers, 'default_carrier' => (int) Configuration::get('PS_CARRIER_DEFAULT'), 'HOOK_EXTRACARRIER' => Module::hookExec('extraCarrier', array('address' => $address)), 'HOOK_BEFORECARRIER' => Module::hookExec('beforeCarrier', array('carriers' => $carriers)))); }
public function getCarriers() { global $cookie, $cart; // code taken from ParentOrderController::_assignCarrier() $customer = new Customer((int) $cookie->id_customer); $address = new Address((int) $cart->id_address_delivery); $id_zone = Address::getZoneById((int) $address->id); $carriers = Carrier::getCarriersForOrder($id_zone, $customer->getGroups()); return $carriers; }
public function getCarriersListByIdZone($id_country, $id_state = 0, $zipcode = 0) { // cookie saving/updating $this->context->cookie->id_country = $id_country; if ($id_state != 0) { $this->context->cookie->id_state = $id_state; } if ($zipcode != 0) { $this->context->cookie->postcode = $zipcode; } $id_zone = 0; if ($id_state != 0) { $id_zone = State::getIdZone($id_state); } if (!$id_zone) { $id_zone = Country::getIdZone($id_country); } // Need to set the infos for carrier module ! $this->context->cookie->id_country = $id_country; $this->context->cookie->id_state = $id_state; $this->context->cookie->postcode = $zipcode; $carriers = Carrier::getCarriersForOrder((int) $id_zone); return sizeof($carriers) ? $carriers : array(); }
public function getCarriersListByIdZone($id_country, $id_state = 0) { global $cart, $smarty; $id_zone = 0; if ($id_state != 0) { $id_zone = State::getIdZone($id_state); } if (!$id_zone) { $id_zone = Country::getIdZone($id_country); } $carriers = Carrier::getCarriersForOrder((int) $id_zone); return sizeof($carriers) ? $carriers : array(); }
/** * create carriers * * @return mixed */ protected function _getCarriers() { $resultsCarrier = array(); $mobileCarrierUse = unserialize(base64_decode(Configuration::get('SG_MOBILE_CARRIER'))); if ($this->_deliveryAddress) { foreach (Carrier::getCarriersForOrder(Address::getZoneById($this->_deliveryAddress->id), $this->getPlugin()->getContext()->customer->getGroups(), $this->getPlugin()->getContext()->cart) as $carrier) { /** @var CarrierCore $carrierItem */ $carrierItem = new Carrier($carrier['id_carrier'], $this->getPlugin()->getContext()->language->id); $taxRulesGroup = new TaxRulesGroup($carrierItem->id_tax_rules_group); $resultCarrier = new ShopgateShippingMethod(); /** * check is defined as mobile carrier */ $idColumn = version_compare(_PS_VERSION_, '1.5.0.1', '>=') ? 'id_reference' : 'id_carrier'; if (is_array($mobileCarrierUse) && empty($mobileCarrierUse[$carrier[$idColumn]])) { continue; } $resultCarrier->setId($carrier['id_carrier']); $resultCarrier->setTitle($carrier['name']); $resultCarrier->setDescription($carrier['delay']); $resultCarrier->setSortOrder($carrier['position']); $resultCarrier->setAmount($carrier['price_tax_exc']); $resultCarrier->setAmountWithTax($carrier['price']); $resultCarrier->setTaxClass($taxRulesGroup->name); if (version_compare(_PS_VERSION_, '1.5.0', '<')) { $carrierTax = Tax::getCarrierTaxRate($carrierItem->id, $this->_deliveryAddress->id); } else { $carrierTax = $carrierItem->getTaxesRate($this->_deliveryAddress); } $resultCarrier->setTaxPercent($carrierTax); $resultCarrier->setInternalShippingInfo(serialize(array('carrierId' => $carrier['id_carrier']))); $resultsCarrier[] = $resultCarrier; } } return $resultsCarrier; }
/** * Get available carrier list for an order * @param Object $order * @return array $delivery_option_list_formated */ protected function getCarrierList($order) { $cart = $this->context->cart; $address = new Address((int) $cart->id_address_delivery); return Carrier::getCarriersForOrder(Address::getZoneById((int) $address->id), null, $cart); }
/** * @param $iso_country_code * @return null|string */ public function shippingCostRetrieveRequest($iso_country_code) { if ($iso_country_code) { $cart = new Cart($this->id_cart); if ($id_country = Country::getByIso($iso_country_code)) { if ($id_zone = Country::getIdZone($id_country)) { $carriers = Carrier::getCarriersForOrder($id_zone); $currency = Currency::getCurrency($cart->id_currency); if ($carriers) { $carrier_list = array(); foreach ($carriers as $carrier) { $c = new Carrier((int) $carrier['id_carrier']); $shipping_method = $c->getShippingMethod(); $price = $shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $carrier['id_carrier']); $price_tax_exc = $shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $carrier['id_carrier'], false); $carrier_list[]['ShippingCost'] = array('Type' => $carrier['name'] . ' (' . $carrier['id_carrier'] . ')', 'CountryCode' => Tools::strtoupper($iso_country_code), 'Price' => array('Gross' => $this->toAmount($price), 'Net' => $this->toAmount($price_tax_exc), 'Tax' => $this->toAmount($price) - $this->toAmount($price_tax_exc), 'CurrencyCode' => Tools::strtoupper($currency['iso_code']))); } $shipping_cost = array('CountryCode' => Tools::strtoupper($iso_country_code), 'ShipToOtherCountry' => 'true', 'ShippingCostList' => $carrier_list); $xml = OpenPayU::buildShippingCostRetrieveResponse($shipping_cost, $this->id_request, $iso_country_code); return $xml; } else { Logger::addLog('carrier by id_zone is undefined'); } } } } return null; }
public function getCarriersListByIdZone($id_country, $id_state = 0, $zipcode = 0) { global $cart, $smarty, $cookie; // cookie saving/updating $cookie->id_country = $id_country; if ($id_state != 0) { $cookie->id_state = $id_state; } if ($zipcode != 0) { $cookie->postcode = $zipcode; } $id_zone = 0; if ($id_state != 0) { $id_zone = State::getIdZone($id_state); } if (!$id_zone) { $id_zone = Country::getIdZone($id_country); } $carriers = Carrier::getCarriersForOrder((int) $id_zone); return sizeof($carriers) ? $carriers : array(); }
public function getCarriersListByIdZone($id_country, $id_state = 0, $zipcode = 0) { global $cart, $smarty, $cookie; // cookie saving/updating $cookie->id_country = $id_country; if ($id_state != 0) { $cookie->id_state = $id_state; } if ($zipcode !== 0) { $cookie->postcode = $zipcode; } $id_zone = 0; if ($id_state != 0) { $id_zone = State::getIdZone($id_state); } if (!$id_zone) { $id_zone = Country::getIdZone($id_country); } // Need to set the infos for carrier module ! $cookie->id_country = $id_country; $cookie->id_state = $id_state; $cookie->postcode = $zipcode; $carriers = array(); if ($this->addAddress($id_country, $zipcode)) { // Back up the current id_address_delivery $current_id_address_delivery = $cart->id_address_delivery; // Get the new one created $cart->id_address_delivery = Configuration::get(CarrierCompare::VIRTUAL_ADDRESS); $cart->id_customer = Configuration::get(CarrierCompare::VIRTUAL_CUSTOMER); // Get carriers with good id_zone $carriers = Carrier::getCarriersForOrder((int) $id_zone); // Delete Address and restore id_address_delivery $address = new Address((int) Configuration::get(CarrierCompare::VIRTUAL_ADDRESS)); $address->delete(); $cart->id_address_delivery = $current_id_address_delivery; } return count($carriers) ? $carriers : array(); }