本文整理汇总了PHP中Address::getCountryAndState方法的典型用法代码示例。如果您正苦于以下问题:PHP Address::getCountryAndState方法的具体用法?PHP Address::getCountryAndState怎么用?PHP Address::getCountryAndState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::getCountryAndState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initContent
public function initContent()
{
$cmofie = "module";
parent::initContent();
${$cmofie} = new AgilePaypal();
$this->context->cart = new Cart();
$this->context->cart->id_lang = intval($this->context->cookie->id_lang);
$this->context->cart->id_currency = intval($this->context->cookie->id_currency);
$jpptxpcvjjk = "sl_expresscheckout_id_country";
$this->context->cart->id_guest = intval($this->context->cookie->id_guest);
$llkzpyey = "id_product";
if ($this->context->cookie->id_customer) {
$this->context->cart->id_customer = intval($this->context->cookie->id_customer);
$this->context->cart->id_address_delivery = intval(Address::getFirstCustomerAddressId($this->context->cart->id_customer));
$this->context->cart->id_address_invoice = $this->context->cart->id_address_delivery;
} else {
$this->context->cart->id_address_delivery = 0;
$this->context->cart->id_address_invoice = 0;
}
${"GLOBALS"}["lpampekuqrwh"] = "id_product";
$this->context->cart->add();
if ($this->context->cart->id) {
$this->context->cookie->id_cart = intval($this->context->cart->id);
}
${$llkzpyey} = (int) Tools::getValue("id_product");
if (${${"GLOBALS"}["hvtkfucisp"]}) {
$this->context->cart->updateQty((int) Tools::getValue("qty"), ${${"GLOBALS"}["lpampekuqrwh"]}, 0, false, "up");
}
${$jpptxpcvjjk} = (int) Configuration::get("PS_COUNTRY_DEFAULT");
if ($this->context->cart->id_address_invoice) {
$sgcgklgjd = "countrystate";
${$sgcgklgjd} = Address::getCountryAndState($this->context->cart->id_address_invoice);
${${"GLOBALS"}["ilrsdjvry"]} = (int) ${${"GLOBALS"}["rlrnvyxftps"]}["id_country"];
}
$this->context->cart->id_address_delivery = ${${"GLOBALS"}["ilrsdjvry"]};
$this->context->cart->id_address_invoice = ${${"GLOBALS"}["ilrsdjvry"]};
${${"GLOBALS"}["smzfojqsh"]} = array("sl_agilepaypalexpress_cycle" => Tools::getValue("sl_agilepaypalexpress_cycle"), "sl_agilepaypalexpress_cycle_base" => Tools::getValue("sl_agilepaypalexpress_cycle_base"), "sl_agilepaypalexpress_cycle_num" => Tools::getValue("sl_agilepaypalexpress_cycle_num"), "sl_expresscheckout_id_country" => ${${"GLOBALS"}["ilrsdjvry"]});
if ($this->context->cart->getOrderTotal() <= 0) {
Tools::redirect("index.php?controller=order");
} else {
if (Tools::getValue("sl_agilepaypalexpress_cycle_num") == 1) {
Tools::redirect($this->context->link->getModuleLink("agilepaypal", "redirect", ${${"GLOBALS"}["smzfojqsh"]}, true));
} else {
Tools::redirect($this->context->link->getModuleLink("agilepaypal", "subscribe", ${${"GLOBALS"}["smzfojqsh"]}, true));
}
}
}
示例2: init
//.........这里部分代码省略.........
$locale = strtolower(Configuration::get('PS_LOCALE_LANGUAGE')) . '_' . strtoupper(Configuration::get('PS_LOCALE_COUNTRY') . '.UTF-8');
setlocale(LC_COLLATE, $locale);
setlocale(LC_CTYPE, $locale);
setlocale(LC_TIME, $locale);
setlocale(LC_NUMERIC, 'en_US.UTF-8');
if (Validate::isLoadedObject($currency)) {
$smarty->ps_currency = $currency;
}
if (Validate::isLoadedObject($ps_language = new Language((int) $cookie->id_lang))) {
$smarty->ps_language = $ps_language;
}
/* get page name to display it in body id */
$pathinfo = pathinfo(__FILE__);
$page_name = basename($_SERVER['PHP_SELF'], '.' . $pathinfo['extension']);
$page_name = preg_match('/^[0-9]/', $page_name) ? 'page_' . $page_name : $page_name;
$smarty->assign(Tools::getMetaTags($cookie->id_lang, $page_name));
$smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
/* Breadcrumb */
$navigationPipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>';
$smarty->assign('navigationPipe', $navigationPipe);
$protocol_link = (Configuration::get('PS_SSL_ENABLED') or !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://';
$protocol_content = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED') or !empty($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://';
if (!defined('_PS_BASE_URL_')) {
define('_PS_BASE_URL_', Tools::getShopDomain(true));
}
if (!defined('_PS_BASE_URL_SSL_')) {
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
}
$link->preloadPageLinks();
$this->canonicalRedirection();
Product::initPricesComputation();
$display_tax_label = $defaultCountry->display_tax_label;
if ($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) {
$infos = Address::getCountryAndState((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$country = new Country((int) $infos['id_country']);
if (Validate::isLoadedObject($country)) {
$display_tax_label = $country->display_tax_label;
}
}
global $isBetaUser, $conversion_rate_inr;
$conversion_rate_inr = 55;
if (!$cookie->isLogged()) {
$this->initFacebook();
} else {
$customer_groups = Customer::getGroupsStatic((int) $cookie->id_customer);
if (in_array(2, $customer_groups)) {
$smarty->assign('internal_vb_user', 1);
}
if (in_array(3, $customer_groups)) {
$isBetaUser = true;
} else {
$isBetaUser = false;
}
/*$reward_points = VBRewards::getCustomerPoints($cookie->id_customer);
$can_redeem = VBRewards::checkPointsValidity($cookie->id_customer, 0);
if($can_redeem)
$smarty->assign('can_redeem_points', 1);
$smarty->assign('balance_points', $reward_points);*/
}
$smarty->assign('img_version', IMG_VERSION);
$this->setRecaptchaHTML();
if ($page_name === "index") {
$sql = "select title,image_path,url from ps_banner where is_active = 1 order by display_order asc";
$home_banners = Db::getInstance()->ExecuteS($sql);
$smarty->assign("home_banners", $home_banners);
}
示例3: getPackageShippingCost
//.........这里部分代码省略.........
//get external shipping cost from module
if ($carrier->shipping_external) {
$module_name = $carrier->external_module_name;
$module = Module::getInstanceByName($module_name);
if (Validate::isLoadedObject($module)) {
if (array_key_exists('id_carrier', $module)) {
$module->id_carrier = $carrier->id;
}
if ($carrier->need_range) {
if (method_exists($module, 'getPackageShippingCost')) {
$shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products);
} else {
$shipping_cost = $module->getOrderShippingCost($this, $shipping_cost);
}
} else {
$shipping_cost = $module->getOrderShippingCostExternal($this);
}
// Check if carrier is available
if ($shipping_cost === false) {
Cache::store($cache_id, false);
return false;
}
} else {
Cache::store($cache_id, false);
return false;
}
}
// Apply tax
if ($use_tax && isset($carrier_tax)) {
$shipping_cost *= 1 + $carrier_tax / 100;
}
// ###############################################################
$num = $this->getTotalWeight($product_list);
$countryAndState = Address::getCountryAndState((int) $this->id_address_delivery);
$state = $countryAndState['id_state'];
$pri = false;
if ($pri) {
echo "carrierid =>" . $id_carrier . "-";
echo 'products => ' . $num . '-';
echo 'state => ' . $state . '-';
}
//Ground
//if( $id_carrier == 21 ){
if ($id_carrier == 31) {
//NO CA
if ($state == 313) {
if ($num == 1) {
$shipping_cost = 19.75;
} elseif ($num == 2) {
$shipping_cost = 20.5;
} elseif ($num == 3) {
$shipping_cost = 22.0;
} elseif ($num == 4) {
$shipping_cost = 24.5;
} elseif ($num == 5) {
$shipping_cost = 25.75;
} elseif ($num == 6) {
$shipping_cost = 27.0;
} elseif ($num == 7) {
$shipping_cost = 30.5;
} elseif ($num == 8) {
$shipping_cost = 31.5;
} elseif ($num == 9) {
$shipping_cost = 32.25;
} elseif ($num == 10) {
$shipping_cost = 33.5;
示例4: _getPricesDropProductsIds
private function _getPricesDropProductsIds()
{
$sqlGroups = '';
if (version_compare(_PS_VERSION_, '1.6.0.0', '>=') && Group::isFeatureActive() && version_compare(_PS_VERSION_, '1.6.0.0', '<')) {
$currentGroups = FrontController::getCurrentCustomerGroups();
$sqlGroups = 'AND cg.`id_group` ' . (is_array($currentGroups) && sizeof($currentGroups) ? 'IN (' . implode(',', $currentGroups) . ')' : '= 1');
}
$currentDate = date('Y-m-d H:i:s');
if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) {
global $cookie, $cart;
$id_group = $cookie->id_customer ? (int) Customer::getDefaultGroupId((int) $cookie->id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
$id_country = (int) ($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
$ids_product = SpecificPrice::getProductIdByDate((int) Shop::getCurrentShop(), (int) $cookie->id_currency, $id_country, $id_group, $currentDate, $currentDate);
} else {
$id_address = $this->_context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
$id_country = (int) ($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
$ids_product = SpecificPrice::getProductIdByDate($this->_context->shop->id, $this->_context->currency->id, $id_country, $this->_context->customer->id_default_group, $currentDate, $currentDate, 0, false);
}
$tab_id_product = array();
foreach ($ids_product as $product) {
if (is_array($product)) {
$tab_id_product[] = (int) $product['id_product'];
} else {
$tab_id_product[] = (int) $product;
}
}
Db::getInstance()->Execute('SET group_concat_max_len := @@max_allowed_packet');
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT GROUP_CONCAT(p.id_product) as pid_list
FROM `' . _DB_PREFIX_ . 'product` p
' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Shop::addSqlAssociation('product', 'p') : '') . '
WHERE ' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p') . '.`active` = 1
AND ' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p') . '.`show_price` = 1
' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? ' AND product_shop.`visibility` IN ("both", "catalog") ' : '') . '
AND ' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p') . '.`id_product` IN (' . (is_array($tab_id_product) && count($tab_id_product) ? implode(', ', $tab_id_product) : 0) . ')
AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `' . _DB_PREFIX_ . 'category_group` cg
LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` ' . $sqlGroups . '
)');
if ($result && isset($result['pid_list']) && !empty($result['pid_list'])) {
return explode(',', $result['pid_list']);
}
return array(0);
}
示例5: _getProductIdByDate
protected function _getProductIdByDate($beginning, $ending, Context $context = null, $with_combination = false)
{
if (!$context) {
$context = Context::getContext();
}
$id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
$id_country = (int) ($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
return SpecificPrice::getProductIdByDate($context->shop->id, $context->currency->id, $id_country, $context->customer->id_default_group, $beginning, $ending, 0, $with_combination);
}
示例6: getApplicableTax
public static function getApplicableTax($id_tax, $productTax, $id_address_delivery = NULL)
{
global $cart, $cookie, $defaultCountry;
if (!$id_address_delivery) {
$id_address_delivery = intval((Validate::isLoadedObject($cart) and $cart->id_address_delivery) ? $cart->id_address_delivery : (isset($cookie->id_address_delivery) ? $cookie->id_address_delivery : 0));
}
/* If customer has an address (implies that he is registered and logged) */
if ($id_address_delivery and $address_ids = Address::getCountryAndState($id_address_delivery)) {
$id_zone_country = Country::getIdZone(intval($address_ids['id_country']));
/* If customer's invoice address is inside a state */
if ($address_ids['id_state']) {
$state = new State(intval($address_ids['id_state']));
if (!Validate::isLoadedObject($state)) {
die(Tools::displayError());
}
/* Return tax value depending to the tax behavior */
$tax_behavior = intval($state->tax_behavior);
if ($tax_behavior == PS_PRODUCT_TAX) {
return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone_country));
}
if ($tax_behavior == PS_STATE_TAX) {
return Tax::getRateByState(intval($address_ids['id_state']));
}
if ($tax_behavior == PS_BOTH_TAX) {
return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone_country)) + Tax::getRateByState(intval($address_ids['id_state']));
}
/* Unknown behavior */
die(Tools::displayError('Unknown tax behavior!'));
}
/* Else getting country zone tax */
if (!($id_zone = Address::getZoneById($id_address_delivery))) {
die(Tools::displayError());
}
return $productTax * Tax::zoneHasTax(intval($id_tax), intval($id_zone));
}
/* Default tax application */
if (!Validate::isLoadedObject($defaultCountry)) {
die(Tools::displayError());
}
return $productTax * Tax::zoneHasTax(intval($id_tax), intval($defaultCountry->id_zone));
}
示例7: getOrderShippingCostExternal
public function getOrderShippingCostExternal($cart, $products = array())
{
if (!$this->id_carrier || !$cart instanceof Cart) {
return false;
}
$cache_key = $this->getCacheKey($cart, $products);
if (isset(self::$carriers[$this->id_carrier][$cache_key])) {
return self::$carriers[$this->id_carrier][$cache_key];
}
$id_address_delivery = empty($products) ? (int) $cart->id_address_delivery : (int) $this->getIdAddressDeliveryByProducts($products);
$id_customer_country = (int) Tools::getValue('id_country');
if (!$id_customer_country) {
$customer_country = Address::getCountryAndState((int) $id_address_delivery);
$id_customer_country = (int) $customer_country['id_country'];
}
$zone = $id_customer_country ? Country::getIdZone((int) $id_customer_country) : Address::getZoneById((int) $id_address_delivery);
if (!($id_method = self::getMethodIdByCarrierId($this->id_carrier))) {
self::$carriers[$this->id_carrier][$cache_key] = false;
return false;
}
$carrier = new Carrier((int) $this->id_carrier);
if (!Validate::isLoadedObject($carrier)) {
return false;
}
$configuration = new DpdGroupConfiguration();
$is_cod_method = $this->isCODCarrier((int) $this->id_carrier);
if ($is_cod_method && !$this->isCODCarrierAvailable($cart, $configuration, (int) $id_customer_country)) {
self::$carriers[$this->id_carrier][$cache_key] = false;
return false;
}
$carrier_shipping_method = $carrier->getShippingMethod();
$order_total_price = empty($products) ? $cart->getOrderTotal(false, Cart::BOTH_WITHOUT_SHIPPING) : $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $products, $this->id_carrier);
$total_weight = empty($products) ? $cart->getTotalWeight() : $cart->getTotalWeight($products);
$cart_total = $carrier_shipping_method == Carrier::SHIPPING_METHOD_WEIGHT ? DpdGroupShipment::convertWeight($total_weight) : $order_total_price;
$price_rule = DpdGroupShipment::getPriceRule($cart_total, $id_method, $id_address_delivery, $is_cod_method);
$additional_shipping_cost = $this->calculateAdditionalShippingCost($cart, $products);
$additional_shipping_cost = Tools::convertPrice($additional_shipping_cost);
$handling_charges = $carrier->shipping_handling ? Configuration::get('PS_SHIPPING_HANDLING') : 0;
$handling_charges = Tools::convertPrice($handling_charges);
$price = false;
switch ($configuration->price_calculation_method) {
case DpdGroupConfiguration::PRICE_CALCULATION_PRESTASHOP:
$price = $this->getPriceByPrestaShopCalculationType($carrier_shipping_method, $carrier, $total_weight, $zone, $additional_shipping_cost, $handling_charges, $is_cod_method, $order_total_price, $configuration, $price_rule);
break;
case DpdGroupConfiguration::PRICE_CALCULATION_WEB_SERVICES:
$price = $this->getPriceByWebServicesCalculationType($cart, $is_cod_method, $order_total_price, $id_method, $id_address_delivery, $additional_shipping_cost, $handling_charges, $configuration, $price_rule, $products);
break;
case DpdGroupConfiguration::PRICE_CALCULATION_CSV:
$price = $this->getPriceByCSVCalculationType($price_rule, $order_total_price, $additional_shipping_cost, $handling_charges, $is_cod_method, $configuration);
break;
}
self::$carriers[$this->id_carrier][$cache_key] = $price;
return self::$carriers[$this->id_carrier][$cache_key];
}
示例8: isDiscounted
public static function isDiscounted($id_product, $quantity = 1, Context $context = null)
{
if (!$context) {
$context = Context::getContext();
}
$id_group = $context->customer->id_default_group;
$cart_quantity = !$context->cart ? 0 : Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT SUM(`quantity`)
FROM `' . _DB_PREFIX_ . 'cart_product`
WHERE `id_product` = ' . (int) $id_product . ' AND `id_cart` = ' . (int) $context->cart->id);
$quantity = $cart_quantity ? $cart_quantity : $quantity;
$id_currency = (int) $context->currency->id;
$ids = Address::getCountryAndState((int) $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$id_country = (int) ($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
return (bool) SpecificPrice::getSpecificPrice((int) $id_product, $context->shop->id, $id_currency, $id_country, $id_group, $quantity);
}
示例9: getProducts
public function getProducts($productList, $id_lang, $colors = array())
{
$context = Context::getContext();
$id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
$id_country = (int) ($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
$sql = 'SELECT p.*, product_shop.*, pl.* , m.`name` AS manufacturer_name, s.`name` AS supplier_name,sp.`id_specific_price`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` ' . Shop::addSqlRestrictionOnLang('pl') . ')
LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
LEFT JOIN `' . _DB_PREFIX_ . 'supplier` s ON (s.`id_supplier` = p.`id_supplier`)
LEFT JOIN `' . _DB_PREFIX_ . 'specific_price` sp ON (sp.`id_product` = p.`id_product`
AND sp.`id_shop` IN(0, ' . (int) $context->shop->id . ')
AND sp.`id_currency` IN(0, ' . (int) $context->currency->id . ')
AND sp.`id_country` IN(0, ' . (int) $id_country . ')
AND sp.`id_group` IN(0, ' . (int) $context->customer->id_default_group . ')
AND sp.`id_customer` IN(0, ' . (int) $context->customer->id . ')
AND sp.`reduction` > 0
)
WHERE pl.`id_lang` = ' . (int) $id_lang . ' AND p.`id_product` in (' . $productList . ')';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if ($productList) {
$tmpImg = array();
$coverImg = array();
$where = ' WHERE i.`id_product` IN (' . $productList . ') AND ish.`id_shop` = ' . Context::getContext()->shop->id;
$order = ' ORDER BY i.`id_product`,`position`';
switch (Configuration::get('LEO_MINFO_SORT')) {
case 'position2':
break;
case 'random':
$order = ' ORDER BY RAND()';
break;
default:
$order = ' ORDER BY i.`id_product`,`position` DESC';
}
$listImg = $this->getAllImages($id_lang, $where, $order);
foreach ($listImg as $val) {
$tmpImg[$val['id_product']][$val['id_image']] = $val;
if ($val['cover'] == 1) {
$coverImg[$val['id_product']] = $val['id_image'];
}
}
}
$now = date('Y-m-d H:i:s');
$finish = $this->l('Expired');
foreach ($result as &$val) {
$time = false;
if (isset($tmpImg[$val['id_product']])) {
$val['images'] = $tmpImg[$val['id_product']];
$val['id_image'] = $coverImg[$val['id_product']];
} else {
$val['images'] = array();
}
$val['specific_prices'] = self::getSpecificPriceById($val['id_specific_price']);
if (isset($val['specific_prices']['from']) && $val['specific_prices']['from'] > $now) {
$time = strtotime($val['specific_prices']['from']);
$val['finish'] = $finish;
$val['check_status'] = 0;
$val['lofdate'] = Tools::displayDate($val['specific_prices']['from']);
} elseif (isset($val['specific_prices']['to']) && $val['specific_prices']['to'] > $now) {
$time = strtotime($val['specific_prices']['to']);
$val['finish'] = $finish;
$val['check_status'] = 1;
$val['lofdate'] = Tools::displayDate($val['specific_prices']['to']);
} elseif (isset($val['specific_prices']['to']) && $val['specific_prices']['to'] == '0000-00-00 00:00:00') {
$val['js'] = 'unlimited';
$val['finish'] = $this->l('Unlimited');
$val['check_status'] = 1;
$val['lofdate'] = $this->l('Unlimited');
} else {
if (isset($val['specific_prices']['to'])) {
$time = strtotime($val['specific_prices']['to']);
$val['finish'] = $finish;
$val['check_status'] = 2;
$val['lofdate'] = Tools::displayDate($val['specific_prices']['from']);
}
}
if ($time) {
$val['js'] = array('month' => date('m', $time), 'day' => date('d', $time), 'year' => date('Y', $time), 'hour' => date('H', $time), 'minute' => date('i', $time), 'seconds' => date('s', $time));
}
}
unset($colors);
return Product::getProductsProperties($id_lang, $result);
}
示例10: init
//.........这里部分代码省略.........
}
die(Tools::displayError());
break;
case 'makeFreeOrder':
/* Bypass payment step if total is 0 */
if (($id_order = $this->_checkFreeOrder()) && $id_order) {
$order = new Order((int) $id_order);
$email = $this->context->customer->email;
if ($this->context->customer->is_guest) {
$this->context->customer->logout();
}
// If guest we clear the cookie for security reason
die('freeorder:' . $order->reference . ':' . $email);
}
exit;
break;
case 'updateAddressesSelected':
if ($this->context->customer->isLogged(true)) {
$address_delivery = new Address((int) Tools::getValue('id_address_delivery'));
$this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart());
$address_invoice = (int) Tools::getValue('id_address_delivery') == (int) Tools::getValue('id_address_invoice') ? $address_delivery : new Address((int) Tools::getValue('id_address_invoice'));
if ($address_delivery->id_customer != $this->context->customer->id || $address_invoice->id_customer != $this->context->customer->id) {
$this->errors[] = Tools::displayError('This address is not yours.');
} elseif (!Address::isCountryActiveById((int) Tools::getValue('id_address_delivery'))) {
$this->errors[] = Tools::displayError('This address is not in a valid area.');
} elseif (!Validate::isLoadedObject($address_delivery) || !Validate::isLoadedObject($address_invoice) || $address_invoice->deleted || $address_delivery->deleted) {
$this->errors[] = Tools::displayError('This address is invalid.');
} else {
$this->context->cart->id_address_delivery = (int) Tools::getValue('id_address_delivery');
$this->context->cart->id_address_invoice = Tools::isSubmit('same') ? $this->context->cart->id_address_delivery : (int) Tools::getValue('id_address_invoice');
if (!$this->context->cart->update()) {
$this->errors[] = Tools::displayError('An error occurred while updating your cart.');
}
$infos = Address::getCountryAndState((int) $this->context->cart->id_address_delivery);
if (isset($infos['id_country']) && $infos['id_country']) {
$country = new Country((int) $infos['id_country']);
$this->context->country = $country;
}
// Address has changed, so we check if the cart rules still apply
$cart_rules = $this->context->cart->getCartRules();
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
if ((int) Tools::getValue('allow_refresh')) {
// If the cart rules has changed, we need to refresh the whole cart
$cart_rules2 = $this->context->cart->getCartRules();
if (count($cart_rules2) != count($cart_rules)) {
$this->ajax_refresh = true;
} else {
$rule_list = array();
foreach ($cart_rules2 as $rule) {
$rule_list[] = $rule['id_cart_rule'];
}
foreach ($cart_rules as $rule) {
if (!in_array($rule['id_cart_rule'], $rule_list)) {
$this->ajax_refresh = true;
break;
}
}
}
}
if (!$this->context->cart->isMultiAddressDelivery()) {
$this->context->cart->setNoMultishipping();
}
// As the cart is no multishipping, set each delivery address lines with the main delivery address
if (!count($this->errors)) {
$result = $this->_getCarrierList();
示例11: validateOrder
//.........这里部分代码省略.........
}
}
// Insert products from cart into order_detail table
$products = $cart->getProducts();
$productsList = '';
$db = Db::getInstance();
$query = 'INSERT INTO `' . _DB_PREFIX_ . 'order_detail`
(`id_order`, `product_id`, `product_attribute_id`, `product_name`, `product_quantity`, `product_quantity_in_stock`, `product_price`, `reduction_percent`, `reduction_amount`, `group_reduction`, `product_quantity_discount`, `product_ean13`, `product_upc`, `product_reference`, `product_supplier_reference`, `product_weight`, `tax_name`, `tax_rate`, `ecotax`, `ecotax_tax_rate`, `discount_quantity_applied`, `download_deadline`, `download_hash`)
VALUES ';
$customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
Product::addCustomizationPrice($products, $customizedDatas);
$outOfStock = false;
$store_all_taxes = array();
foreach ($products as $key => $product) {
$productQuantity = (int) Product::getQuantity((int) $product['id_product'], $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL);
$quantityInStock = $productQuantity - (int) $product['cart_quantity'] < 0 ? $productQuantity : (int) $product['cart_quantity'];
if ($id_order_state != Configuration::get('PS_OS_CANCELED') and $id_order_state != Configuration::get('PS_OS_ERROR')) {
if (Product::updateQuantity($product, (int) $order->id)) {
$product['stock_quantity'] -= $product['cart_quantity'];
}
if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) {
$outOfStock = true;
}
Product::updateDefaultAttribute($product['id_product']);
}
$price = Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 6, NULL, false, true, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$price_wt = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : NULL, 2, NULL, false, true, $product['cart_quantity'], false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
/* Store tax info */
$id_country = (int) Country::getDefaultCountryId();
$id_state = 0;
$id_county = 0;
$rate = 0;
$id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$address_infos = Address::getCountryAndState($id_address);
if ($address_infos['id_country']) {
$id_country = (int) $address_infos['id_country'];
$id_state = (int) $address_infos['id_state'];
$id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
}
$allTaxes = TaxRulesGroup::getTaxes((int) Product::getIdTaxRulesGroupByIdProduct((int) $product['id_product']), $id_country, $id_state, $id_county);
// If its a freeOrder, there will be no calculation
if ($order->total_products > 0) {
// remove order discount quotepart on product price in order to obtain the real tax
$ratio = $price / $order->total_products;
$order_reduction_amount = (double) abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS)) * $ratio;
$tmp_price = $price - $order_reduction_amount;
foreach ($allTaxes as $res) {
if (!isset($store_all_taxes[$res->id])) {
$store_all_taxes[$res->id] = array();
$store_all_taxes[$res->id]['amount'] = 0;
}
$store_all_taxes[$res->id]['name'] = $res->name[(int) $order->id_lang];
$store_all_taxes[$res->id]['rate'] = $res->rate;
$unit_tax_amount = $tmp_price * ($res->rate * 0.01);
$tmp_price = $tmp_price + $unit_tax_amount;
$store_all_taxes[$res->id]['amount'] += $unit_tax_amount * $product['cart_quantity'];
}
}
/* End */
// Add some informations for virtual products
$deadline = '0000-00-00 00:00:00';
$download_hash = null;
if ($id_product_download = ProductDownload::getIdFromIdProduct((int) $product['id_product'])) {
$productDownload = new ProductDownload((int) $id_product_download);
$deadline = $productDownload->getDeadLine();
$download_hash = $productDownload->getHash();
示例12: getProductIdByDates
public static function getProductIdByDates($categories, $beginning, $ending, Context $context = null, $with_combination = false)
{
if (!$context) {
$context = Context::getContext();
}
$id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
$id_country = $ids['id_country'] ? (int) $ids['id_country'] : (int) Configuration::get('PS_COUNTRY_DEFAULT');
return self::getProductIdByDate($categories, $context->shop->id, $context->currency->id, $id_country, $context->customer->id_default_group, $beginning, $ending, 0, $with_combination);
}
示例13: getCarrierTaxRate
public static function getCarrierTaxRate($id_carrier, $id_address = NULL)
{
$id_country = (int) Country::getDefaultCountryId();
$id_state = 0;
$id_county = 0;
if (!empty($id_address)) {
$address_infos = Address::getCountryAndState($id_address);
if ($address_infos['id_country']) {
$id_country = (int) $address_infos['id_country'];
$id_state = (int) $address_infos['id_state'];
$id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
}
if (!empty($address_infos['vat_number']) and $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') and Configuration::get('VATNUMBER_MANAGEMENT')) {
return 0;
}
}
return TaxRulesGroup::getTaxesRate((int) Carrier::getIdTaxRulesGroupByIdCarrier((int) $id_carrier), (int) $id_country, (int) $id_state, (int) $id_county);
}
示例14: init
//.........这里部分代码省略.........
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
}
/* Cart already exists */
if ((int) $this->context->cookie->id_cart) {
if (!isset($cart)) {
$cart = new Cart($this->context->cookie->id_cart);
}
if (Validate::isLoadedObject($cart) && $cart->OrderExists()) {
PrestaShopLogger::addLog('Frontcontroller::init - Cart cannot be loaded or an order has already been placed using this cart', 1, null, 'Cart', (int) $this->context->cookie->id_cart, true);
unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
$this->context->cookie->check_cgv = false;
} elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && $cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 && !FrontController::isInWhitelistForGeolocation() && !in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
/* Delete product of cart, if user can't make an order from his country */
PrestaShopLogger::addLog('Frontcontroller::init - GEOLOCATION is deleting a cart', 1, null, 'Cart', (int) $this->context->cookie->id_cart, true);
unset($this->context->cookie->id_cart, $cart);
} elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency) {
// update cart values
if ($this->context->cookie->id_customer) {
$cart->id_customer = (int) $this->context->cookie->id_customer;
}
$cart->id_lang = (int) $this->context->cookie->id_lang;
$cart->id_currency = (int) $currency->id;
$cart->update();
}
/* Select an address if not set */
if (isset($cart) && (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0 || !isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) && $this->context->cookie->id_customer) {
$to_update = false;
if (!isset($cart->id_address_delivery) || $cart->id_address_delivery == 0) {
$to_update = true;
$cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
}
if (!isset($cart->id_address_invoice) || $cart->id_address_invoice == 0) {
$to_update = true;
$cart->id_address_invoice = (int) Address::getFirstCustomerAddressId($cart->id_customer);
}
if ($to_update) {
$cart->update();
}
}
}
if (!isset($cart) || !$cart->id) {
$cart = new Cart();
$cart->id_lang = (int) $this->context->cookie->id_lang;
$cart->id_currency = (int) $this->context->cookie->id_currency;
$cart->id_guest = (int) $this->context->cookie->id_guest;
$cart->id_shop_group = (int) $this->context->shop->id_shop_group;
$cart->id_shop = $this->context->shop->id;
if ($this->context->cookie->id_customer) {
$cart->id_customer = (int) $this->context->cookie->id_customer;
$cart->id_address_delivery = (int) Address::getFirstCustomerAddressId($cart->id_customer);
$cart->id_address_invoice = (int) $cart->id_address_delivery;
} else {
$cart->id_address_delivery = 0;
$cart->id_address_invoice = 0;
}
// Needed if the merchant want to give a free product to every visitors
$this->context->cart = $cart;
CartRule::autoAddToCart($this->context);
} else {
$this->context->cart = $cart;
}
$this->context->cart->checkAndUpdateAddresses();
$this->context->smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
// Automatically redirect to the canonical URL if needed
if (!empty($this->php_self) && !Tools::getValue('ajax')) {
$this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id));
}
Product::initPricesComputation();
$display_tax_label = $this->context->country->display_tax_label;
if (isset($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) && $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) {
$infos = Address::getCountryAndState((int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$country = new Country((int) $infos['id_country']);
$this->context->country = $country;
if (Validate::isLoadedObject($country)) {
$display_tax_label = $country->display_tax_label;
}
}
$languages = Language::getLanguages(true, $this->context->shop->id);
$meta_language = array();
foreach ($languages as $lang) {
$meta_language[] = $lang['iso_code'];
}
/*
* These shortcuts are DEPRECATED as of version 1.5.0.1
* Use the Context to access objects instead.
* Example: $this->context->cart
*/
self::$cookie = $this->context->cookie;
self::$cart = $cart;
self::$smarty = $this->context->smarty;
self::$link = $link;
$defaultCountry = $this->context->country;
$this->displayMaintenancePage();
if (Country::GEOLOC_FORBIDDEN == $this->restrictedCountry) {
$this->displayRestrictedCountryPage();
}
$this->iso = $iso;
$this->context->cart = $cart;
$this->context->currency = $currency;
}
示例15: init
//.........这里部分代码省略.........
$physical_destination = $reference_details_result_wrapper->GetOrderReferenceDetailsResult->getOrderReferenceDetails()->getDestination()->getPhysicalDestination();
$iso_code = (string) $physical_destination->GetCountryCode();
$city = (string) $physical_destination->GetCity();
$postcode = (string) $physical_destination->GetPostalCode();
$state = (string) $physical_destination->GetStateOrRegion();
$address_delivery = AmazonPaymentsAddressHelper::findByAmazonOrderReferenceIdOrNew(Tools::getValue('amazonOrderReferenceId'));
$address_delivery->id_country = Country::getByIso($iso_code);
$address_delivery->alias = 'Amazon Payments Delivery';
$address_delivery->lastname = 'amzLastname';
$address_delivery->firstname = 'amzFirstname';
$address_delivery->address1 = 'amzAddress1';
$address_delivery->city = $city;
$address_delivery->postcode = $postcode;
if ($state != '') {
$state_id = State::getIdByIso($state, Country::getByIso($iso_code));
if (!$state_id) {
$state_id = State::getIdByName($state);
}
if ($state_id) {
$address_delivery->id_state = $state_id;
}
}
$address_delivery->save();
AmazonPaymentsAddressHelper::saveAddressAmazonReference($address_delivery, Tools::getValue('amazonOrderReferenceId'));
$this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart());
$old_delivery_address_id = $this->context->cart->id_address_delivery;
$this->context->cart->id_address_delivery = $address_delivery->id;
$this->context->cart->id_address_invoice = $address_delivery->id;
$this->context->cart->setNoMultishipping();
$this->context->cart->updateAddressId($old_delivery_address_id, $address_delivery->id);
if (!$this->context->cart->update()) {
$this->errors[] = Tools::displayError('An error occurred while updating your cart.');
}
$infos = Address::getCountryAndState((int) $this->context->cart->id_address_delivery);
if (isset($infos['id_country']) && $infos['id_country']) {
$country = new Country((int) $infos['id_country']);
$this->context->country = $country;
}
$cart_rules = $this->context->cart->getCartRules();
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
if ((int) Tools::getValue('allow_refresh')) {
$cart_rules2 = $this->context->cart->getCartRules();
if (count($cart_rules2) != count($cart_rules)) {
$this->ajax_refresh = true;
} else {
$rule_list = array();
foreach ($cart_rules2 as $rule) {
$rule_list[] = $rule['id_cart_rule'];
}
foreach ($cart_rules as $rule) {
if (!in_array($rule['id_cart_rule'], $rule_list)) {
$this->ajax_refresh = true;
break;
}
}
}
}
if (!$this->context->cart->isMultiAddressDelivery()) {
$this->context->cart->setNoMultishipping();
}
if (!count($this->errors)) {
$result = $this->_getCarrierList();
if (isset($result['hasError'])) {
unset($result['hasError']);
}