// Merge with revision 7841
This commit is contained in:
+32
-1
@@ -399,7 +399,38 @@ class CarrierCore extends ObjectModel
|
||||
return $carriers;
|
||||
}
|
||||
|
||||
public static function getCarriersForOrder($id_zone, $groups = NULL, Cart $cart = null, $id_currency = null, $id_lang = null)
|
||||
public static function getDeliveredCountries($id_lang, $activeCountries = false, $activeCarriers = false, $containStates = NULL)
|
||||
{
|
||||
if (!Validate::isBool($activeCountries) OR !Validate::isBool($activeCarriers))
|
||||
die(Tools::displayError());
|
||||
|
||||
$states = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT s.*
|
||||
FROM `'._DB_PREFIX_.'state` s
|
||||
ORDER BY s.`name` ASC');
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT cl.*,c.*, cl.`name` AS country, zz.`name` AS zone FROM `'._DB_PREFIX_.'country` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (c.`id_country` = cl.`id_country` AND cl.`id_lang` = 1)
|
||||
INNER JOIN (`'._DB_PREFIX_.'carrier_zone` cz INNER JOIN `'._DB_PREFIX_.'carrier` cr ON ( cr.id_carrier = cz.id_carrier AND cr.deleted = 0 '.($activeCarriers ?
|
||||
'AND cr.active = 1) ' : ') ').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'zone` zz ON cz.id_zone = zz.id_zone) ON zz.`id_zone` = c.`id_zone`
|
||||
WHERE 1
|
||||
'.($activeCountries ? 'AND c.active = 1' : '').'
|
||||
'.(!is_null($containStates) ? 'AND c.`contains_states` = '.(int)($containStates) : '').'
|
||||
ORDER BY cl.name ASC');
|
||||
|
||||
$countries = array();
|
||||
foreach ($result AS &$country)
|
||||
$countries[$country['id_country']] = $country;
|
||||
foreach ($states AS &$state)
|
||||
if (isset($countries[$state['id_country']])) /* Does not keep the state if its country has been disabled and not selected */
|
||||
$countries[$state['id_country']]['states'][] = $state;
|
||||
|
||||
return $countries;
|
||||
}
|
||||
|
||||
public static function getCarriersForOrder($id_zone, $groups = NULL)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
if (!$id_lang)
|
||||
|
||||
@@ -67,7 +67,6 @@ class FrontControllerCore
|
||||
public function __construct()
|
||||
{
|
||||
global $useSSL;
|
||||
|
||||
$useSSL = $this->ssl;
|
||||
}
|
||||
|
||||
@@ -393,8 +392,9 @@ class FrontControllerCore
|
||||
if (isset($this->php_self) AND !empty($this->php_self))
|
||||
{
|
||||
// $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain
|
||||
$canonicalURL = $this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id);
|
||||
if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/i', (($this->ssl AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))
|
||||
|
||||
$canonicalURL = $link->getPageLink($this->php_self, $this->ssl, $this->context->language->id);
|
||||
if (!Tools::getValue('ajax') && !preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/', (($this->ssl AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))
|
||||
{
|
||||
header('HTTP/1.0 301 Moved');
|
||||
$params = '';
|
||||
|
||||
@@ -538,6 +538,8 @@ class ImageCore extends ObjectModel
|
||||
if (!$image || $image->id !== (int)$matches[2])
|
||||
$image = new Image((int)$matches[2]);
|
||||
|
||||
if (Validate::isLoadedObject($image))
|
||||
{
|
||||
// create the new folder if it does not exist
|
||||
if (!$image->createImgFolder())
|
||||
return false;
|
||||
@@ -549,6 +551,7 @@ class ImageCore extends ObjectModel
|
||||
if (!@rename(_PS_PROD_IMG_DIR_.$file, $new_path) || !file_exists($new_path))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((int)$max_execution_time != 0 && (time() - $start_time > (int)$max_execution_time - 4))
|
||||
return 'timeout';
|
||||
}
|
||||
|
||||
@@ -219,6 +219,7 @@ abstract class PaymentModuleCore extends Module
|
||||
if (!empty($product['ecotax']))
|
||||
$ecotaxTaxRate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||
|
||||
$product_price = (float)Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), (Product::getTaxCalculationMethod((int)($order->id_customer)) == PS_TAX_EXC ? 2 : 6), NULL, false, false, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), $specificPrice, false);
|
||||
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $this->context->shop->getID(), (int)$cart->id_currency, (int)$vat_address->id_country, (int)$customer->id_default_group, (int)$product['cart_quantity']);
|
||||
$unitPrice = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL), 2, NULL, false, true, 1, false, (int)$order->id_customer, NULL, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
|
||||
$quantityDiscountValue = $quantityDiscount ? ((Product::getTaxCalculationMethod((int)$order->id_customer) == PS_TAX_EXC ? Tools::ps_round($unitPrice, 2) : $unitPrice) - $quantityDiscount['price'] * (1 + $tax_rate / 100)) : 0.00;
|
||||
@@ -228,7 +229,7 @@ abstract class PaymentModuleCore extends Module
|
||||
\''.pSQL($product['name'].((isset($product['attributes']) AND $product['attributes'] != NULL) ? ' - '.$product['attributes'] : '')).'\',
|
||||
'.(int)($product['cart_quantity']).',
|
||||
'.$quantityInStock.',
|
||||
'.(float)(Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), (Product::getTaxCalculationMethod((int)($order->id_customer)) == PS_TAX_EXC ? 2 : 6), NULL, false, false, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), $specificPrice, FALSE)).',
|
||||
'.$product_price.',
|
||||
'.(float)(($specificPrice AND $specificPrice['reduction_type'] == 'percentage') ? $specificPrice['reduction'] * 100 : 0.00).',
|
||||
'.(float)(($specificPrice AND $specificPrice['reduction_type'] == 'amount') ? (!$specificPrice['id_currency'] ? Tools::convertPrice($specificPrice['reduction'], $order->id_currency) : $specificPrice['reduction']) : 0.00).',
|
||||
'.(float)(Group::getReduction((int)($order->id_customer))).',
|
||||
|
||||
+24
-18
@@ -243,7 +243,7 @@ class ProductCore extends ObjectModel
|
||||
'cache_has_attachments' => 'isBool'
|
||||
);
|
||||
protected $fieldsRequiredLang = array('link_rewrite', 'name');
|
||||
/* Description short is limited to 400 chars, but without html, so it can't be generic */
|
||||
/* Description short is limited to 400 chars (but can be configured in Preferences Tab), but without html, so it can't be generic */
|
||||
protected $fieldsSizeLang = array('meta_description' => 255, 'meta_keywords' => 255,
|
||||
'meta_title' => 128, 'link_rewrite' => 128, 'name' => 128, 'available_now' => 255, 'available_later' => 255);
|
||||
protected $fieldsValidateLang = array(
|
||||
@@ -550,13 +550,16 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public function validateFieldsLang($die = true, $errorReturn = false)
|
||||
{
|
||||
$limit = (int)Configuration::get('PS_PRODUCT_SHORT_DESC_LIMIT');
|
||||
if ($limit <= 0)
|
||||
$limit = 400;
|
||||
if (!is_array($this->description_short))
|
||||
$this->description_short = array();
|
||||
foreach ($this->description_short as $k => $value)
|
||||
if (Tools::strlen(strip_tags($value)) > 400)
|
||||
if (Tools::strlen(strip_tags($value)) > $limit)
|
||||
{
|
||||
if ($die) die (Tools::displayError().' ('.get_class($this).'->description: length > 400 for language '.$k.')');
|
||||
return $errorReturn ? get_class($this).'->'.Tools::displayError('description: length > 400 for language').' '.$k : false;
|
||||
if ($die) die (Tools::displayError().' ('.get_class($this).'->description: length > '.$limit.' for language '.$k.')');
|
||||
return $errorReturn ? get_class($this).'->'.Tools::displayError('description: length >').' '.$limit.' '.Tools::displayError('for language').' '.$k : false;
|
||||
}
|
||||
return parent::validateFieldsLang($die, $errorReturn);
|
||||
}
|
||||
@@ -1635,8 +1638,7 @@ class ProductCore extends ObjectModel
|
||||
* @return float Product price
|
||||
*/
|
||||
public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = NULL, $decimals = 6, $divisor = NULL, $only_reduc = false,
|
||||
$usereduc = true, $quantity = 1, $forceAssociatedTax = false, $id_customer = NULL, $id_cart = NULL, $id_address = NULL, &$specificPriceOutput = NULL,
|
||||
$with_ecotax = TRUE, Context $context = null)
|
||||
$usereduc = true, $quantity = 1, $forceAssociatedTax = false, $id_customer = NULL, $id_cart = NULL, $id_address = NULL, &$specificPriceOutput = NULL, $with_ecotax = true, $use_groupReduction = true, Context $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
@@ -1711,7 +1713,7 @@ class ProductCore extends ObjectModel
|
||||
$usetax = false;
|
||||
|
||||
return Product::priceCalculation($context->shop->getID(), $id_product, $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity, $usetax, $decimals, $only_reduc,
|
||||
$usereduc, $with_ecotax, $specificPriceOutput);
|
||||
$usereduc, $with_ecotax, $specificPriceOutput, $use_groupReduction);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1733,7 +1735,7 @@ class ProductCore extends ObjectModel
|
||||
* @param variable_reference $specific_price_output If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object
|
||||
* @return float Product price
|
||||
**/
|
||||
public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price)
|
||||
public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_groupReduction)
|
||||
{
|
||||
// Caching
|
||||
if ($id_product_attribute === NULL)
|
||||
@@ -1803,13 +1805,15 @@ class ProductCore extends ObjectModel
|
||||
$price -= $reduc;
|
||||
|
||||
// Group reduction
|
||||
if ($use_groupReduction)
|
||||
{
|
||||
if ($reductionFromCategory = (float)(GroupReduction::getValueForProduct($id_product, $id_group)))
|
||||
$price -= $price * $reductionFromCategory;
|
||||
else // apply group reduction if there is no group reduction for this category
|
||||
$price *= ((100 - Group::getReductionByIdGroup($id_group)) / 100);
|
||||
}
|
||||
|
||||
$price = Tools::ps_round($price, $decimals);
|
||||
|
||||
// Eco Tax
|
||||
if (($result['ecotax'] OR isset($result['attribute_ecotax'])) AND $with_ecotax)
|
||||
{
|
||||
@@ -3066,22 +3070,21 @@ class ProductCore extends ObjectModel
|
||||
public function checkAccess($id_customer)
|
||||
{
|
||||
if (!$id_customer)
|
||||
{
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT ctg.`id_group`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
|
||||
WHERE cp.`id_product` = '.(int)$this->id.' AND ctg.`id_group` = 1');
|
||||
} else {
|
||||
else
|
||||
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT cg.`id_group`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
INNER JOIN `'._DB_PREFIX_.'category_group` ctg ON (ctg.`id_category` = cp.`id_category`)
|
||||
INNER JOIN `'._DB_PREFIX_.'customer_group` cg ON (cg.`id_group` = ctg.`id_group`)
|
||||
WHERE cp.`id_product` = '.(int)$this->id.' AND cg.`id_customer` = '.(int)$id_customer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a stock movement for current product
|
||||
*
|
||||
@@ -3092,7 +3095,7 @@ class ProductCore extends ObjectModel
|
||||
* @param int $id_employee
|
||||
* @return bool
|
||||
*/
|
||||
public function addStockMvt($quantity, $id_reason, $id_product_attribute = NULL, $id_order = NULL, $id_employee = NULL)
|
||||
public function addStockMvt($quantity, $id_reason, $id_product_attribute = null, $id_order = null, $id_employee = null)
|
||||
{
|
||||
if (!$this->id)
|
||||
return;
|
||||
@@ -3114,12 +3117,15 @@ class ProductCore extends ObjectModel
|
||||
$stockMvt->id_employee = (int)$id_employee;
|
||||
$stockMvt->quantity = $quantity;
|
||||
$stockMvt->id_stock_mvt_reason = (int)$id_reason;
|
||||
$result = $stockMvt->add();
|
||||
|
||||
// @hook updateQuantity
|
||||
Hook::updateQuantity($this, null);
|
||||
|
||||
return $result;
|
||||
// adding stock mouvement, this action update the stock of product in database only
|
||||
if ($stockMvt->add())
|
||||
{
|
||||
$this->quantity = $this->getStock();
|
||||
Hook::updateQuantity($this, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getStockMvts($id_lang)
|
||||
|
||||
Reference in New Issue
Block a user