本文整理汇总了PHP中Carrier::checkCarrierZone方法的典型用法代码示例。如果您正苦于以下问题:PHP Carrier::checkCarrierZone方法的具体用法?PHP Carrier::checkCarrierZone怎么用?PHP Carrier::checkCarrierZone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carrier
的用法示例。
在下文中一共展示了Carrier::checkCarrierZone方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOrderStep
function processOrderStep($params)
{
global $cart, $smarty, $errors, $isVirtualCart, $orderTotal;
$cart->recyclable = (isset($_POST['recyclable']) and !empty($_POST['recyclable'])) ? 1 : 0;
if (isset($_POST['gift']) and !empty($_POST['gift'])) {
if (!Validate::isMessage($_POST['gift_message'])) {
$errors[] = Tools::displayError('invalid gift message');
} else {
$cart->gift = 1;
$cart->gift_message = strip_tags($_POST['gift_message']);
}
} else {
$cart->gift = 0;
}
$address = new Address(intval($cart->id_address_delivery));
if (!Validate::isLoadedObject($address)) {
die(Tools::displayError());
}
if (!($id_zone = Address::getZoneById($address->id))) {
$errors[] = Tools::displayError('no zone match with your address');
}
if (isset($_POST['id_carrier']) and Validate::isInt($_POST['id_carrier']) and sizeof(Carrier::checkCarrierZone(intval($_POST['id_carrier']), intval($id_zone)))) {
$cart->id_carrier = intval($_POST['id_carrier']);
} elseif (!$isVirtualCart) {
$errors[] = Tools::displayError('invalid carrier or no carrier selected');
}
Module::hookExec('extraCarrierDetailsProcess', array('carrier' => new Carrier($cart->id_carrier)));
$cart->update();
}
示例2: getAvailableCarrierList
/**
* 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) {
//.........这里部分代码省略.........
示例3: getAvailableCarrierList
/**
* 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;
}
示例4: _processCarrier
protected function _processCarrier()
{
self::$cart->recyclable = (int) Tools::getValue('recyclable');
self::$cart->gift = (int) Tools::getValue('gift');
if ((int) Tools::getValue('gift')) {
if (!Validate::isMessage($_POST['gift_message'])) {
$this->errors[] = Tools::displayError('Invalid gift message');
} else {
self::$cart->gift_message = strip_tags($_POST['gift_message']);
}
}
if (isset(self::$cookie->id_customer) and self::$cookie->id_customer) {
$address = new Address((int) self::$cart->id_address_delivery);
if (!($id_zone = Address::getZoneById($address->id))) {
$this->errors[] = Tools::displayError('No zone match with your address');
}
} else {
$id_zone = Country::getIdZone((int) Configuration::get('PS_COUNTRY_DEFAULT'));
}
if (Validate::isInt(Tools::getValue('id_carrier')) and sizeof(Carrier::checkCarrierZone((int) Tools::getValue('id_carrier'), (int) $id_zone))) {
self::$cart->id_carrier = (int) Tools::getValue('id_carrier');
} elseif (!self::$cart->isVirtualCart() and (int) Tools::getValue('id_carrier') != 0) {
$this->errors[] = Tools::displayError('Invalid carrier or no carrier selected');
}
Module::hookExec('processCarrier', array('cart' => self::$cart));
return self::$cart->update();
}
示例5: processCarrier
function processCarrier()
{
global $cart, $smarty, $isVirtualCart, $orderTotal;
$errors = array();
$cart->recyclable = (isset($_POST['recyclable']) and !empty($_POST['recyclable'])) ? 1 : 0;
if (isset($_POST['gift']) and !empty($_POST['gift'])) {
if (!Validate::isMessage($_POST['gift_message'])) {
$errors[] = Tools::displayError('invalid gift message');
} else {
$cart->gift = 1;
$cart->gift_message = strip_tags($_POST['gift_message']);
}
} else {
$cart->gift = 0;
}
$address = new Address(intval($cart->id_address_delivery));
if (!Validate::isLoadedObject($address)) {
die(Tools::displayError());
}
if (!($id_zone = Address::getZoneById($address->id))) {
$errors[] = Tools::displayError('no zone match with your address');
}
if (isset($_POST['id_carrier']) and Validate::isInt($_POST['id_carrier']) and sizeof(Carrier::checkCarrierZone(intval($_POST['id_carrier']), intval($id_zone)))) {
$cart->id_carrier = intval($_POST['id_carrier']);
} elseif (!$isVirtualCart) {
$errors[] = Tools::displayError('invalid carrier or no carrier selected');
}
$cart->update();
if (sizeof($errors)) {
$smarty->assign('errors', $errors);
displayCarrier();
include dirname(__FILE__) . '/footer.php';
exit;
}
$orderTotal = $cart->getOrderTotal();
}
示例6: getAvailableCarrierList
/**
* For a given {product, warehouse}, gets the carrier available
*
* @param JeproshopProductModelProduct $product The id of the product, or an array with at least the package size and weight
* @param int $warehouse_id
* @param int $address_delivery_id
* @param int $shop_id
* @param $cart
* @return array
*/
public static function getAvailableCarrierList(JeproshopProductModelProduct $product, $warehouse_id, $address_delivery_id = null, $shop_id = null, $cart = null)
{
if (is_null($shop_id)) {
$shop_id = JeproshopContext::getContext()->shop->shop_id;
}
if (is_null($cart)) {
$cart = JeproshopContext::getContext()->cart;
}
$address_id = (int) (!is_null($address_delivery_id) && $address_delivery_id != 0 ? $address_delivery_id : $cart->address_delivery_id);
if ($address_id) {
$address = new JeproshopAddressModelAddress($address_id);
$zone_id = JeproshopAddressModelAddress::getZoneIdByAddressId($address->address_id);
// Check the country of the address is activated
if (!JeproshopAddressModelAddress::isCountryActiveById($address->address_id)) {
return array();
}
} else {
$country = new JeproshopCountryModelCountry(JeproshopSettingModelSetting::getValue('default_country'));
$izone_id = $country->zone_id;
}
// 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->product_id);
$query->where('pc.id_shop = ' . (int) $shop_id);
$cache_id = 'Carrier::getAvailableCarrierList_' . (int) $product->id . '-' . (int) $id_shop;
if (!Cache::isStored($cache_id)) {
$carriers_for_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
Cache::store($cache_id, $carriers_for_product);
}
$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'];
}
}
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 ($warehouse_id) {
$warehouse = new JeproshopWarehouseModelWarehouse($warehouse_id);
$warehouse_carrier_list = $warehouse->getCarriers();
}
$available_carrier_list = array();
$customer = new JeproshopCustomerModelCustomer($cart->customer_id);
$carriers = JeproshopCarrierModelCarrier::getCarriersForOrder($zone_id, $customer->getGroups(), $cart);
foreach ($carriers as $carrier) {
$available_carrier_list[] = $carrier->carrier_id;
}
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);
}
if ($product->width > 0 || $product->height > 0 || $product->depth > 0 || $product->weight > 0) {
foreach ($carrier_list as $key => $carrier_id) {
$carrier = new JeproshopCarrierModelCarrier($carrier_id);
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;
}