// merge 1.4 (5397)
This commit is contained in:
+141
-2
@@ -168,6 +168,145 @@ class AddressCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns fields required for an address in an array hash
|
||||
* @return array hash values
|
||||
*/
|
||||
public static function getFieldsValidate()
|
||||
{
|
||||
$tmp_addr = new Address();
|
||||
$out = ($tmp_addr->fieldsValidate);
|
||||
|
||||
unset($tmp_addr);
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns selected fields required for an address in an array according to a selection hash
|
||||
* @return array String values
|
||||
*/
|
||||
public static function getDispFieldsValidate()
|
||||
{
|
||||
$out = array();
|
||||
$remove_fields = array(
|
||||
'id_customer' => 1
|
||||
,'id_manufacturer' => 1
|
||||
,'id_supplier' => 1
|
||||
,'deleted'=> 1
|
||||
,'dni' => 1
|
||||
,'vat_number' => 1
|
||||
,'other' => 1
|
||||
|
||||
);
|
||||
|
||||
$fields_hash = self::getFieldsValidate();
|
||||
foreach (array_keys($fields_hash) as $field_item)
|
||||
{
|
||||
if (!isset($remove_fields[$field_item]))
|
||||
{
|
||||
if ($field_item == 'id_country')
|
||||
$field_item = 'country';
|
||||
elseif($field_item == 'id_state')
|
||||
$field_item = 'state';
|
||||
|
||||
$out[] = $field_item;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns values ordered in an array according to given fields
|
||||
* @param array $config set options for the method formated as
|
||||
$config = array(
|
||||
'spacer' => ' '
|
||||
, 'optional' => array(
|
||||
'company' => 1
|
||||
,'phone' => 1
|
||||
)
|
||||
, 'ignore' => array(
|
||||
'phone_mobile' => 1
|
||||
)
|
||||
, 'return_set' => true (true: hash return, false: String array)
|
||||
)
|
||||
* @param String $pattern lines of each needed fields \n splitted
|
||||
* @param array $values optionnal given values
|
||||
* @return array field values or hash values
|
||||
*/
|
||||
public static function getOrderedValuesFromArray($config, $pattern, array $values = null)
|
||||
{
|
||||
$tmp_address = new Address();
|
||||
$out = $tmp_address->getOrderedValues($config, $pattern, $values);
|
||||
unset($tmp_address);
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns values ordered in an array according to given fields
|
||||
* @param array $config set options for the method formated as
|
||||
$config = array(
|
||||
'spacer' => ' '
|
||||
, 'optional' => array(
|
||||
'company' => 1
|
||||
,'phone' => 1
|
||||
,'phone_mobile' => 1
|
||||
)
|
||||
, 'return_set' => true
|
||||
)
|
||||
* @param String $address_datas lines of each needed fields \n splitted
|
||||
* @param array $given_values optionnal given values
|
||||
* @return array field values or values in a hash
|
||||
*/
|
||||
|
||||
public function getOrderedValues(array $config, $address_datas, array $given_values = null)
|
||||
{
|
||||
|
||||
$spacer = $config["spacer"]; // String used for joining lines_out
|
||||
$optional_fields = (isset($config["optional"]))? $config["optional"] : array(); // array hash tells which fields are optional
|
||||
|
||||
$ignore = (isset($config["ignore"]))? $config["ignore"] : array(); // array hash tells which fields are ignored
|
||||
|
||||
|
||||
$return_set = (!empty($config["return_set"])) ? $config["return_set"] : false;
|
||||
|
||||
$line_breaker = "\n"; // used in address_datas format
|
||||
|
||||
|
||||
$lines_out = array();
|
||||
$fields_lines = explode($line_breaker, $address_datas);
|
||||
|
||||
foreach ($fields_lines as $one_line)
|
||||
if(!empty($one_line) && $one_line!= '')
|
||||
{
|
||||
$tmp_values = array();
|
||||
$val_added = false;
|
||||
|
||||
$words = explode(' ', trim($one_line));
|
||||
$tmp_words = array();
|
||||
|
||||
foreach ($words as $one_word)
|
||||
{
|
||||
if (!isset($ignore[$one_word]))
|
||||
{
|
||||
$one_word = trim($one_word);
|
||||
$val = (is_null($given_values)) ? $this->{$one_word} : $given_values[$one_word];
|
||||
if ((!empty($val) && $val != '') || ((empty($val) || $val == '') && (isset($optional_fields[$one_word]) != 1)))
|
||||
{
|
||||
$tmp_values[$one_word] = $val;
|
||||
$val_added = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($val_added)
|
||||
$lines_out[] = ($return_set) ? $tmp_values : implode($spacer, $tmp_values);
|
||||
}
|
||||
return $lines_out;
|
||||
}
|
||||
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
parent::validateFields();
|
||||
@@ -197,9 +336,9 @@ class AddressCore extends ObjectModel
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function validateControler($htmlentities = true)
|
||||
public function validateController($htmlentities = true)
|
||||
{
|
||||
$errors = parent::validateControler($htmlentities);
|
||||
$errors = parent::validateController($htmlentities);
|
||||
if (!Configuration::get('VATNUMBER_CHECKING'))
|
||||
return $errors;
|
||||
include_once(_PS_MODULE_DIR_.'vatnumber/vatnumber.php');
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 1.4 $
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class AddressFormatCore extends ObjectModel
|
||||
{
|
||||
/** @var integer */
|
||||
public $id_address_format;
|
||||
|
||||
/** @var integer */
|
||||
public $id_country;
|
||||
|
||||
/** @var string */
|
||||
public $format;
|
||||
|
||||
|
||||
protected $fieldsRequired = array ('format');
|
||||
protected $fieldsValidate = array ('format' => 'isGenericName');
|
||||
|
||||
/* MySQL does not allow 'order detail' for a table name */
|
||||
protected $table = 'address_format';
|
||||
protected $identifier = 'id_country';
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
parent::validateFields();
|
||||
|
||||
$fields['id_country'] = (int)($this->id_country);
|
||||
$fields['format'] = pSQL($this->format);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
public function checkFormatFields()
|
||||
{
|
||||
$out = true;
|
||||
$addr_f_validate = Address::getFieldsValidate();
|
||||
|
||||
$fields_format = explode("\n", $this->format);
|
||||
foreach($fields_format as $field_line)
|
||||
{
|
||||
$fields = explode(' ', trim($field_line));
|
||||
foreach($fields as $field_item)
|
||||
{
|
||||
$field_item = trim($field_item);
|
||||
if (!isset($addr_f_validate[$field_item]) && !isset($addr_f_validate['id_'.$field_item]))
|
||||
$out = false;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns address format fields in array by country
|
||||
*
|
||||
* @param Integer PS_COUNTRY.id
|
||||
* @return Array String field address format
|
||||
*/
|
||||
public static function getOrderedAddressFields($id_country)
|
||||
{
|
||||
$out = array();
|
||||
$field_set = explode("\n", self::getAddressCountryFormat($id_country));
|
||||
foreach ($field_set as $field_item)
|
||||
{
|
||||
$out[] = trim($field_item);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns address format by country if not defined using default country
|
||||
*
|
||||
* @param Integer PS_COUNTRY.id
|
||||
* @return String field address format
|
||||
*/
|
||||
public static function getAddressCountryFormat($id_country)
|
||||
{
|
||||
$out = '';
|
||||
$tmp_obj = new AddressFormat();
|
||||
$tmp_obj->id_country = $id_country;
|
||||
$out = $tmp_obj->getFormat($tmp_obj->id_country);
|
||||
unset($tmp_obj);
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns address format by country
|
||||
*
|
||||
* @param Integer PS_COUNTRY.id
|
||||
* @return String field address format
|
||||
*/
|
||||
public function getFormat($id_country)
|
||||
{
|
||||
global $defaultCountry;
|
||||
$out = $this->_getFormatDB($id_country);
|
||||
if (strlen(trim($out)) == 0)
|
||||
{
|
||||
$out = $this->_getFormatDB($defaultCountry->id);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function _getFormatDB($id_country)
|
||||
{
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT format
|
||||
FROM `'._DB_PREFIX_.$this->table.'`
|
||||
WHERE `id_country` = '.(int)($id_country));
|
||||
|
||||
return isset($result['format']) ? $result['format'] : false;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-8
@@ -185,14 +185,15 @@ abstract class AdminTabCore
|
||||
if ($className == 'AdminCategories' OR $className == 'AdminProducts')
|
||||
$className = 'AdminCatalog';
|
||||
$this->token = Tools::getAdminToken($className.(int)($this->id).(int)($cookie->id_employee));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* use translations files to replace english expression.
|
||||
*
|
||||
*
|
||||
* @param mixed $string term or expression in english
|
||||
* @param string $class
|
||||
* @param string $class
|
||||
* @param boolan $addslashes if set to true, the return value will pass through addslashes(). Otherwise, stripslashes().
|
||||
* @param boolean $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8')
|
||||
* @return string the translation if available, or the english default text.
|
||||
@@ -297,6 +298,7 @@ abstract class AdminTabCore
|
||||
foreach ($res AS $row)
|
||||
$required_fields[(int)$row['id_required_field']] = $row['field_name'];
|
||||
|
||||
|
||||
$table_fields = Db::getInstance()->ExecuteS('SHOW COLUMNS FROM '.pSQL(_DB_PREFIX_.$this->table));
|
||||
$irow = 0;
|
||||
foreach ($table_fields AS $field)
|
||||
@@ -1094,7 +1096,7 @@ abstract class AdminTabCore
|
||||
LIMIT '.(int)($start).','.(int)($limit);
|
||||
|
||||
$this->_list = Db::getInstance()->ExecuteS($sql);
|
||||
$this->_listTotal = count(Db::getInstance()->ExecuteS('SELECT
|
||||
$this->_listTotal = count(Db::getInstance()->ExecuteS('SELECT
|
||||
'.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
|
||||
'.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').'
|
||||
FROM `'._DB_PREFIX_.$sqlTable.'` a
|
||||
@@ -1105,8 +1107,8 @@ abstract class AdminTabCore
|
||||
'.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').(isset($this->_having) ? $this->_having.' ' : '').'
|
||||
ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).
|
||||
($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '')));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1145,9 +1147,9 @@ abstract class AdminTabCore
|
||||
global $currentIndex, $cookie;
|
||||
$isCms = false;
|
||||
if (preg_match('/cms/Ui', $this->identifier))
|
||||
$isCms = true;
|
||||
$isCms = true;
|
||||
$id_cat = Tools::getValue('id_'.($isCms ? 'cms_' : '').'category');
|
||||
|
||||
|
||||
if (!isset($token) OR empty($token))
|
||||
$token = $this->token;
|
||||
|
||||
@@ -1469,7 +1471,7 @@ abstract class AdminTabCore
|
||||
{
|
||||
global $currentIndex;
|
||||
|
||||
echo '<a href="'.$currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.
|
||||
echo '<a href="'.$currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table.
|
||||
((int)$id_category AND (int)$id_product ? '&id_category='.$id_category : '').'&token='.($token!=NULL ? $token : $this->token).'">
|
||||
<img src="../img/admin/'.($value ? 'enabled.gif' : 'disabled.gif').'"
|
||||
alt="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" title="'.($value ? $this->l('Enabled') : $this->l('Disabled')).'" /></a>';
|
||||
|
||||
+48
-25
@@ -684,13 +684,13 @@ class CartCore extends ObjectModel
|
||||
self::$_nbProducts = NULL;
|
||||
if ((int)($id_customization))
|
||||
{
|
||||
$productTotalQuantity = (int)(Db::getInstance()->getValue('SELECT `quantity`
|
||||
FROM `'._DB_PREFIX_.'cart_product`
|
||||
$productTotalQuantity = (int)(Db::getInstance()->getValue('SELECT `quantity`
|
||||
FROM `'._DB_PREFIX_.'cart_product`
|
||||
WHERE `id_product` = '.(int)($id_product).' AND `id_product_attribute` = '.(int)($id_product_attribute)));
|
||||
$customizationQuantity = (int)(Db::getInstance()->getValue('SELECT `quantity`
|
||||
FROM `'._DB_PREFIX_.'customization`
|
||||
WHERE `id_cart` = '.(int)($this->id).'
|
||||
AND `id_product` = '.(int)($id_product).'
|
||||
$customizationQuantity = (int)(Db::getInstance()->getValue('SELECT `quantity`
|
||||
FROM `'._DB_PREFIX_.'customization`
|
||||
WHERE `id_cart` = '.(int)($this->id).'
|
||||
AND `id_product` = '.(int)($id_product).'
|
||||
AND `id_product_attribute` = '.(int)($id_product_attribute)));
|
||||
if (!$this->_deleteCustomization((int)($id_customization), (int)($id_product), (int)($id_product_attribute)))
|
||||
return false;
|
||||
@@ -719,7 +719,7 @@ class CartCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a customization from the cart. If customization is a Picture (type=2),
|
||||
* Delete a customization from the cart. If customization is a Picture (type=2),
|
||||
* then the image is also deleted
|
||||
*
|
||||
* @param integer $id_customization
|
||||
@@ -729,7 +729,7 @@ class CartCore extends ObjectModel
|
||||
{
|
||||
$result = true;
|
||||
$customization = Db::getInstance()->getRow('SELECT *
|
||||
FROM `'._DB_PREFIX_.'customization`
|
||||
FROM `'._DB_PREFIX_.'customization`
|
||||
WHERE `id_customization` = '.(int)($id_customization));
|
||||
|
||||
if ($customization and sizeof($customization))
|
||||
@@ -737,7 +737,7 @@ class CartCore extends ObjectModel
|
||||
$custData = Db::getInstance()->getRow('SELECT *
|
||||
FROM `'._DB_PREFIX_.'customized_data`
|
||||
WHERE `id_customization` = '.(int)($id_customization));
|
||||
|
||||
|
||||
if (isset($custData['type']) and $custData['type'] == 0)
|
||||
$result &= $this->deletePictureToProduct($id_product,$custData['value']);
|
||||
|
||||
@@ -748,15 +748,15 @@ class CartCore extends ObjectModel
|
||||
if($result)
|
||||
$result &= Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'cart_product`
|
||||
SET `quantity` = `quantity` - '.(int)($customization['quantity']).'
|
||||
WHERE `id_cart` = '.(int)($this->id).'
|
||||
AND `id_product` = '.(int)($id_product).((int)($id_product_attribute) ? '
|
||||
WHERE `id_cart` = '.(int)($this->id).'
|
||||
AND `id_product` = '.(int)($id_product).((int)($id_product_attribute) ? '
|
||||
AND `id_product_attribute` = '.(int)($id_product_attribute) : ''));
|
||||
|
||||
if (!$result)
|
||||
return false;
|
||||
|
||||
return Db::getInstance()->Execute('DELETE
|
||||
FROM `'._DB_PREFIX_.'customization`
|
||||
return Db::getInstance()->Execute('DELETE
|
||||
FROM `'._DB_PREFIX_.'customization`
|
||||
WHERE `id_customization` = '.(int)($id_customization));
|
||||
}
|
||||
|
||||
@@ -829,8 +829,10 @@ class CartCore extends ObjectModel
|
||||
|
||||
if ($withTaxes)
|
||||
{
|
||||
$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);
|
||||
$total_price = Tools::ps_round($total_price - $total_ecotax, 2);
|
||||
$total_price = ($total_price - $total_ecotax) * (1 + (float)(Tax::getProductTaxRate((int)$product['id_product'], (int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')})) / 100);
|
||||
$total_ecotax = $total_ecotax * (1 + Tax::getProductEcotaxRate((int)$this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}) / 100);
|
||||
$total_price = Tools::ps_round($total_price + $total_ecotax, 2);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -971,18 +973,12 @@ class CartCore extends ObjectModel
|
||||
// If no carrier, select default one
|
||||
if (!$id_carrier)
|
||||
$id_carrier = $this->id_carrier;
|
||||
if (empty($id_carrier))
|
||||
{
|
||||
$carrier = new Carrier((int)(Configuration::get('PS_CARRIER_DEFAULT')), Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
if (($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT AND (Carrier::checkDeliveryPriceByWeight((int)(Configuration::get('PS_CARRIER_DEFAULT')), $this->getTotalWeight(), $id_zone)))
|
||||
OR ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE AND (Carrier::checkDeliveryPriceByPrice((int)(Configuration::get('PS_CARRIER_DEFAULT')), $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, (int)($this->id_currency)))))
|
||||
{
|
||||
if ($id_carrier && !$this->isCarrierInRange($id_carrier, $id_zone))
|
||||
$id_carrier = '';
|
||||
|
||||
if (empty($id_carrier) && $this->isCarrierInRange(Configuration::get('PS_CARRIER_DEFAULT'), $id_zone))
|
||||
$id_carrier = (int)(Configuration::get('PS_CARRIER_DEFAULT'));
|
||||
}
|
||||
|
||||
unset($carrier);
|
||||
}
|
||||
|
||||
if (empty($id_carrier))
|
||||
{
|
||||
@@ -1255,6 +1251,7 @@ class CartCore extends ObjectModel
|
||||
$invoice = new Address((int)($this->id_address_invoice));
|
||||
|
||||
$total_tax = $this->getOrderTotal() - $this->getOrderTotal(false);
|
||||
|
||||
if ($total_tax < 0)
|
||||
$total_tax = 0;
|
||||
|
||||
@@ -1540,5 +1537,31 @@ class CartCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'cart` ca ON (ca.`id_customer` = cu.`id_customer`)
|
||||
WHERE ca.`id_cart` = '.(int)$id_cart);
|
||||
}
|
||||
|
||||
/**
|
||||
* isCarrierInRange
|
||||
*
|
||||
* Check if the specified carrier is in range
|
||||
*
|
||||
* @id_carrier int
|
||||
* @id_zone int
|
||||
*/
|
||||
public function isCarrierInRange($id_carrier, $id_zone)
|
||||
{
|
||||
$carrier = new Carrier((int)$id_carrier, Configuration::get('PS_LANG_DEFAULT'));
|
||||
$is_in_zone = false;
|
||||
$order_total = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
|
||||
|
||||
if (($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT
|
||||
AND (Carrier::checkDeliveryPriceByWeight((int)$id_carrier, $this->getTotalWeight(), $id_zone)))
|
||||
OR ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE
|
||||
AND (Carrier::checkDeliveryPriceByPrice((int)$id_carrier, $order_total, $id_zone, (int)($this->id_currency)))))
|
||||
{
|
||||
$is_in_zone = true;
|
||||
}
|
||||
|
||||
unset($carrier);
|
||||
return $is_in_zone;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-8
@@ -56,6 +56,9 @@ class CountryCore extends ObjectModel
|
||||
/** @var string Zip Code Format */
|
||||
public $zip_code_format;
|
||||
|
||||
/** @var boolean Display or not the tax incl./tax excl. mention in the front office */
|
||||
public $display_tax_label = true;
|
||||
|
||||
/** @var boolean Status for delivery */
|
||||
public $active = true;
|
||||
|
||||
@@ -63,9 +66,9 @@ class CountryCore extends ObjectModel
|
||||
|
||||
protected $tables = array ('country', 'country_lang');
|
||||
|
||||
protected $fieldsRequired = array('id_zone', 'id_currency', 'iso_code', 'contains_states', 'need_identification_number');
|
||||
protected $fieldsRequired = array('id_zone', 'id_currency', 'iso_code', 'contains_states', 'need_identification_number', 'display_tax_label');
|
||||
protected $fieldsSize = array('iso_code' => 3);
|
||||
protected $fieldsValidate = array('id_zone' => 'isUnsignedId', 'id_currency' => 'isUnsignedId', 'call_prefix' => 'isInt', 'iso_code' => 'isLanguageIsoCode', 'active' => 'isBool', 'contains_states' => 'isBool', 'need_identification_number' => 'isBool', 'need_zip_code' => 'isBool', 'zip_code_format' => 'isZipCodeFormat');
|
||||
protected $fieldsValidate = array('id_zone' => 'isUnsignedId', 'id_currency' => 'isUnsignedId', 'call_prefix' => 'isInt', 'iso_code' => 'isLanguageIsoCode', 'active' => 'isBool', 'contains_states' => 'isBool', 'need_identification_number' => 'isBool', 'need_zip_code' => 'isBool', 'zip_code_format' => 'isZipCodeFormat', 'display_tax_label' => 'isBool');
|
||||
protected $fieldsRequiredLang = array('name');
|
||||
protected $fieldsSizeLang = array('name' => 64);
|
||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
||||
@@ -93,6 +96,7 @@ class CountryCore extends ObjectModel
|
||||
$fields['need_identification_number'] = (int)($this->need_identification_number);
|
||||
$fields['need_zip_code'] = (int)($this->need_zip_code);
|
||||
$fields['zip_code_format'] = $this->zip_code_format;
|
||||
$fields['display_tax_label'] = $this->display_tax_label;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -291,27 +295,27 @@ class CountryCore extends ObjectModel
|
||||
AND `id_lang` = '.(int)$id_lang
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function isNeedDni()
|
||||
{
|
||||
return (bool)self::isNeedDniByCountryId($this->id);
|
||||
}
|
||||
|
||||
|
||||
static public function isNeedDniByCountryId($id_country)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT `need_identification_number`
|
||||
SELECT `need_identification_number`
|
||||
FROM `'._DB_PREFIX_.'country`
|
||||
WHERE `id_country` = '.(int)$id_country);
|
||||
}
|
||||
|
||||
|
||||
static public function containsStates($id_country)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT `contains_states`
|
||||
SELECT `contains_states`
|
||||
FROM `'._DB_PREFIX_.'country`
|
||||
WHERE `id_country` = '.(int)$id_country);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ class FrontControllerCore
|
||||
public function init()
|
||||
{
|
||||
global $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files;
|
||||
|
||||
|
||||
$css_files = array();
|
||||
$js_files = array();
|
||||
|
||||
@@ -135,7 +135,10 @@ class FrontControllerCore
|
||||
if ($cart->OrderExists())
|
||||
unset($cookie->id_cart, $cart);
|
||||
/* Delete product of cart, if user can't make an order from his country */
|
||||
elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) AND !in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) AND $cart->nbProducts() AND intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1)
|
||||
elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) AND
|
||||
!in_array(strtoupper($cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) AND
|
||||
$cart->nbProducts() AND intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 AND
|
||||
!self::isInWhitelistForGeolocation())
|
||||
unset($cookie->id_cart, $cart);
|
||||
elseif ($cookie->id_customer != $cart->id_customer OR $cookie->id_lang != $cart->id_lang OR $cookie->id_currency != $cart->id_currency)
|
||||
{
|
||||
@@ -203,6 +206,15 @@ class FrontControllerCore
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$smarty->assign(array(
|
||||
'link' => $link,
|
||||
'cart' => $cart,
|
||||
@@ -225,6 +237,7 @@ class FrontControllerCore
|
||||
'shop_name' => Configuration::get('PS_SHOP_NAME'),
|
||||
'roundMode' => (int)Configuration::get('PS_PRICE_ROUND_MODE'),
|
||||
'use_taxes' => (int)Configuration::get('PS_TAX'),
|
||||
'display_tax_label' => (bool)$display_tax_label,
|
||||
'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'),
|
||||
'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'),
|
||||
'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE')
|
||||
@@ -275,7 +288,7 @@ class FrontControllerCore
|
||||
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
||||
if (!is_dir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$ad))
|
||||
die(Tools::displayError());
|
||||
|
||||
|
||||
|
||||
$this->iso = $iso;
|
||||
$this->setMedia();
|
||||
@@ -284,7 +297,7 @@ class FrontControllerCore
|
||||
/* Display a maintenance page if shop is closed */
|
||||
protected function displayMaintenancePage()
|
||||
{
|
||||
|
||||
|
||||
if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP'))))
|
||||
{
|
||||
header('HTTP/1.1 503 temporarily overloaded');
|
||||
@@ -297,7 +310,7 @@ class FrontControllerCore
|
||||
protected function displayRestrictedCountryPage()
|
||||
{
|
||||
global $smarty;
|
||||
|
||||
|
||||
header('HTTP/1.1 503 temporarily overloaded');
|
||||
$smarty->display(_PS_THEME_DIR_.'restricted-country.tpl');
|
||||
exit;
|
||||
@@ -306,7 +319,7 @@ class FrontControllerCore
|
||||
protected function canonicalRedirection()
|
||||
{
|
||||
global $link, $cookie;
|
||||
|
||||
|
||||
if (Configuration::get('PS_CANONICAL_REDIRECT'))
|
||||
{
|
||||
// Automatically redirect to the canonical URL if needed
|
||||
@@ -392,13 +405,13 @@ class FrontControllerCore
|
||||
public function setMedia()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
|
||||
Tools::addCSS(_THEME_CSS_DIR_.'global.css', 'all');
|
||||
Tools::addJS(array(_PS_JS_DIR_.'tools.js', _PS_JS_DIR_.'jquery/jquery-1.4.4.min.js', _PS_JS_DIR_.'jquery/jquery.easing.1.3.js'));
|
||||
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
|
||||
{
|
||||
Tools::addJS(array(
|
||||
_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js',
|
||||
_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js',
|
||||
_PS_JS_DIR_.'jquery/jquery.fancybox-1.3.4.js',
|
||||
_PS_JS_DIR_.'hookLiveEdit.js')
|
||||
);
|
||||
@@ -453,7 +466,7 @@ class FrontControllerCore
|
||||
if (Configuration::get('PS_JS_THEME_CACHE'))
|
||||
Tools::cccJs();
|
||||
}
|
||||
|
||||
|
||||
self::$smarty->assign('css_files', $css_files);
|
||||
self::$smarty->assign('js_files', array_unique($js_files));
|
||||
self::$smarty->display(_PS_THEME_DIR_.'header.tpl');
|
||||
|
||||
@@ -277,6 +277,7 @@ class LanguageCore extends ObjectModel
|
||||
$langTables[] = $t;
|
||||
|
||||
Db::getInstance()->Execute('SET @id_lang_default = (SELECT c.`value` FROM `'._DB_PREFIX_.'configuration` c WHERE c.`name` = \'PS_LANG_DEFAULT\' LIMIT 1)');
|
||||
$return = true;
|
||||
foreach($langTables as $name)
|
||||
{
|
||||
$fields = '';
|
||||
@@ -293,8 +294,9 @@ class LanguageCore extends ObjectModel
|
||||
$sql .= '(SELECT `'.$column['Field'].'` FROM `'.$name.'` tl WHERE tl.`id_lang` = @id_lang_default AND tl.`'.$identifier.'` = `'.str_replace('_lang', '', $name).'`.`'.$identifier.'`), ';
|
||||
$sql = rtrim($sql, ', ');
|
||||
$sql .= ' FROM `'._DB_PREFIX_.'lang` CROSS JOIN `'.str_replace('_lang', '', $name).'`) ;';
|
||||
Db::getInstance()->Execute(pSQL($sql));
|
||||
$return &= Db::getInstance()->Execute(pSQL($sql));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public static function recurseDeleteDir($dir)
|
||||
|
||||
+2
-1
@@ -539,6 +539,7 @@ abstract class ModuleCore
|
||||
*/
|
||||
public static function getNonNativeModuleList()
|
||||
{
|
||||
$db = Db::getInstance();
|
||||
$modulesDirOnDisk = Module::getModulesDirOnDisk();
|
||||
|
||||
$module_list_xml = _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'modules_list.xml';
|
||||
@@ -552,7 +553,7 @@ abstract class ModuleCore
|
||||
$arrNativeModules[] = '"'.pSQL($module['name']).'"';
|
||||
}
|
||||
|
||||
return Db::getInstance()->ExecuteS('
|
||||
return $db->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'module` m
|
||||
WHERE name NOT IN ('.implode(',',$arrNativeModules).') ');
|
||||
|
||||
@@ -452,7 +452,15 @@ abstract class ObjectModelCore
|
||||
return ((is_array($_FIELDS) AND array_key_exists($key, $_FIELDS)) ? ($htmlentities ? htmlentities($_FIELDS[$key], ENT_QUOTES, 'utf-8') : $_FIELDS[$key]) : $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: refactor rename all calls to this to validateController
|
||||
*/
|
||||
public function validateControler($htmlentities = true)
|
||||
{
|
||||
return $this->validateController($htmlentities);
|
||||
}
|
||||
|
||||
public function validateController($htmlentities = true)
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
|
||||
@@ -288,17 +288,25 @@ class OrderCore extends ObjectModel
|
||||
$this->total_products -= $productPriceWithoutTax;
|
||||
$this->total_products_wt -= $productPrice;
|
||||
$this->total_shipping = $cart->getOrderShippingCost();
|
||||
|
||||
/* It's temporary fix for 1.3 version... */
|
||||
if ($orderDetail->product_quantity_discount != '0.000000')
|
||||
$this->total_paid -= ($productPrice + $shippingDiff);
|
||||
else
|
||||
$this->total_paid = $cart->getOrderTotal();
|
||||
|
||||
$this->total_paid_real -= ($productPrice + $shippingDiff);
|
||||
|
||||
/* Prevent from floating precision issues (total_products has only 2 decimals) */
|
||||
if ($this->total_products < 0)
|
||||
$this->total_products = 0;
|
||||
|
||||
if ($this->total_paid < 0)
|
||||
$this->total_paid = 0;
|
||||
|
||||
if ($this->total_paid_real < 0)
|
||||
$this->total_paid_real = 0;
|
||||
|
||||
/* Prevent from floating precision issues */
|
||||
$this->total_paid = number_format($this->total_paid, 2, '.', '');
|
||||
$this->total_paid_real = number_format($this->total_paid_real, 2, '.', '');
|
||||
|
||||
+99
-37
@@ -278,23 +278,51 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$pdf->SetY(25);
|
||||
$pdf->SetFont(self::fontname(), '', 9);
|
||||
|
||||
if (!empty($delivery_address->company))
|
||||
|
||||
|
||||
$ordered_adr_fields = AddressFormat::getOrderedAddressFields($invoice_address->id_country);
|
||||
|
||||
$optional_fields = array(
|
||||
'address2' => 1
|
||||
, 'company' => 1
|
||||
);
|
||||
$ignore_fields = array(
|
||||
'phone' => 1
|
||||
, 'mobile_phone' =>1
|
||||
);
|
||||
|
||||
foreach ($ordered_adr_fields as $adr_line)
|
||||
{
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->company), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
$line_fields = explode(" ", trim($adr_line));
|
||||
$tmp_dlv_vals = array();
|
||||
|
||||
foreach($line_fields as $field_name)
|
||||
{
|
||||
// if not skip
|
||||
if (!isset($ignore_fields[$field_name]))
|
||||
{
|
||||
$tmp_dlv = $delivery_address->{$field_name};
|
||||
|
||||
if (!((empty($tmp_dlv) || $tmp_dlv == '') && isset($optional_fields[$field_name])))
|
||||
{
|
||||
$tmp_dlv = ($field_name == "country") ? $tmp_dlv.($deliveryState ? ' - '.$deliveryState->name : ''): $tmp_dlv;
|
||||
$tmp_dlv_vals[] = Tools::iconv('utf-8', self::encoding(), $tmp_dlv);
|
||||
}
|
||||
}
|
||||
}
|
||||
$str_dlv_vals = implode(" ", $tmp_dlv_vals);
|
||||
|
||||
$need_nl = false;
|
||||
if (!empty($str_dlv_vals) && $str_dlv_vals != '' && $str_dlv_vals != ' ')
|
||||
{
|
||||
$need_nl = true;
|
||||
$pdf->Cell($width, 10, $str_dlv_vals, 0, 'L');
|
||||
}
|
||||
|
||||
if ($need_nl)
|
||||
$pdf->Ln(5);
|
||||
|
||||
}
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->firstname).' '.Tools::iconv('utf-8', self::encoding(), $delivery_address->lastname), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->address1), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
if (!empty($delivery_address->address2))
|
||||
{
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->address2), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
}
|
||||
$pdf->Cell($width, 10, $delivery_address->postcode.' '.Tools::iconv('utf-8', self::encoding(), $delivery_address->city), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->country.($deliveryState ? ' - '.$deliveryState->name : '')), 0, 'L');
|
||||
|
||||
/*
|
||||
* display order information
|
||||
@@ -403,6 +431,17 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$delivery_address = new Address((int)($order->id_address_delivery));
|
||||
$deliveryState = $delivery_address->id_state ? new State($delivery_address->id_state) : false;
|
||||
|
||||
$ordered_adr_fields = AddressFormat::getOrderedAddressFields($invoice_address->id_country);
|
||||
|
||||
$optional_fields = array(
|
||||
'address2' => 1
|
||||
, 'company' => 1
|
||||
);
|
||||
$ignore_fields = array(
|
||||
'phone' => 1
|
||||
, 'mobile_phone' =>1
|
||||
);
|
||||
|
||||
$width = 100;
|
||||
|
||||
$pdf->SetX(10);
|
||||
@@ -413,30 +452,53 @@ class PDFCore extends PDF_PageGroupCore
|
||||
$pdf->Ln(5);
|
||||
$pdf->SetFont(self::fontname(), '', 9);
|
||||
|
||||
if (!empty($delivery_address->company) OR !empty($invoice_address->company))
|
||||
|
||||
foreach ($ordered_adr_fields as $adr_line)
|
||||
{
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->company), 0, 'L');
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->company), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
$line_fields = explode(" ", trim($adr_line));
|
||||
|
||||
$tmp_inv_vals = array();
|
||||
$tmp_dlv_vals = array();
|
||||
|
||||
foreach($line_fields as $field_name)
|
||||
{
|
||||
// if not skip
|
||||
if (!isset($ignore_fields[$field_name]))
|
||||
{
|
||||
$tmp_inv = $invoice_address->{$field_name};
|
||||
$tmp_dlv = $delivery_address->{$field_name};
|
||||
if (!((empty($tmp_inv) || $tmp_inv == '') && isset($optional_fields[$field_name])))
|
||||
{
|
||||
$tmp_inv = ($field_name == "country") ? $tmp_inv.($deliveryState ? ' - '.$deliveryState->name : ''): $tmp_inv;
|
||||
$tmp_inv_vals[] = Tools::iconv('utf-8', self::encoding(), $tmp_inv);
|
||||
}
|
||||
if (!((empty($tmp_dlv) || $tmp_dlv == '') && isset($optional_fields[$field_name])))
|
||||
{
|
||||
$tmp_dlv = ($field_name == "country") ? $tmp_dlv.($deliveryState ? ' - '.$deliveryState->name : ''): $tmp_dlv;
|
||||
$tmp_dlv_vals[] = Tools::iconv('utf-8', self::encoding(), $tmp_dlv);
|
||||
}
|
||||
}
|
||||
}
|
||||
$str_inv_vals = implode(" ", $tmp_inv_vals);
|
||||
$str_dlv_vals = implode(" ", $tmp_dlv_vals);
|
||||
|
||||
$need_nl = false;
|
||||
if (!empty($str_dlv_vals) && $str_dlv_vals != '' && $str_dlv_vals != ' ')
|
||||
{
|
||||
$need_nl = true;
|
||||
$pdf->Cell($width, 10, $str_dlv_vals, 0, 'L');
|
||||
}
|
||||
if (!empty($str_inv_vals) && $str_inv_vals != '' && $str_inv_vals != ' ')
|
||||
{
|
||||
$need_nl = true;
|
||||
$pdf->Cell($width, 10, $str_inv_vals, 0, 'L');
|
||||
}
|
||||
|
||||
if ($need_nl)
|
||||
$pdf->Ln(5);
|
||||
|
||||
}
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->firstname).' '.Tools::iconv('utf-8', self::encoding(), $delivery_address->lastname), 0, 'L');
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->firstname).' '.Tools::iconv('utf-8', self::encoding(), $invoice_address->lastname), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->address1), 0, 'L');
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->address1), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
if (!empty($invoice_address->address2) OR !empty($delivery_address->address2))
|
||||
{
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->address2), 0, 'L');
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->address2), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
}
|
||||
$pdf->Cell($width, 10, $delivery_address->postcode.' '.Tools::iconv('utf-8', self::encoding(), $delivery_address->city), 0, 'L');
|
||||
$pdf->Cell($width, 10, $invoice_address->postcode.' '.Tools::iconv('utf-8', self::encoding(), $invoice_address->city), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->country.($deliveryState ? ' - '.$deliveryState->name : '')), 0, 'L');
|
||||
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->country.($invoiceState ? ' - '.$invoiceState->name : '')), 0, 'L');
|
||||
$pdf->Ln(5);
|
||||
|
||||
|
||||
if (Configuration::get('VATNUMBER_MANAGEMENT') AND !empty($invoice_address->vat_number))
|
||||
{
|
||||
|
||||
@@ -367,6 +367,19 @@ abstract class PaymentModuleCore extends Module
|
||||
'{firstname}' => $customer->firstname,
|
||||
'{lastname}' => $customer->lastname,
|
||||
'{email}' => $customer->email,
|
||||
'{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"),
|
||||
'{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"),
|
||||
'{delivery_block_html}' => $this->_getFormatedAddress($delivery, "<br />", array(
|
||||
'firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>'
|
||||
, 'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>'
|
||||
|
||||
)),
|
||||
'{invoice_block_html}' => $this->_getFormatedAddress($invoice, "<br />", array(
|
||||
'firstname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>'
|
||||
, 'lastname' => '<span style="color:#DB3484; font-weight:bold;">%s</span>'
|
||||
|
||||
)),
|
||||
|
||||
'{delivery_company}' => $delivery->company,
|
||||
'{delivery_firstname}' => $delivery->firstname,
|
||||
'{delivery_lastname}' => $delivery->lastname,
|
||||
@@ -436,6 +449,57 @@ abstract class PaymentModuleCore extends Module
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Object Address $the_address that needs to be txt formated
|
||||
* @return String the txt formated address block
|
||||
*/
|
||||
private function _getTxtFormatedAddress($the_address)
|
||||
{
|
||||
$out = '';
|
||||
$adr_fields = AddressFormat::getOrderedAddressFields($the_address->id_country);
|
||||
$r_values = array();
|
||||
foreach($adr_fields as $fields_line)
|
||||
{
|
||||
$tmp_values = array();
|
||||
foreach (explode(' ', $fields_line) as $field_item)
|
||||
{
|
||||
$field_item = trim($field_item);
|
||||
$tmp_values[] = $the_address->{$field_item};
|
||||
}
|
||||
$r_values[] = implode(' ', $tmp_values);
|
||||
}
|
||||
|
||||
$out = implode("\n", $r_values);
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Object Address $the_address that needs to be txt formated
|
||||
* @return String the txt formated address block
|
||||
*/
|
||||
|
||||
private function _getFormatedAddress(Address $the_address, $line_sep, $fields_style = array())
|
||||
{
|
||||
$out = '';
|
||||
$adr_fields = AddressFormat::getOrderedAddressFields($the_address->id_country);
|
||||
|
||||
$r_values = array();
|
||||
|
||||
foreach($adr_fields as $fields_line)
|
||||
{
|
||||
$tmp_values = array();
|
||||
foreach (explode(' ', $fields_line) as $field_item)
|
||||
{
|
||||
$field_item = trim($field_item);
|
||||
$tmp_values[] = (isset($fields_style[$field_item]))? sprintf($fields_style[$field_item], $the_address->{$field_item}) : $the_address->{$field_item};
|
||||
}
|
||||
$r_values[] = implode(' ', $tmp_values);
|
||||
}
|
||||
|
||||
|
||||
$out = implode($line_sep, $r_values);
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_currency : this parameter is optionnal but on 1.5 version of Prestashop, it will be REQUIRED
|
||||
|
||||
+31
-17
@@ -1593,27 +1593,41 @@ class ProductCore extends ObjectModel
|
||||
}
|
||||
$quantity = ($id_cart AND $cart_quantity) ? $cart_quantity : $quantity;
|
||||
$id_currency = (int)(Validate::isLoadedObject($cur_cart) ? $cur_cart->id_currency : ((isset($cookie->id_currency) AND (int)($cookie->id_currency)) ? $cookie->id_currency : Configuration::get('PS_CURRENCY_DEFAULT')));
|
||||
if (!$id_address)
|
||||
$id_address = $cur_cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
|
||||
|
||||
if (Tax::excludeTaxeOption())
|
||||
$usetax = false;
|
||||
|
||||
// retrieve address informations
|
||||
$id_country = (int)Country::getDefaultCountryId();
|
||||
$id_state = 0;
|
||||
$id_county = 0;
|
||||
$id_state = 0;
|
||||
|
||||
|
||||
$address_infos = Address::getCountryAndState($id_address);
|
||||
if ($address_infos['id_country'])
|
||||
if (!$id_address)
|
||||
{
|
||||
$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 ($id_address = $cur_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']);
|
||||
$postcode = (int)$address_infos['postcode'];
|
||||
|
||||
$id_county = (int)County::getIdCountyByZipCode($id_state, $postcode);
|
||||
}
|
||||
} else if (isset($cookie->id_country)) {
|
||||
// fetch address from cookie
|
||||
$id_country = (int)$cookie->id_country;
|
||||
$id_state = (int)$cookie->id_state;
|
||||
$postcode = (int)$cookie->postcode;
|
||||
|
||||
$id_county = (int)County::getIdCountyByZipCode($id_state, $postcode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Tax::excludeTaxeOption())
|
||||
$usetax = false;
|
||||
|
||||
if ($usetax != false AND !empty($address_infos['vat_number']) AND $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') AND Configuration::get('VATNUMBER_MANAGEMENT'))
|
||||
$usetax = false;
|
||||
|
||||
@@ -1649,7 +1663,7 @@ class ProductCore extends ObjectModel
|
||||
$product_attribute_label = 'NULL';
|
||||
else
|
||||
$product_attribute_label = ($id_product_attribute === false ? 'false' : $id_product_attribute);
|
||||
$cacheId = $id_product.'-'.$id_shop.'-'.$id_currency.'-'.$id_country.'-'.$id_group.'-'.$quantity.'-'.$product_attribute_label.'-'.($use_tax?'1':'0').'-'.$decimals.'-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0');
|
||||
$cacheId = $id_product.'-'.$id_shop.'-'.$id_currency.'-'.$id_country.'-'.$id_state.'-'.$id_county.'-'.$id_group.'-'.$quantity.'-'.$product_attribute_label.'-'.($use_tax?'1':'0').'-'.$decimals.'-'.($only_reduc?'1':'0').'-'.($use_reduc?'1':'0').'-'.$with_ecotax;
|
||||
|
||||
if (isset(self::$_prices[$cacheId]))
|
||||
return self::$_prices[$cacheId];
|
||||
@@ -1658,14 +1672,14 @@ class ProductCore extends ObjectModel
|
||||
$cacheId2 = $id_product.'-'.$id_product_attribute;
|
||||
if (!isset(self::$_pricesLevel2[$cacheId2]))
|
||||
self::$_pricesLevel2[$cacheId2] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT p.`price`, p.`ecotax`,
|
||||
'.($id_product_attribute ? 'pa.`price`' : 'IFNULL((SELECT pa.price FROM `'._DB_PREFIX_.'product_attribute` pa WHERE id_product = '.(int)($id_product).' AND default_on = 1), 0)').' AS attribute_price
|
||||
SELECT p.`price`,
|
||||
'.($id_product_attribute ? 'pa.`price`' : 'IFNULL((SELECT pa.price FROM `'._DB_PREFIX_.'product_attribute` pa WHERE id_product = '.(int)($id_product).' AND default_on = 1), 0)').' AS attribute_price,
|
||||
'.($id_product_attribute ? 'pa.`ecotax`' : 'p.`ecotax`').'
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.($id_product_attribute ? 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON pa.`id_product_attribute` = '.(int)($id_product_attribute) : '').'
|
||||
WHERE p.`id_product` = '.(int)($id_product));
|
||||
$result = self::$_pricesLevel2[$cacheId2];
|
||||
|
||||
|
||||
// Cache for specific prices
|
||||
$cacheId3 = $id_product.'-'.$id_shop.'-'.$id_currency.'-'.$id_country.'-'.$id_group.'-'.$quantity;
|
||||
|
||||
@@ -2310,12 +2324,12 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public static function duplicateTags($id_product_old, $id_product_new)
|
||||
{
|
||||
$resource = Db::getInstance()->ExecuteS('SELECT `id_tag` FROM `'._DB_PREFIX_.'product_tag` WHERE `id_product` = '.(int)($id_product_old));
|
||||
$tags = Db::getInstance()->ExecuteS('SELECT `id_tag` FROM `'._DB_PREFIX_.'product_tag` WHERE `id_product` = '.(int)($id_product_old));
|
||||
if (!Db::getInstance()->NumRows())
|
||||
return true;
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_tag` (`id_product`, `id_tag`) VALUES';
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
$query .= ' ('.(int)($id_product_new).', '.(int)($row['id_tag']).'),';
|
||||
foreach($tags as $tag)
|
||||
$query .= ' ('.(int)($id_product_new).', '.(int)($tag['id_tag']).'),';
|
||||
$query = rtrim($query, ',');
|
||||
return Db::getInstance()->Execute($query);
|
||||
}
|
||||
|
||||
+15
-4
@@ -185,9 +185,20 @@ class StateCore extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
public static function hasCounties($id_state)
|
||||
{
|
||||
return sizeof(County::getCounties((int)$id_state));
|
||||
}
|
||||
public static function hasCounties($id_state)
|
||||
{
|
||||
return sizeof(County::getCounties((int)$id_state));
|
||||
}
|
||||
|
||||
public static function getIdZone($id_state)
|
||||
{
|
||||
if (!Validate::isUnsignedId($id_state))
|
||||
die(Tools::displayError());
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `id_zone`
|
||||
FROM `'._DB_PREFIX_.'state`
|
||||
WHERE `id_state` = '.(int)($id_state));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ class ValidateCore
|
||||
|
||||
static public function isStateIsoCode($isoCode)
|
||||
{
|
||||
return preg_match('/^[a-z0-9]{2}((-)[a-z0-9]{1,3})?$/ui', $isoCode);
|
||||
return preg_match('/^[a-z0-9]{2,3}((-)[a-z0-9]{1,3})?$/ui', $isoCode);
|
||||
}
|
||||
|
||||
static public function isNumericIsoCode($isoCode)
|
||||
|
||||
Reference in New Issue
Block a user