本文整理汇总了PHP中RangeWeight类的典型用法代码示例。如果您正苦于以下问题:PHP RangeWeight类的具体用法?PHP RangeWeight怎么用?PHP RangeWeight使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RangeWeight类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createDejalaCarrier
/**
* creates of a dejala carrier corresponding to $dejalaProduct
*/
public static function createDejalaCarrier($dejalaConfig, $dejalaProduct)
{
// MFR091130 - get id zone from the country used in the module (if the store zones were customized) - default is 1 (Europe)
$id_zone = 1;
$moduleCountryIsoCode = strtoupper($dejalaConfig->country);
$countryID = Country::getByIso($moduleCountryIsoCode);
if (intval($countryID)) {
$id_zone = Country::getIdZone($countryID);
}
$vatRate = floatval($dejalaProduct['vat']);
// MFR091130 - get or create the tax & attach it to our zone if needed
$id_tax = Tax::getTaxIdByRate($vatRate);
if (!$id_tax) {
$tax = new Tax();
$tax->rate = $vatRate;
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
$tax->name[$defaultLanguage] = $tax->rate . '%';
$tax->add();
$id_tax = Tax::getTaxIdByRate($vatRate);
}
if (!Tax::zoneHasTax($id_tax, $id_zone)) {
// MFR : direct call because $tax->addZone($id_zone) causes errors when called
Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'tax_zone` (`id_tax` , `id_zone`) VALUES (' . intval($id_tax) . ', ' . intval($id_zone) . ')');
}
$carrier = new Carrier();
$carrier->name = 'dejala';
$carrier->id_tax = $id_tax;
$carrier->url = 'http://tracking.dejala.' . $dejalaConfig->country . '/tracker/@';
$carrier->active = true;
$carrier->deleted = 0;
$carrier->shipping_handling = false;
$carrier->range_behavior = 0;
$carrier->is_module = 1;
$languages = Language::getLanguages(true);
foreach ($languages as $language) {
if ($language['iso_code'] == 'fr') {
$carrier->delay[$language['id_lang']] = utf8_encode('Quand vous voulez... Par coursier, ' . $dejalaProduct['timelimit'] . 'H');
}
if ($language['iso_code'] == 'en') {
$carrier->delay[$language['id_lang']] = utf8_encode('When you want... Dispatch rider, ' . $dejalaProduct['timelimit'] . 'H range');
}
if ($language['iso_code'] == 'es') {
$carrier->delay[$language['id_lang']] = utf8_encode('Cuando quiera... Por mensajero, ' . $dejalaProduct['timelimit'] . 'H');
}
}
$carrier->add();
$sql = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` (`id_carrier` , `id_zone`) VALUES (' . intval($carrier->id) . ', ' . intval($id_zone) . ')';
Db::getInstance()->Execute($sql);
$rangeW = new RangeWeight();
$rangeW->id_carrier = $carrier->id;
$rangeW->delimiter1 = 0;
$rangeW->delimiter2 = $dejalaProduct['max_weight'];
$rangeW->add();
$vat_factor = 1 + $dejalaProduct['vat'] / 100;
$priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2);
$priceHT = round($priceTTC / $vat_factor, 2);
$priceList = '(NULL' . ',' . $rangeW->id . ',' . $carrier->id . ',' . $id_zone . ',' . $priceHT . ')';
$carrier->addDeliveryPrice($priceList);
return new Carrier($carrier->id);
}
示例2: xdInstall
public function xdInstall()
{
foreach ($this->Options->getValue('carrierList') as $carrier_key => $carrier_name) {
$carrierId = \Configuration::get($carrier_key);
$deleted = false;
if ($carrierId > 0) {
$carrier = new \Carrier($carrierId);
$deleted = $carrier->deleted;
}
if ($carrierId < 1 || $deleted) {
// Create carrier
$carrier = new \Carrier();
$carrier->name = $carrier_name;
$carrier->id_tax_rules_group = 0;
$carrier->active = 1;
$carrier->deleted = 0;
foreach (\Language::getLanguages(true) as $language) {
// TODO Carrier delay
$carrier->delay[(int) $language['id_lang']] = ' ';
}
$carrier->shipping_handling = 0;
$carrier->range_behavior = 1;
$carrier->is_module = 1;
$carrier->shipping_external = 1;
$carrier->external_module_name = $this->moduleInstance->name;
$carrier->need_range = 1;
if (!$carrier->add()) {
return false;
}
// Associate carrier to all groups
$groups = \Group::getGroups(true);
foreach ($groups as $group) {
\Db::getInstance()->insert('carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']));
}
// Create price range
$rangePrice = new \RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '10000';
$rangePrice->add();
// Create weight range
$rangeWeight = new \RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '10000';
$rangeWeight->add();
// Associate carrier to all zones
$zones = \Zone::getZones(true);
foreach ($zones as $zone) {
\Db::getInstance()->insert('carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']));
\Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
\Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
}
copy(self::$instanceBaseDir . '/img/logo.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
\Configuration::updateValue($carrier_key, $carrier->id);
}
}
return true;
}
示例3: installExternalCarrier
public function installExternalCarrier($config)
{
$carrier = new Carrier();
$carrier->name = $config['name'];
$carrier->id_tax_rules_group = $config['id_tax_rules_group'];
$carrier->active = $config['active'];
$carrier->deleted = $config['deleted'];
$carrier->delay = $config['delay'];
$carrier->shipping_handling = $config['shipping_handling'];
$carrier->range_behavior = $config['range_behavior'];
$carrier->is_module = $config['is_module'];
$carrier->shipping_external = $config['shipping_external'];
$carrier->external_module_name = $config['external_module_name'];
$carrier->need_range = $config['need_range'];
$languages = Context::getContext()->language->getLanguages(true);
foreach ($languages as $language) {
if ($language['iso_code'] == 'cs') {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
} else {
$carrier->delay[(int) $language['id_lang']] = '2 days';
}
}
if ($carrier->add()) {
$groups = Group::getGroups(true);
foreach ($groups as $group) {
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
}
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '1000000';
$rangePrice->add();
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '10000';
$rangeWeight->add();
$sql = 'SELECT DISTINCT id_zone FROM ' . _DB_PREFIX_ . 'country WHERE iso_code="CZ" OR iso_code="SK"';
$zones = Db::getInstance()->executeS($sql);
if (is_array($zones)) {
foreach ($zones as $zone) {
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
}
}
$this->module->copyLogo($carrier->id);
if (Configuration::get('PS_TAX')) {
$carrier->setTaxRulesGroup(1, true);
}
return (int) $carrier->id;
}
$this->messages[] = 'Failed to create external carrier ' . $config['name'];
return false;
}
示例4: postProcess
public function postProcess()
{
$id = (int) Tools::getValue('id_' . $this->table);
if (Tools::getValue('submitAdd' . $this->table)) {
if (Tools::getValue('delimiter1') >= Tools::getValue('delimiter2')) {
$this->errors[] = Tools::displayError('Invalid range');
} elseif (!$id && RangeWeight::rangeExist((int) Tools::getValue('id_carrier'), (double) Tools::getValue('delimiter1'), (double) Tools::getValue('delimiter2'))) {
$this->errors[] = Tools::displayError('The range already exists');
} elseif (RangeWeight::isOverlapping((int) Tools::getValue('id_carrier'), (double) Tools::getValue('delimiter1'), (double) Tools::getValue('delimiter2'), $id ? (int) $id : null)) {
$this->errors[] = Tools::displayError('Error: Ranges are overlapping');
} elseif (!count($this->errors)) {
parent::postProcess();
}
} else {
parent::postProcess();
}
}
示例5: postProcess
public function postProcess()
{
if (isset($_POST['submitAdd' . $this->table])) {
$delimiter1 = Tools::getValue('delimiter1');
$delimiter2 = Tools::getValue('delimiter2');
if ($delimiter1 >= $delimiter2) {
$this->_errors[] = Tools::displayError('Invalid range, "From" must be lower than "To"');
}
/* Check that a similar range does not exist yet for this carrier */
if (!Tools::isSubmit('id_range_weight') && !count($this->_errors) && ($ranges = RangeWeight::getRanges((int) Tools::getValue('id_carrier')))) {
foreach ($ranges as $range) {
if (!($delimiter2 <= $range['delimiter1'] || $delimiter1 >= $range['delimiter2'])) {
$this->_errors[] = Tools::displayError('Invalid range, this range is overlapping an existing range');
break;
}
}
}
}
parent::postProcess();
}
示例6: installExternalCarrier
public static function installExternalCarrier($config)
{
$carrier = new Carrier();
$carrier->name = $config['name'];
$carrier->id_tax = $config['id_tax'];
$carrier->active = $config['active'];
$carrier->deleted = $config['deleted'];
$carrier->delay = $config['delay'];
$carrier->shipping_handling = $config['shipping_handling'];
$carrier->range_behavior = $config['range_behavior'];
$carrier->is_module = $config['is_module'];
$carrier->shipping_external = $config['shipping_external'];
$carrier->external_module_name = $config['external_module_name'];
$carrier->need_range = $config['need_range'];
$languages = Language::getLanguages(true);
foreach ($languages as $language) {
if ($language['iso_code'] == 'fr') {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($language['iso_code'] == 'en') {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($language['iso_code'] == 'es') {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
}
if ($carrier->add()) {
$groups = Group::getGroups(true);
foreach ($groups as $group) {
Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'carrier_group` VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
}
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '10000';
$rangePrice->add();
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '15';
$rangeWeight->add();
$id_zone = Zone::getIdByName('Europe');
Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $id_zone . '\')');
Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'delivery` (`id_carrier`, `id_range_price`, `id_range_weight`, `id_zone`, `price`)
VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $rangePrice->id . '\',NULL,\'' . (int) $id_zone . '\',\'' . (double) $config['price'] . '\'),
(\'' . (int) $carrier->id . '\',NULL,\'' . (int) $rangeWeight->id . '\',\'' . (int) $id_zone . '\',\'' . (double) $config['price'] . '\')');
Configuration::updateValue('KIALASMALL_CARRIER_ID', (int) $carrier->id);
//copy logo
if (!copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) {
return false;
}
return true;
} else {
return false;
}
}
示例7: installExternalCarrier
public static function installExternalCarrier($config)
{
$carrier = new Carrier();
$carrier->name = $config['name'];
$carrier->id_tax_rules_group = $config['id_tax_rules_group'];
$carrier->id_zone = $config['id_zone'];
$carrier->active = $config['active'];
$carrier->deleted = $config['deleted'];
$carrier->delay = $config['delay'];
$carrier->shipping_handling = $config['shipping_handling'];
$carrier->range_behavior = $config['range_behavior'];
$carrier->is_module = $config['is_module'];
$carrier->shipping_external = $config['shipping_external'];
$carrier->external_module_name = $config['external_module_name'];
$carrier->need_range = $config['need_range'];
$languages = Language::getLanguages(true);
foreach ($languages as $language) {
if ($language['iso_code'] == 'fr') {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($language['iso_code'] == 'en') {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($language['iso_code'] == Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'))) {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
}
if ($carrier->add()) {
$groups = Group::getGroups(true);
foreach ($groups as $group) {
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
}
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '10000';
$rangePrice->add();
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '10000';
$rangeWeight->add();
$zones = Zone::getZones(true);
foreach ($zones as $zone) {
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
}
// Copy Logo
if (!copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) {
return false;
}
// Return ID Carrier
return (int) $carrier->id;
}
return false;
}
示例8: addRanges
protected function addRanges($carrier)
{
$range_price = new RangePrice();
$range_price->id_carrier = $carrier->id;
$range_price->delimiter1 = '0';
$range_price->delimiter2 = '10000';
$range_price->add();
$range_weight = new RangeWeight();
$range_weight->id_carrier = $carrier->id;
$range_weight->delimiter1 = '0';
$range_weight->delimiter2 = '10000';
$range_weight->add();
}
示例9: installExternalCarrier
public static function installExternalCarrier($config)
{
$carrier = new Carrier();
$carrier->hydrate($config);
$carrier->name = $config['name'];
$carrier->id_zone = $config['id_zone'];
$carrier->active = $config['active'];
$carrier->deleted = $config['deleted'];
$carrier->delay = $config['delay'];
$carrier->shipping_handling = $config['shipping_handling'];
$carrier->range_behavior = $config['range_behavior'];
$carrier->is_module = $config['is_module'];
$carrier->shipping_external = $config['shipping_external'];
$carrier->external_module_name = $config['external_module_name'];
$carrier->need_range = $config['need_range'];
$carrier->setTaxRulesGroup($config['id_tax_rules_group'], true);
$languages = Language::getLanguages(true);
foreach ($languages as $language) {
if ($language['iso_code'] == 'lv') {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($language['iso_code'] == 'lt') {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($language['iso_code'] == Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'))) {
$carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
}
}
if ($carrier->add()) {
$groups = Group::getGroups(true);
foreach ($groups as $group) {
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
}
// $range_price = new RangePrice();
// $range_price->id_carrier = $carrier->id;
// $range_price->delimiter1 = '0';
// $range_price->delimiter2 = '10000';
// $range_price->add();
// $range_weight = new RangeWeight();
// $range_weight->id_carrier = $carrier->id;
// $range_weight->delimiter1 = '0';
// $range_weight->delimiter2 = '10000';
// $range_weight->add();
// Add weight ranges to carrier
$rangePrices = array();
foreach ($config['ranges'] as $range) {
$rangeWeight = new RangeWeight();
$rangeWeight->hydrate(array('id_carrier' => $carrier->id, 'delimiter1' => (double) $range['delimiter1'], 'delimiter2' => (double) $range['delimiter2']));
$rangeWeight->add();
// Save range ID and price and set it after the Zones have been added
$rangePrices[] = array('id_range_weight' => $rangeWeight->id, 'price' => $range['price']);
}
// Update prices in delivery table for each range (need IDs)
foreach ($rangePrices as $rangePrice) {
$data = array('price' => $rangePrice['price']);
$where = 'id_range_weight = ' . $rangePrice['id_range_weight'];
Db::getInstance()->update('delivery', $data, $where);
}
// Add Europe for EVERY carrier range
// Automatically creates rows in delivery table, price is 0
$id_zone_europe = Zone::getIdByName('Europe');
$carrier->addZone($id_zone_europe ? $id_zone_europe : 1);
// Copy Logo
if (!Tools::copy(dirname(__FILE__) . '/logo.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.png')) {
return false;
}
DpdCarrierOptions::setCarrierOptions((int) $carrier->id, (int) $carrier->id, $config['type']);
// Return ID Carrier
return (int) $carrier->id;
}
return false;
}
开发者ID:uab-balticode,项目名称:dpd-shipping-module-prestashop-2,代码行数:72,代码来源:dynamicparceldistribution.php
示例10: createShopgateCarrier
/**
* create shopgate carrier
*/
public function createShopgateCarrier()
{
/** @var CarrierCore $carrier */
$carrier = new Carrier();
$carrier->name = self::MODULE_CARRIER_NAME;
$carrier->active = true;
$carrier->deleted = true;
$carrier->shipping_handling = false;
$carrier->range_behavior = true;
$carrier->delay[Configuration::get('PS_LANG_DEFAULT')] = self::MODULE_CARRIER_NAME;
$carrier->shipping_external = true;
$carrier->is_module = true;
$carrier->external_module_name = self::DEFAULT_EXTERNAL_MODULE_CARRIER_NAME;
$carrier->need_range = true;
foreach (Language::getLanguages() as $language) {
$carrier->delay[$language['id_lang']] = 'Depends on Shopgate selected carrier';
}
if ($carrier->add()) {
$groups = Group::getGroups(true);
foreach ($groups as $group) {
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
}
/** @var RangePriceCore $rangePrice */
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '1000000';
$rangePrice->add();
/** @var RangeWeightCore $rangeWeight */
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '1000000';
$rangeWeight->add();
$zones = Zone::getZones(true);
foreach ($zones as $zone) {
/** @var $zone ZoneCore */
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
}
}
Configuration::updateValue('SG_CARRIER_ID', $carrier->id);
}
示例11: carrierCompatibility
private function carrierCompatibility($carrier)
{
// fix a bug in Prestashop before version 1.4.4.0 classes/cart.php function isCarrierInRange() range behavior
$rangePrices = RangePrice::getRanges($carrier->id);
if (empty($rangePrices)) {
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = 0.0;
$rangePrice->delimiter2 = 1000000.0;
if (!$rangePrice->add()) {
$this->log('installation adding rangePrice failed', ShopgateLogger::LOGTYPE_ACCESS);
return false;
}
} else {
$rangePrice = new RangeWeight($rangePrices[0]['id_range_price']);
}
$rangeWeights = RangeWeight::getRanges($carrier->id);
if (empty($rangeWeights)) {
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = 0.0;
$rangeWeight->delimiter2 = 1000000.0;
if (!$rangeWeight->add()) {
$this->log('installation adding rangeWeight failed', ShopgateLogger::LOGTYPE_ACCESS);
return false;
}
} else {
$rangeWeight = new RangeWeight($rangeWeights[0]['id_range_weight']);
}
// Zones
$zones = Zone::getZones();
foreach ($zones as $zone) {
$carrier->addZone($zone['id_zone']);
}
// create for each zone delivery options
foreach ($zones as $zone) {
$deliveryRangeWeight = new Delivery();
$deliveryRangeWeight->id_carrier = $carrier->id;
$deliveryRangeWeight->id_range_weight = $rangeWeight->id;
$deliveryRangeWeight->id_range_price = 0;
$deliveryRangeWeight->price = 0;
$deliveryRangeWeight->id_zone = $zone['id_zone'];
if (!$deliveryRangeWeight->add(true, true)) {
$this->log('installation adding deliveryRangeWeight failed', ShopgateLogger::LOGTYPE_ACCESS);
return false;
}
$deliveryRangePrice = new Delivery();
$deliveryRangePrice->id_carrier = $carrier->id;
$deliveryRangePrice->id_range_price = $rangePrice->id;
$deliveryRangePrice->id_range_weight = 0;
$deliveryRangePrice->price = 0;
$deliveryRangePrice->id_zone = $zone['id_zone'];
if (!$deliveryRangePrice->add(true, true)) {
$this->log('installation adding deliveryRangePrice failed', ShopgateLogger::LOGTYPE_ACCESS);
return false;
}
}
}
示例12: createChronopostCarriers
public static function createChronopostCarriers($carrierConfig)
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
// Create carriers from config
foreach ($carrierConfig as $carrierName => $config) {
$carrier = new Carrier();
$carrier->name = $config['name'];
$carrier->id_tax_rules_group = $config['id_tax_rules_group'];
$carrier->url = $config['url'];
$carrier->active = $config['active'];
$carrier->deleted = $config['deleted'];
$carrier->delay = $config['delay'];
$carrier->shipping_handling = $config['shipping_handling'];
$carrier->range_behavior = $config['range_behavior'];
$carrier->is_module = $config['is_module'];
$carrier->shipping_external = $config['shipping_external'];
$carrier->external_module_name = $config['external_module_name'];
$carrier->need_range = $config['need_range'];
$languages = Language::getLanguages(true);
foreach ($languages as $language) {
if (array_key_exists($language['iso_code'], $config['delay'])) {
$carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
} else {
$carrier->delay[$language['id_lang']] = $config['delay']['fr'];
}
}
if ($carrier->add()) {
Configuration::updateValue($config['configuration_item'], (int) $carrier->id);
// ASSIGN GROUPS
$groups = Group::getgroups(true);
foreach ($groups as $group) {
Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_group VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
}
// ASSIGN ZONES
$zones = Zone::getZones();
foreach ($zones as $zone) {
$carrier->addZone($zone['id_zone']);
}
// RANGE PRICE
$rp = new RangePrice();
$rp->id_carrier = $carrier->id;
$rp->delimiter1 = 0;
$rp->delimiter2 = 100000;
$rp->add();
$fp = fopen(_MYDIR_ . '/csv/' . $carrierName . '.csv', 'r');
// insert prices per weight range
while ($line = fgetcsv($fp)) {
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = $line[0];
$rangeWeight->delimiter2 = $line[1];
$rangeWeight->price_to_affect = $line[2];
$rangeWeight->add();
}
//copy logo
if (!copy(dirname(__FILE__) . '/views/img/' . $config['logo_filename'] . '.jpg', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
return false;
}
}
}
return true;
}
示例13: installCarrier
private function installCarrier($is_COD = 0)
{
$carrier = new Carrier();
$carrier->name = 'Почта России';
//Проверяем какого перевозчика создаем
if ($is_COD) {
$carrier->name .= ' (наложенный платеж)';
}
// @deprecated since 1.5.0
//$carrier->id_tax_rules_group' = 0;
// TODO: проверить -- это точно обязательно?
//Способ доставки активен
$carrier->active = true;
// TODO: проверить -- это точно обязательно?
//Не удален. При удалении способа доставки он не удаляется из
//базы данных, а только помечается как удаленный
$carrier->deleted = 0;
// TODO: это может быть интересным -- стоимость упаковки и пр.
//Доставка и обработка
$carrier->shipping_handling = false;
// Что делать, если Out Of Range. 0 -- считать, 1 -- не считать
// Мы, ведь, сами определяем можем или не можем, настроек range
// никаких не будет.
//Исключения: применить наибольшую цену доставки
$carrier->range_behavior = 0;
// Тут зависимости от языка
// TODO: по идее это время доставки, но для разных пунктов
// оно может сильно отличасться. Посмотреть, можно-ли это как-то
// динамически править
$delay_str_list = array('ru' => 'Срок доставки зависит от удаленности', 'default' => 'Delivery time depens on distance');
$languages = Language::getLanguages(false);
foreach ($languages as $language) {
//Проверяем есть ли текущий язык в списке предусмотренных языков
if (!isset($delay_str_list[$language['iso_code']])) {
//Если нет, то ставим фразу по умолчанию
$carrier->delay[(int) $language['id_lang']] = $delay_str_list['default'];
} else {
//Иначе берем фразу из конфига
$carrier->delay[(int) $language['id_lang']] = $delay_str_list[$language['iso_code']];
}
}
// Этот перевозчик связан с модулем
//Расчет производится из внешнего источника
$carrier->shipping_external = true;
//Признак того, что способ доставки принадлежит модулю
$carrier->is_module = true;
//Имя модуля, которому принадлежит способ доставки
$carrier->external_module_name = 'russianpostcarrier';
// Если я правильно понял, то заданные лимиты
// нам не уперлись, у нас внутре свои лимиты задаются
// UPD: Но оно в этом случае, похоже, не работает. Придется задавать лимиты
$carrier->need_range = true;
// TODO: еще полезные переменные, мы ими потом займемся,
// надо понять, как оно считает
// $carrier->max_width => 1;
// $carrier->max_height => 1;
// $carrier->max_depth => 1;
// $carrier->max_weight => 1; // вот это вот особенно!
if ($carrier->add()) {
// Добавим нашего несчастного перевозчика всем группам
$groups = Group::getGroups(true);
foreach ($groups as $group) {
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
}
// Без указания пределов по весу и стоимости оно не заработало
// Сделаем, хотя оно нам не надо
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '100500';
$rangePrice->add();
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '100500';
//Предельные тяжеловесные посылки 20 кг
$rangeWeight->add();
$zones = Zone::getZones(true);
foreach ($zones as $z) {
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $z['id_zone']), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
}
copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
return $carrier->id;
}
return false;
}
示例14: createSoColissimoCarrier
public static function createSoColissimoCarrier($config)
{
$carrier = new Carrier();
$carrier->name = $config['name'];
$carrier->id_tax_rules_group = $config['id_tax_rules_group'];
$carrier->id_zone = $config['id_zone'];
$carrier->url = $config['url'];
$carrier->active = $config['active'];
$carrier->deleted = $config['deleted'];
$carrier->delay = $config['delay'];
$carrier->shipping_handling = $config['shipping_handling'];
$carrier->range_behavior = $config['range_behavior'];
$carrier->is_module = $config['is_module'];
$carrier->shipping_external = $config['shipping_external'];
$carrier->external_module_name = $config['external_module_name'];
$carrier->need_range = $config['need_range'];
$languages = Language::getLanguages(true);
foreach ($languages as $language) {
if ($language['iso_code'] == 'fr') {
$carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($language['iso_code'] == 'en') {
$carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
}
}
if ($carrier->add()) {
Configuration::updateValue('SOCOLISSIMO_CARRIER_ID', (int) $carrier->id);
$groups = Group::getgroups(true);
foreach ($groups as $group) {
Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_group VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
}
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '10000';
$rangePrice->add();
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '10000';
$rangeWeight->add();
$zones = Zone::getZones(true);
foreach ($zones as $zone) {
Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_zone VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $zone['id_zone'] . '\')');
Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'delivery VALUE (\'\',\'' . (int) $carrier->id . '\',\'' . (int) $rangePrice->id . '\',NULL,\'' . (int) $zone['id_zone'] . '\',\'1\')');
Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'delivery VALUE (\'\',\'' . (int) $carrier->id . '\',NULL,\'' . (int) $rangeWeight->id . '\',\'' . (int) $zone['id_zone'] . '\',\'1\')');
}
//copy logo
if (!copy(dirname(__FILE__) . '/socolissimo.jpg', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
return false;
}
return true;
} else {
return false;
}
}
示例15: installCarriers
public function installCarriers()
{
$id_lang_default = Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'));
$carriers_list = array('MYMOD_CA_CLDE' => 'Classic delivery', 'MYMOD_CA_REPO' => 'Relay Point');
foreach ($carriers_list as $carrier_key => $carrier_name) {
if (Configuration::get($carrier_key) < 1) {
// Create new carrier
$carrier = new Carrier();
$carrier->name = $carrier_name;
$carrier->id_tax_rules_group = 0;
$carrier->active = 1;
$carrier->deleted = 0;
foreach (Language::getLanguages(true) as $language) {
$carrier->delay[(int) $language['id_lang']] = 'Delay ' . $carrier_name;
}
$carrier->shipping_handling = false;
$carrier->range_behavior = 0;
$carrier->is_module = true;
$carrier->shipping_external = true;
$carrier->external_module_name = $this->name;
$carrier->need_range = true;
if (!$carrier->add()) {
return false;
}
// Associate carrier to all groups
$groups = Group::getGroups(true);
foreach ($groups as $group) {
Db::getInstance()->insert('carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']));
}
// Create price range
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '10000';
$rangePrice->add();
// Create weight range
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '10000';
$rangeWeight->add();
// Associate carrier to all zones
$zones = Zone::getZones(true);
foreach ($zones as $zone) {
Db::getInstance()->insert('carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']));
Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
}
// Copy the carrier logo
copy(dirname(__FILE__) . '/views/img/' . $carrier_key . '.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
// Save the carrier ID in the Configuration table
Configuration::updateValue($carrier_key, $carrier->id);
}
}
return true;
}