本文整理汇总了PHP中RangePrice类的典型用法代码示例。如果您正苦于以下问题:PHP RangePrice类的具体用法?PHP RangePrice怎么用?PHP RangePrice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RangePrice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例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 && RangePrice::rangeExist((int) Tools::getValue('id_carrier'), (double) Tools::getValue('delimiter1'), (double) Tools::getValue('delimiter2'))) {
$this->errors[] = Tools::displayError('The range already exists');
} elseif (RangePrice::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_price') && !count($this->_errors) && ($ranges = RangePrice::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_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;
}
示例7: 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();
}
示例8: 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);
}
示例9: 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;
}
示例10: 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;
}
}
示例11: createSoColissimoCarrierSeller
public static function createSoColissimoCarrierSeller($config)
{
$carrier = new Carrier();
$carrier->name = $config['name'] . ' - Commerce de proximité';
$carrier->id_tax_rules_group = $config['id_tax_rules_group'];
$carrier->id_zone = $config['id_zone'];
$carrier->url = $config['url'];
$carrier->active = 0;
$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_seller'][$language['iso_code']];
}
if ($language['iso_code'] == 'en') {
$carrier->delay[$language['id_lang']] = $config['delay_seller'][$language['iso_code']];
}
}
if ($carrier->add()) {
if (!version_compare(_PS_VERSION_, '1.5', '<')) {
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
}
Configuration::updateValue('SOCOLISSIMO_CARRIER_ID_SELLER', (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'] . '\')');
}
$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();
//copy logo
if (!copy(dirname(__FILE__) . '/img/socolissimo.jpg', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
return false;
}
return true;
}
return false;
}
示例12: cAddCarrierPost
public function cAddCarrierPost()
{
$db = Db::getInstance();
if (!Tools::getIsset('packetery_add_carrier') || !Tools::getValue('packetery_add_carrier')) {
return;
}
$carrier = new Carrier();
$carrier->name = Tools::getValue('packetery_carrier_name');
$carrier->active = true;
$carrier->shipping_method = defined('Carrier::SHIPPING_METHOD_WEIGHT') ? Carrier::SHIPPING_METHOD_WEIGHT : 1;
$carrier->deleted = 0;
$carrier->range_behavior = true;
// true disables this carrier if outside weight range
$carrier->is_module = false;
$carrier->external_module_name = "packetery";
$carrier->need_range = true;
foreach (Language::getLanguages(true) as $language) {
if (Tools::getIsset('delay_' . $language['id_lang']) && Tools::getValue('delay_' . $language['id_lang'])) {
$carrier->delay[$language['id_lang']] = Tools::getValue('delay_' . $language['id_lang']);
}
}
if (!$carrier->add()) {
return false;
}
$country = "";
$countries = Tools::getValue('packetery_carrier_country');
foreach ($countries as $key => $countryCode) {
$country .= $countryCode;
if ($key != count($countries) - 1) {
$country .= ',';
}
}
$db->execute('insert into `' . _DB_PREFIX_ . 'packetery_carrier` set id_carrier=' . (int) $carrier->id . ', country="' . pSQL($country ? $country : 'cz,sk') . '", list_type=' . (int) Tools::getValue('packetery_carrier_list_type') . ', is_cod=' . (Tools::getIsset('packetery_carrier_is_cod') ? (int) Tools::getValue('packetery_carrier_is_cod') : 0));
foreach (Group::getGroups(true) as $group) {
$db->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
}
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '5';
$rangeWeight->add();
$rangePrice = new RangePrice();
$rangePrice->id_carrier = $carrier->id;
$rangePrice->delimiter1 = '0';
$rangePrice->delimiter2 = '1000000';
$rangePrice->add();
$zones = Zone::getZones(true);
foreach ($zones as $zone) {
$db->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
$db->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->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');
}
if (Tools::getIsset('packetery_carrier_logo') && Tools::strlen(Tools::getValue('packetery_carrier_logo')) == 2) {
copy(dirname(__FILE__) . '/logo-' . Tools::getValue('packetery_carrier_logo') . '.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
}
}
示例13: createCarrier
private function createCarrier($config, $product_id, $name, $debug_mode = false, &$debug_info = array())
{
$carrier = new Carrier();
if ($debug_mode) {
array_push($debug_info, "Trying to create carrier " . $product_id . " with name " . $name);
}
$carrier->name = $name;
$carrier->id_zone = $config['id_zone'];
$carrier->url = $config['url'];
$carrier->active = $config['active'];
$carrier->deleted = $config['deleted'];
$carrier->shipping_handling = $config['shipping_handling'];
$carrier->range_behaviour = $config['range_behaviour'];
$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'] == 'en') {
$carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
}
if ($language['iso_code'] == 'no') {
$carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
}
}
if ($debug_mode) {
array_push($debug_info, "Adding carrier");
}
if ($carrier->add()) {
if ($debug_mode) {
array_push($debug_info, "Carrier added, setting up associations");
}
$carriers_str = Configuration::get('FRAKTGUIDE_CREATED_CARRIER_IDS');
$carriers = $carriers_str ? explode(';', Configuration::get('FRAKTGUIDE_CREATED_CARRIER_IDS')) : array();
$carriers[] = $carrier->id;
Configuration::updateValue('FRAKTGUIDE_CREATED_CARRIER_IDS', implode(';', $carriers));
$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'] . '\')');
}
$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();
if ($debug_mode) {
array_push($debug_info, "Trying to update product name table");
}
if (!Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'fraktguide_product_names`(`id_carrier`, `product_id`) VALUES(' . $carrier->id . ', \'' . $product_id . '\')')) {
return false;
}
if (!copy(dirname(__FILE__) . '/img/logo.png', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
return false;
}
if ($debug_mode) {
array_push($debug_info, "Success");
}
// Link to correct tax group (ps_carrier_tax_rules_group_shop aparently...)
if (!Db::getInstance()->insert('carrier_tax_rules_group_shop', array('id_carrier' => $carrier->id, 'id_tax_rules_group' => Configuration::get('FRAKTGUIDE_ID_TAX_RULES_GROUP'), 'id_shop' => Context::getContext()->shop->id))) {
return false;
}
return true;
} else {
Tools::dieOrLog("Error creating carrier " . $product_id);
return false;
}
}
示例14: 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;
}
示例15: installExternalCarrier
/**
*
* @param type $config
* @return boolean
*/
public function installExternalCarrier($config)
{
$check = Db::getInstance()->executeS("SELECT id_carrier FROM " . _DB_PREFIX_ . "carrier WHERE name = '" . $config['name'] . "' ");
if (is_array($check) && !empty($check)) {
return Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier', array('deleted' => 0), 'UPDATE', ' name = "' . $config['name'] . '" ');
}
$carrier = new Carrier();
$carrier->name = $config['name'];
$carrier->url = $config['url'];
$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) {
$carrier->delay[(int) $language['id_lang']] = $config['delay']['br'];
}
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 = '0';
$rangePrice->add();
$rangeWeight = new RangeWeight();
$rangeWeight->id_carrier = $carrier->id;
$rangeWeight->delimiter1 = '0';
$rangeWeight->delimiter2 = '30';
$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');
}
Configuration::updateValue("PS_CORREIOS_CARRIER_{$carrier->id}", $config['cod_servico']);
// Copy Logo
if (!copy(dirname(__FILE__) . '/logos/' . $config['cod_servico'] . '.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) {
return false;
}
// Return ID Carrier
return (int) $carrier->id;
}
return false;
}