[+] BO : add new feature, Order edition

This commit is contained in:
dMetzger
2011-11-23 17:45:52 +00:00
parent f5de69ad84
commit d902a38ec8
31 changed files with 3349 additions and 846 deletions
+2 -1
View File
@@ -918,6 +918,8 @@ class AdminControllerCore extends Controller
'desc' => $this->l('Save')
);
break;
case 'view':
break;
default: // list
$this->toolbar_btn['new'] = array(
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
@@ -1849,7 +1851,6 @@ class AdminControllerCore extends Controller
if (empty($order_by))
$order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
if (empty($order_way))
$order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
+80 -79
View File
@@ -75,9 +75,9 @@ class CartCore extends ObjectModel
public $checkedTos = false;
public $pictures;
public $textFields;
public $delivery_option;
/** @var boolean Allow to seperate order in multiple package in order to recieve as soon as possible the available products */
public $allow_seperated_package = false;
@@ -257,6 +257,7 @@ class CartCore extends ObjectModel
/**
* @deprecated 1.5.0.1
* @see Cart::getCartRules()
*/
public function getDiscounts($lite = false, $refresh = false)
{
@@ -691,7 +692,7 @@ class CartCore extends ObjectModel
$context = Context::getContext()->cloneContext();
$context->cart = $this;
CartRule::autoAddToCart($context);
if ($product->customizable)
return $this->_updateCustomizationQuantity((int)$quantity, (int)$id_customization, (int)$id_product, (int)$id_product_attribute, $operator);
else
@@ -983,7 +984,7 @@ class CartCore extends ObjectModel
return 0;
if ($virtual AND $type == Cart::BOTH)
$type = Cart::BOTH_WITHOUT_SHIPPING;
if ($type != Cart::BOTH_WITHOUT_SHIPPING AND $type != Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)
{
if (is_null($products) && is_null($id_carrier))
@@ -993,13 +994,13 @@ class CartCore extends ObjectModel
}
else
$shipping_fees = 0;
if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING)
$type = Cart::ONLY_PRODUCTS;
if (is_null($products))
$products = $this->getProducts();
$order_total = 0;
if (Tax::excludeTaxeOption())
$withTaxes = false;
@@ -1068,10 +1069,10 @@ class CartCore extends ObjectModel
return $order_total_discount;
return Tools::ps_round((float)$order_total, 2);
}
/**
* Get products grouped by package and by addresses to be sent individualy (one package = one shipping cost).
*
*
* @return array array(
* 0 => array( // First address
* 0 => array( // First package
@@ -1095,15 +1096,15 @@ class CartCore extends ObjectModel
{
if (!isset($warehouse_count_by_address[$product['id_address_delivery']]))
$warehouse_count_by_address[$product['id_address_delivery']] = array();
$product['warehouse_list'] = array();
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
// Does the product is in stock ?
// If yes, get only warehouse where the product is in stock
$warehouse_in_stock = array();
$manager = StockManagerFactory::getManager();
foreach ($warehouse_list as $key => $warehouse)
{
if ($manager->getProductRealQuantities(
@@ -1121,7 +1122,7 @@ class CartCore extends ObjectModel
}
else
$product['in_stock'] = false;
foreach ($warehouse_list as $warehouse)
{
if (!isset($warehouse_carrier_list[$warehouse['id_warehouse']]))
@@ -1129,21 +1130,21 @@ class CartCore extends ObjectModel
$warehouse_object = new Warehouse($warehouse['id_warehouse']);
$warehouse_carrier_list[$warehouse['id_warehouse']] = $warehouse_object->getCarriers();
}
$product['warehouse_list'][] = $warehouse['id_warehouse'];
if (!isset($warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]))
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']] = 0;
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]++;
}
}
// If product from the cart are not in any warehouse, return false
//foreach ($warehouse_count_by_address as $warehouse_count)
// if (empty($warehouse_count))
// return false;
arsort($warehouse_count_by_address);
// Step 2 : Group product by warehouse
$grouped_by_warehouse = array();
foreach ($product_list as &$product)
@@ -1153,32 +1154,32 @@ class CartCore extends ObjectModel
'in_stock' => array(),
'out_of_stock' => array(),
);
// Determine the warehouse to use for this product in order to reduce the number of package
$id_warehouse = 0;
foreach ($warehouse_count_by_address[$product['id_address_delivery']] as $id_warehouse)
if (in_array($id_warehouse, $product['warehouse_list']))
break;
if (!isset($grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse]))
{
$grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse] = array();
$grouped_by_warehouse[$product['id_address_delivery']]['out_of_stock'][$id_warehouse] = array();
}
if (!$this->allow_seperated_package)
$key = 'in_stock';
else
$key = ($product['in_stock']) ? 'in_stock' : 'out_of_stock';
$product['carrier_list'] = Carrier::getAvailableCarrierList($product, $id_warehouse);
if (empty($product['carrier_list']))
$product['carrier_list'] = array(0);
$grouped_by_warehouse[$product['id_address_delivery']][$key][$id_warehouse][] = $product;
}
// Step 3 : grouped product from grouped_by_warehouse by available carriers
$grouped_by_carriers = array();
foreach ($grouped_by_warehouse as $id_address_delivery => $products_in_stock_list)
@@ -1188,7 +1189,7 @@ class CartCore extends ObjectModel
'in_stock' => array(),
'out_of_stock' => array(),
);
foreach ($products_in_stock_list as $key => $warehouse_list)
{
if (!isset($grouped_by_carriers[$id_address_delivery][$key]))
@@ -1197,23 +1198,23 @@ class CartCore extends ObjectModel
{
if (!isset($grouped_by_carriers[$id_address_delivery][$key][$id_warehouse]))
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse] = array();
foreach ($product_list as $product)
{
$package_carriers_key = implode(',', $product['carrier_list']);
if (!isset($grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key]))
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key] = array(
'product_list' => array(),
'carrier_list' => $product['carrier_list']
);
$grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key]['product_list'][] = $product;
}
}
}
}
$package_list = array();
// Step 4 : merge product from grouped_by_carriers into $package to minimize the number of package
foreach ($grouped_by_carriers as $id_address_delivery => $products_in_stock_list)
@@ -1223,8 +1224,8 @@ class CartCore extends ObjectModel
'in_stock' => array(),
'out_of_stock' => array(),
);
foreach ($products_in_stock_list as $key => $warehouse_list)
{
if (!isset($package_list[$id_address_delivery][$key]))
@@ -1242,7 +1243,7 @@ class CartCore extends ObjectModel
}
}
arsort($carrier_count);
foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers)
{
if (!isset($package_list[$id_address_delivery][$key][$id_warehouse]))
@@ -1269,14 +1270,14 @@ class CartCore extends ObjectModel
}
}
}
// Step 5 : Reduce deep of $package_list
$final_package_list = array();
foreach ($package_list as $id_address_delivery => $products_in_stock_list)
{
if (!isset($final_package_list[$id_address_delivery]))
$final_package_list[$id_address_delivery] = array();
foreach ($products_in_stock_list as $key => $warehouse_list)
foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers)
foreach ($products_grouped_by_carriers as $data)
@@ -1288,11 +1289,11 @@ class CartCore extends ObjectModel
}
return $final_package_list;
}
/**
* Get all deliveries options available for the current cart
* @param Country $default_country
*
*
* @return array array(
* 0 => array( // First address
* 0 => array( // First delivery option available for this address
@@ -1326,7 +1327,7 @@ class CartCore extends ObjectModel
{
$delivery_option_list[$id_address] = array();
$carriers_price[$id_address] = array();
$common_carriers = array();
$best_price_carriers = array();
$best_grade_carriers = array();
@@ -1335,10 +1336,10 @@ class CartCore extends ObjectModel
// No carriers available
if (count($package['carrier_list']) == 1 && current($package['carrier_list']) == 0)
return array();
$carriers_price[$id_address][$id_package] = array();
$carriers_instance = array();
if (empty($common_carriers))
$common_carriers = $package['carrier_list'];
else
@@ -1361,19 +1362,19 @@ class CartCore extends ObjectModel
$carriers_price[$id_address][$id_package][$id_carrier] = array(
'without_tax' => $price_without_tax,
'with_tax' => $price_with_tax);
$grade = $carriers_instance[$id_carrier]->grade;
if (is_null($best_grade) || $grade > $best_grade)
{
$best_grade = $grade;
$best_grade_carrier = $id_carrier;
}
}
$best_price_carriers[$id_package] = $best_price_carrier;
$best_grade_carriers[$id_package] = $best_grade_carrier;
}
$best_price_carrier = array();
$key = '';
foreach ($best_price_carriers as $id_package => $id_carrier)
@@ -1396,7 +1397,7 @@ class CartCore extends ObjectModel
'is_best_grade' => false,
'unique_carrier' => false
);
$best_grade_carrier = array();
$key = '';
foreach ($best_grade_carriers as $id_package => $id_carrier)
@@ -1420,7 +1421,7 @@ class CartCore extends ObjectModel
'unique_carrier' => false
);
$delivery_option_list[$id_address][$key]['is_best_grade'] = true;
foreach ($common_carriers as $id_carrier)
{
$price = 0;
@@ -1463,11 +1464,11 @@ class CartCore extends ObjectModel
{
$total_price_with_tax += $data['price_with_tax'];
$total_price_without_tax += $data['price_without_tax'];
if (!isset($carrier_collection[$id_carrier]))
$carrier_collection[$id_carrier] = new Carrier($id_carrier);
$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['instance'] = $carrier_collection[$id_carrier];
if (file_exists(_PS_SHIP_IMG_DIR_.$id_carrier.'.jpg'))
$delivery_option_list[$id_address][$key]['carrier_list'][$id_carrier]['logo'] = _THEME_SHIP_DIR_.$id_carrier.'.jpg';
else
@@ -1479,7 +1480,7 @@ class CartCore extends ObjectModel
}
return $delivery_option_list;
}
/**
* Does the cart use multiple
*/
@@ -1507,7 +1508,7 @@ class CartCore extends ObjectModel
$collection[$row['id_address_delivery']] = new Address($row['id_address_delivery']);
return $collection;
}
/**
* Set the delivery option and id_carrier, if there is only one carrier
*/
@@ -1569,7 +1570,7 @@ class CartCore extends ObjectModel
{
if (is_null($delivery_option))
$delivery_option = $this->getDeliveryOption($default_country);
$total_shipping = 0;
$delivery_option_list = $this->getDeliveryOptionList();
foreach ($delivery_option as $id_address => $key)
@@ -1595,14 +1596,14 @@ class CartCore extends ObjectModel
* @param Array $product_list
* @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
* @deprecated since 1.5.0
*
*
* @return float Shipping total
*/
public function getOrderShippingCost($id_carrier = null, $useTax = true, Country $default_country = null, $product_list = null)
{
return $this->getPackageShippingCost($id_carrier, $useTax, $default_country, $product_list);
}
/**
* Return package shipping cost
*
@@ -1611,7 +1612,7 @@ class CartCore extends ObjectModel
* @param Country $default_country
* @param Array $product_list
* @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
*
*
* @return float Shipping total
*/
public function getPackageShippingCost($id_carrier = null, $useTax = true, Country $default_country = null, $product_list = null)
@@ -1627,7 +1628,7 @@ class CartCore extends ObjectModel
$products = $complete_product_list;
else
$products = $product_list;
// Checking discounts in cart
// if (Discount::isFeatureActive())
// $discounts = $this->getDiscounts(true);
@@ -1864,7 +1865,7 @@ class CartCore extends ObjectModel
}
return $total_weight;
}
if (!isset(self::$_totalWeight[$this->id]))
{
if (Combination::isFeatureActive())
@@ -2192,16 +2193,16 @@ class CartCore extends ObjectModel
}
return true;
}
public function setProductAddressDelivery($id_product, $id_product_attribute, $old_id_address_delivery, $new_id_address_delivery)
{
// Check address is linked with the customer
if (!Customer::customerHasAddress(Context::getContext()->customer->id, $new_id_address_delivery))
return false;
if ($new_id_address_delivery == $old_id_address_delivery)
return false;
// Checking if the product with the old address delivery exists
$sql = new DbQuery();
$sql->select('count(*)');
@@ -2213,7 +2214,7 @@ class CartCore extends ObjectModel
$result = Db::getInstance()->getValue($sql);
if ($result == 0)
return false;
// Checking if there is no others similar products with this new address delivery
$sql = new DbQuery();
$sql->select('sum(quantity) as qty');
@@ -2223,7 +2224,7 @@ class CartCore extends ObjectModel
$sql->where('id_address_delivery = '.(int)$new_id_address_delivery);
$sql->where('id_cart = '.(int)$this->id);
$result = Db::getInstance()->getValue($sql);
// Removing similar products with this new address delivery
$sql = 'DELETE FROM '._DB_PREFIX_.'cart_product
WHERE id_product = '.(int)$id_product.'
@@ -2232,7 +2233,7 @@ class CartCore extends ObjectModel
AND id_cart = '.(int)$this->id.'
LIMIT 1';
Db::getInstance()->execute($sql);
// Changing the address
$sql = 'UPDATE '._DB_PREFIX_.'cart_product
SET `id_address_delivery` = '.(int)$new_id_address_delivery.',
@@ -2243,7 +2244,7 @@ class CartCore extends ObjectModel
AND id_cart = '.(int)$this->id.'
LIMIT 1';
Db::getInstance()->execute($sql);
// Changing the address of the customizations
$sql = 'UPDATE '._DB_PREFIX_.'customization
SET `id_address_delivery` = '.(int)$new_id_address_delivery.'
@@ -2252,16 +2253,16 @@ class CartCore extends ObjectModel
AND id_address_delivery = '.(int)$old_id_address_delivery.'
AND id_cart = '.(int)$this->id;
Db::getInstance()->execute($sql);
return true;
}
public function duplicateProduct($id_product, $id_product_attribute, $id_address_delivery, $new_id_address_delivery, $quantity = 1, $keep_quantity = false)
{
// Check address is linked with the customer
if (!Customer::customerHasAddress(Context::getContext()->customer->id, $new_id_address_delivery))
return false;
// Checking the product do not exist with the new address
$sql = new DbQuery();
$sql->select('count(*)');
@@ -2273,7 +2274,7 @@ class CartCore extends ObjectModel
$result = Db::getInstance()->getValue($sql);
if ($result > 0)
return false;
// Duplicating cart_product line
$sql = 'INSERT INTO '._DB_PREFIX_.'cart_product
(`id_cart`, `id_product`, `id_shop`, `id_product_attribute`, `quantity`, `date_add`, `id_address_delivery`)
@@ -2286,7 +2287,7 @@ class CartCore extends ObjectModel
NOW(),
'.(int)$new_id_address_delivery.')';
Db::getInstance()->execute($sql);
if (!$keep_quantity)
{
$sql = 'UPDATE '._DB_PREFIX_.'cart_product
@@ -2298,7 +2299,7 @@ class CartCore extends ObjectModel
AND id_address_delivery = '.(int)$id_address_delivery;
Db::getInstance()->execute($sql);
}
// Checking if there is customizations
$sql = new DbQuery();
$sql->select('*');
@@ -2311,7 +2312,7 @@ class CartCore extends ObjectModel
foreach ($results as $customization)
{
// Duplicate customization
$sql = 'INSERT INTO '._DB_PREFIX_.'customization(`id_product_attribute`, `id_address_delivery`, `id_cart`, `id_product`, `quantity`, `in_cart`)
VALUES (
@@ -2322,12 +2323,12 @@ class CartCore extends ObjectModel
'.$quantity.',
'.$customization['in_cart'].')';
Db::getInstance()->execute($sql);
$sql = 'INSERT INTO '._DB_PREFIX_.'customized_data(`id_customization`, `type`, `index`, `value`)
(SELECT '.(int)Db::getInstance()->Insert_ID().' `id_customization`, `type`, `index`, `value` FROM customized_data WHERE id_customization = '.$customization['id_customization'].')';
Db::getInstance()->execute($sql);
}
$customization_count = count($results);
if ($customization_count > 0)
{
@@ -2342,7 +2343,7 @@ class CartCore extends ObjectModel
}
return true;
}
/**
* Update products cart address delivery with the address delivery of the cart
*/
@@ -2365,7 +2366,7 @@ class CartCore extends ObjectModel
AND id_product_attribute = '.$product['id_product_attribute'];
Db::getInstance()->execute($sql);
}
// Merging multiple lines
$sql = 'DELETE cp1
FROM `'._DB_PREFIX_.'cart_product` cp1
@@ -2378,8 +2379,8 @@ class CartCore extends ObjectModel
AND (cp1.date_add > cp2.date_add)
)';
Db::getInstance()->execute($sql);
// upgradng address delivery
$sql = 'UPDATE `'._DB_PREFIX_.'cart_product`
SET `id_address_delivery` =
@@ -2402,7 +2403,7 @@ class CartCore extends ObjectModel
WHERE `id_cart` = '.(int)$this->id;
Db::getInstance()->execute($sql);
}
/**
* Set an address to all products on the cart without address delivery
*/
@@ -2415,17 +2416,17 @@ class CartCore extends ObjectModel
{
if ((int)$cart->id_customer == 0)
return;
$customer = new Customer((int)$cart->id_customer);
$addresses = $customer->getAddresses(Context::getContext()->language->id);
if (count($addresses) == 0)
return;
$id_address_delivery = $addresses[0]['id_address'];
}
// Update
// Update
$sql = 'UPDATE `'._DB_PREFIX_.'cart_product`
SET `id_address_delivery` =
(
+44 -43
View File
@@ -59,7 +59,7 @@ class CartRuleCore extends ObjectModel
protected $table = 'cart_rule';
protected $identifier = 'id_cart_rule';
protected $fieldsRequired = array('date_from', 'date_to');
protected $fieldsSize = array('code' => 254, 'description' => 65534);
protected $fieldsValidate = array(
@@ -134,16 +134,16 @@ class CartRuleCore extends ObjectModel
return false;
return $this->getTranslationsFields(array('name'));
}
public function add($autodate = true, $nullValues = false)
{
if (!parent::add($autodate, $nullValues))
return false;
Configuration::updateGlobalValue('PS_CART_RULE_FEATURE_ACTIVE', '1');
return true;
}
public function delete()
{
if (!parent::delete())
@@ -158,7 +158,7 @@ class CartRuleCore extends ObjectModel
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule` WHERE `id_cart_rule` = '.(int)$this->id);
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule_value` WHERE `id_product_rule` NOT IN (SELECT `id_product_rule` FROM `'._DB_PREFIX_.'cart_rule_product_rule`)');
}
public static function copyConditions($id_cart_rule_source, $id_cart_rule_destination)
{
Db::getInstance()->Execute('
@@ -186,7 +186,7 @@ class CartRuleCore extends ObjectModel
return false;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_cart_rule` FROM `'._DB_PREFIX_.'cart_rule` WHERE `code` = \''.pSQL($code).'\'');
}
public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null)
{
if (!CartRule::isFeatureActive())
@@ -219,7 +219,7 @@ class CartRuleCore extends ObjectModel
}
return $result;
}
public function usedByCustomer($id_customer)
{
return (bool)Db::getInstance()->getValue('
@@ -229,7 +229,7 @@ class CartRuleCore extends ObjectModel
WHERE ocr.`id_cart_rule` = '.(int)$this->id.'
AND o.`id_customer` = '.(int)$id_customer);
}
public static function cartRuleExists($name)
{
if (!CartRule::isFeatureActive())
@@ -240,7 +240,7 @@ class CartRuleCore extends ObjectModel
FROM `'._DB_PREFIX_.'cart_rule`
WHERE `code` = \''.pSQL($name).'\'');
}
public static function deleteByIdCustomer($id_customer)
{
$return = true;
@@ -255,7 +255,7 @@ class CartRuleCore extends ObjectModel
{
if (!Validate::isLoadedObject($this) OR $this->product_restriction == 0)
return array();
$productRules = array();
$result = Db::getInstance()->ExecuteS('
SELECT *
@@ -270,13 +270,13 @@ class CartRuleCore extends ObjectModel
}
return $productRules;
}
// Todo : Add shop management
public function checkValidity(Context $context, $alreadyInCart = false)
{
if (!CartRule::isFeatureActive())
return false;
if (!$this->active)
return Tools::displayError('This voucher is disabled');
if (!$this->quantity)
@@ -285,7 +285,7 @@ class CartRuleCore extends ObjectModel
return Tools::displayError('This voucher is not valid yet');
if (strtotime($this->date_to) < time())
return Tools::displayError('This voucher has expired');
if ($context->cart->id_customer)
{
$quantityUsed = Db::getInstance()->getValue('
@@ -304,7 +304,7 @@ class CartRuleCore extends ObjectModel
if ($quantityUsed + 1 > $this->quantity_per_user)
return Tools::displayError('You cannot use this voucher anymore (usage limit reached)');
}
$otherCartRules = $context->cart->getCartRules();
if (count($otherCartRules))
foreach ($otherCartRules as $otherCartRule)
@@ -325,7 +325,7 @@ class CartRuleCore extends ObjectModel
}
}
}
// Get an intersection of the customer groups and the cart rule groups (if the customer is not logged in, the default group is 1)
if ($this->group_restriction)
{
@@ -337,7 +337,7 @@ class CartRuleCore extends ObjectModel
if (!$id_cart_rule)
return Tools::displayError('You cannot use this voucher');
}
// Check if the customer delivery address is usable with the cart rule
if ($this->country_restriction AND $context->cart->id_address_delivery)
{
@@ -349,7 +349,7 @@ class CartRuleCore extends ObjectModel
if (!$id_cart_rule)
return Tools::displayError('You cannot use this voucher in your country of delivery');
}
// Check if the carrier chosen by the customer is usable with the cart rule
if ($this->carrier_restriction AND $context->cart->id_carrier)
{
@@ -361,7 +361,7 @@ class CartRuleCore extends ObjectModel
if (!$id_cart_rule)
return Tools::displayError('You cannot use this voucher with this carrier');
}
// Check if the products chosen by the customer are usable with the cart rule
if ($this->product_restriction)
{
@@ -420,13 +420,14 @@ class CartRuleCore extends ObjectModel
return Tools::displayError('You cannot use this voucher').' - '.Tools::displayError('Please log in');
return Tools::displayError('You cannot use this voucher');
}
if ($this->minimum_amount)
{
$minimum_amount = $this->minimum_amount;
if ($this->minimum_amount_currency != Configuration::get('PS_CURRENCY_DEFAULT'))
{
$minimumAmountCurrency = new Currency($this->minimum_amount);
$minimumAmountCurrency = new Currency($this->minimum_amount_currency);
//p($this->minimum_amount_currency);
$minimum_amount = $this->minimum_amount / $minimumAmountCurrency->convertion_rate;
}
$cartTotal = $context->cart->getOrderTotal($this->minimum_amount_tax, Cart::ONLY_PRODUCTS);
@@ -436,7 +437,7 @@ class CartRuleCore extends ObjectModel
return Tools::displayError('You do not reach the minimum amount required to use this voucher');
}
}
// The reduction value is POSITIVE
public function getContextualValue($useTax, Context $context = NULL)
{
@@ -444,9 +445,9 @@ class CartRuleCore extends ObjectModel
return 0;
if (!$context)
$context = Context::getContext();
$reductionValue = 0;
// Free shipping on selected carriers
if ($this->free_shipping)
{
@@ -463,13 +464,13 @@ class CartRuleCore extends ObjectModel
$reductionValue += $context->cart->getOrderShippingCost($context->cart->id_carrier, $useTax, $context->country);
}
}
// Discount (%) on the whole order
if ($this->reduction_percent AND $this->reduction_product == 0)
{
$reductionValue += $context->cart->getOrderTotal($useTax, Cart::ONLY_PRODUCTS) * $this->reduction_percent / 100;
}
// Discount (%) on a specific product
if ($this->reduction_percent AND $this->reduction_product > 0)
{
@@ -477,7 +478,7 @@ class CartRuleCore extends ObjectModel
if ($product['id_product'] == $this->reduction_product)
$reductionValue += ($useTax ? $product['total_wt'] : $product['total']) * $this->reduction_percent / 100;
}
// Discount (%) on the cheapest product
if ($this->reduction_percent AND $this->reduction_product == -1)
{
@@ -490,7 +491,7 @@ class CartRuleCore extends ObjectModel
$reductionValue += $minPrice * $this->reduction_percent / 100;
}
}
// Discount (¤)
if ($this->reduction_amount)
{
@@ -503,10 +504,10 @@ class CartRuleCore extends ObjectModel
$reduction_amount /= $voucherCurrency->conversion_rate;
// Then we convert the voucher value in the default currency into the cart currency
$reduction_amount *= $context->currency->conversion_rate;
$reduction_amount = Tools::ps_round($reduction_amount);
}
// If it has the same tax application that you need, then it's the right value, whatever the product!
if ($this->reduction_tax == $useTax)
$reductionValue += $reduction_amount;
@@ -543,7 +544,7 @@ class CartRuleCore extends ObjectModel
// Todo: discount on the cheapest (but this is not meaningful)
}
}
// Free gift
if ($this->gift_product)
{
@@ -551,10 +552,10 @@ class CartRuleCore extends ObjectModel
if ($product['id_product'] == $this->gift_product)
$reductionValue += ($useTax ? $product['price_wt'] : $product['price']);
}
return $reductionValue;
}
protected function getCartRuleCombinations()
{
$array = array();
@@ -586,14 +587,14 @@ class CartRuleCore extends ObjectModel
)');
return $array;
}
public function getAssociatedRestrictions($type, $active = 1)
{
$array = array('selected' => array(), 'unselected' => array());
if (!in_array($type, array('country', 'carrier', 'group', 'cart_rule')))
return false;
if (!Validate::isLoadedObject($this) OR $this->{$type.'_restriction'} == 0)
{
$array['selected'] = Db::getInstance()->ExecuteS('
@@ -625,12 +626,12 @@ class CartRuleCore extends ObjectModel
}
return $array;
}
public static function autoRemoveFromCart($context = NULL)
{
if (!CartRule::isFeatureActive())
return;
$errors = array();
if (!$context)
$context = Context::getContext();
@@ -647,14 +648,14 @@ class CartRuleCore extends ObjectModel
}
return $errors;
}
public static function autoAddToCart($context = NULL)
{
if ($context === NULL)
$context = Context::getContext();
if (!CartRule::isFeatureActive() || !Validate::isLoadedObject($context->cart))
return;
$result = Db::getInstance()->ExecuteS('
SELECT cr.*
FROM '._DB_PREFIX_.'cart_rule cr
@@ -667,7 +668,7 @@ class CartRuleCore extends ObjectModel
AND cr.date_to > "'.date('Y-m-d H:i:s').'"
AND cr.id_cart_rule NOT IN (SELECT id_cart_rule FROM '._DB_PREFIX_.'cart_cart_rule WHERE id_cart = '.(int)$context->cart->id.')
AND (
cr.id_customer = 0
cr.id_customer = 0
'.($context->customer->id ? 'OR cr.id_customer = '.(int)$context->cart->id_customer : '').'
)
AND (
@@ -693,15 +694,15 @@ class CartRuleCore extends ObjectModel
)
)
ORDER BY priority');
$cartRules = ObjectModel::hydrateCollection('CartRule', $result);
// Todo: consider optimization (we can avoid many queries in checkValidity)
foreach ($cartRules as $cartRule)
if (!$cartRule->checkValidity($context))
$context->cart->addCartRule($cartRule->id);
}
public static function isFeatureActive()
{
return (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE');
+9 -9
View File
@@ -73,15 +73,15 @@ class CurrencyCore extends ObjectModel
protected $webserviceParameters = array(
'objectsNodeName' => 'currencies',
);
/**
* contains the sign to display before price, according to its format
* @var string
* @var string
*/
public $prefix = null;
/**
* contains the sign to display after price, according to its format
* @var string
* @var string
*/
public $suffix = null;
@@ -198,7 +198,7 @@ class CurrencyCore extends ObjectModel
*
* @return array Currencies
*/
static public function getCurrencies($object = false, $active = 1, Shop $shop = null)
public static function getCurrencies($object = false, $active = 1, Shop $shop = null)
{
if (!$shop)
$shop = new Shop(Context::getContext()->shop->getID(true));
@@ -216,7 +216,7 @@ class CurrencyCore extends ObjectModel
return $tab;
}
static public function getPaymentCurrenciesSpecial($id_module, $id_shop = null)
public static function getPaymentCurrenciesSpecial($id_module, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID();
@@ -228,7 +228,7 @@ class CurrencyCore extends ObjectModel
return Db::getInstance()->getRow($sql);
}
static public function getPaymentCurrencies($id_module, $id_shop = null)
public static function getPaymentCurrencies($id_module, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID();
@@ -244,7 +244,7 @@ class CurrencyCore extends ObjectModel
return Db::getInstance()->executeS($sql);
}
static public function checkPaymentCurrencies($id_module, $id_shop = null)
public static function checkPaymentCurrencies($id_module, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
@@ -275,7 +275,7 @@ class CurrencyCore extends ObjectModel
return $result['id_currency'];
}
static public function getIdByIsoCodeNum($iso_code)
public static function getIdByIsoCodeNum($iso_code)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `id_currency`
@@ -357,7 +357,7 @@ class CurrencyCore extends ObjectModel
/**
* Get current currency
*
*
* @deprecated as of 1.5 use $context->currency instead
* @return Currency
*/
+13 -9
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -25,6 +25,12 @@
* International Registered Trademark & Property of PrestaShop SA
*/
/**
*
* @deprecated 1.5.0.1
* @see OrderPaymentCore
*
*/
class PaymentCCCore extends ObjectModel
{
public $id_order;
@@ -60,7 +66,7 @@ class PaymentCCCore extends ObjectModel
$fields['date_add'] = pSQL($this->date_add);
return $fields;
}
public function add($autodate = true, $nullValues = false)
{
if (parent::add($autodate, $nullValues))
@@ -70,20 +76,18 @@ class PaymentCCCore extends ObjectModel
}
return false;
}
/**
* Get the detailed payment of an order
* @param int $id_order
* @return array
* @deprecated 1.5.0.1
* @see OrderPaymentCore
*/
public static function getByOrderId($id_order)
{
$query = '
SELECT *
FROM `'._DB_PREFIX_.'payment_cc`
WHERE `id_order` = '.$id_order;
return Db::getInstance()->getRow($query);
Tools::displayAsDeprecated();
return null;
}
}
+50 -71
View File
@@ -32,9 +32,6 @@ abstract class PaymentModuleCore extends Module
public $currencies = true;
public $currencies_mode = 'checkbox';
/* @var object PaymentCC */
public $pcc = null;
public function install()
{
if (!parent::install())
@@ -78,18 +75,6 @@ abstract class PaymentModuleCore extends Module
return false;
return parent::uninstall();
}
public function __construct()
{
$this->pcc = new PaymentCC();
parent::__construct();
}
public function __destruct()
{
unset($this->pcc);
}
/**
* Validate an order in database
@@ -101,12 +86,12 @@ abstract class PaymentModuleCore extends Module
* @param string $paymentMethod Payment method (eg. 'Credit card')
* @param string $message Message to attach to order
*/
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown',
$message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false,
public function validateOrder($id_cart, $id_order_state, $amountPaid, $paymentMethod = 'Unknown',
$message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false,
$secure_key = false, Shop $shop = null)
{
$cart = new Cart((int)($id_cart));
if (!$shop)
$shop = Context::getContext()->shop;
// Does order already exists ?
@@ -114,7 +99,7 @@ abstract class PaymentModuleCore extends Module
{
if ($secure_key !== false AND $secure_key != $cart->secure_key)
die(Tools::displayError());
// For each package, generate an order
$delivery_option_list = $cart->getDeliveryOptionList();
$package_list = $cart->getPackageList();
@@ -128,27 +113,27 @@ abstract class PaymentModuleCore extends Module
$cart_delivery_option[$id_address] = $key;
break;
}
$order_list = array();
$order_detail_list = array();
$reference = Order::generateReference();
$this->currentOrderReference = $reference;
$id_currency = $currency_special ? (int)($currency_special) : (int)($cart->id_currency);
$currency = new Currency($id_currency);
$this->context->cart->order_reference = $reference;
$orderCreationFailed = false;
$cart_total_paid = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH)), 2);
if ($cart->orderExists())
{
$errorMessage = Tools::displayError('An order has already been placed using this cart.');
Logger::addLog($errorMessage, 4, '0000001', 'Cart', intval($cart->id));
die($errorMessage);
}
foreach ($cart_delivery_option as $id_address => $key_carriers)
foreach ($delivery_option_list[$id_address][$key_carriers]['carrier_list'] as $id_carrier => $data)
foreach ($data['package_list'] as $id_package)
@@ -162,14 +147,13 @@ abstract class PaymentModuleCore extends Module
$order->id_address_delivery = (int)$id_address;
$order->id_currency = $id_currency;
$order->id_lang = (int)($cart->id_lang);
$order->id_warehouse = $package_list[$id_address][$id_package]['id_warehouse'];
$order->id_cart = (int)($cart->id);
$order->reference = $reference;
$order->id_shop = (int)($shop->getID() ? $shop->getID() : $cart->id_shop);
$order->id_group_shop = (int)($shop->getID() ? $shop->getGroupID() : $cart->id_group_shop);
$customer = new Customer((int)($order->id_customer));
$order->secure_key = ($secure_key ? pSQL($secure_key) : pSQL($customer->secure_key));
$order->payment = $paymentMethod;
@@ -191,18 +175,18 @@ abstract class PaymentModuleCore extends Module
$order->total_shipping = (float)$cart->getPackageShippingCost((int)$id_carrier, true, null, $product_list, $id_carrier);
$order->total_shipping_tax_excl = (float)$cart->getPackageShippingCost((int)$id_carrier, false, null, $product_list, $id_carrier);
$order->total_shipping_tax_incl = (float)$cart->getPackageShippingCost((int)$id_carrier, true, null, $product_list, $id_carrier);
if (Validate::isLoadedObject($carrier))
$order->carrier_tax_rate = $carrier->getTaxesRate(new Address($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$order->total_wrapping = (float)abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
$order->total_wrapping_tax_excl = (float)abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
$order->total_wrapping_tax_incl = (float)abs($cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $product_list, $id_carrier));
$order->total_paid = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier)), 2);
$order->total_paid_tax_excl = (float)Tools::ps_round((float)($cart->getOrderTotal(false, Cart::BOTH, $product_list, $id_carrier)), 2);
$order->total_paid_tax_incl = (float)Tools::ps_round((float)($cart->getOrderTotal(true, Cart::BOTH, $product_list, $id_carrier)), 2);
$order->invoice_date = '0000-00-00 00:00:00';
$order->delivery_date = '0000-00-00 00:00:00';
// Amount paid by customer is not the right one -> Status = payment error
@@ -211,18 +195,29 @@ abstract class PaymentModuleCore extends Module
// We use number_format in order to compare two string
if (number_format($cart_total_paid, 2) != number_format($order->total_paid_real, 2))
$id_order_state = Configuration::get('PS_OS_ERROR');
// Creating order
$result = $order->add();
$order_list[] = $order;
// Insert new Order detail list using cart for the current order
$order_detail = new OrderDetail(null, null, $this->context);
$order_detail->createList($order, $cart, $id_order_state, $product_list);
$order_detail_list[] = $order_detail;
// Adding an entry in order_carrier table
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'order_carrier` (`id_order`, `id_carrier`, `weight`, `shipping_cost_tax_excl`, `shipping_cost_tax_incl`, `date_add`) VALUES
('.(int)$order->id.', '.(int)$carrier->id.', '.(float)$order->getTotalWeight().', '.(float)$order->total_shipping_tax_excl.', '.(float)$order->total_shipping_tax_incl.', NOW())');
}
$this->addPCC($reference, $id_currency, $amountPaid);
// Register Payment
if (!$order->addOrderPayment($amountPaid))
{
$errorMessage = Tools::displayError('Can\'t save payment');
Logger::addLog($errorMessage, 4, '0000003', 'Order', intval($order->id));
die($errorMessage);
}
// Next !
foreach ($order_detail_list as $key => $order_detail)
@@ -249,9 +244,9 @@ abstract class PaymentModuleCore extends Module
// Insert new Order detail list using cart for the current order
//$orderDetail = new OrderDetail(null, null, $this->context);
//$orderDetail->createList($order, $cart, $id_order_state);
//$this->addPCC($order->id, $order->id_currency, $amountPaid);
// Construct order detail table for the email
$productsList = '';
$products = $cart->getProducts();
@@ -259,7 +254,7 @@ abstract class PaymentModuleCore extends Module
{
$price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$customizationQuantity = 0;
if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']]))
{
@@ -269,15 +264,15 @@ abstract class PaymentModuleCore extends Module
if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD]))
foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] AS $text)
$customizationText .= $text['name'].':'.' '.$text['value'].'<br />';
if (isset($customization['datas'][Product::CUSTOMIZE_FILE]))
$customizationText .= sizeof($customization['datas'][Product::CUSTOMIZE_FILE]) .' '. Tools::displayError('image(s)').'<br />';
$customizationText .= '---<br />';
}
$customizationText = rtrim($customizationText, '---<br />');
$customizationQuantity = (int)($product['customizationQuantityTotal']);
$productsList .=
'<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
@@ -288,7 +283,7 @@ abstract class PaymentModuleCore extends Module
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice($customizationQuantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
</tr>';
}
if (!$customizationQuantity OR (int)$product['cart_quantity'] > $customizationQuantity)
$productsList .=
'<tr style="background-color: '.($key % 2 ? '#DDE2E6' : '#EBECEE').';">
@@ -299,7 +294,7 @@ abstract class PaymentModuleCore extends Module
<td style="padding: 0.6em 0.4em; text-align: right;">'.Tools::displayPrice(((int)($product['cart_quantity']) - $customizationQuantity) * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? $price : $price_wt), $currency, false).'</td>
</tr>';
} // end foreach ($products)
$cartRulesList = '';
$result = $cart->getCartRules();
$cartRules = ObjectModel::hydrateCollection('CartRule', $result, (int)$order->id_lang);
@@ -326,19 +321,19 @@ abstract class PaymentModuleCore extends Module
Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order #').$order->id, $params, $customer->email, $customer->firstname.' '.$customer->lastname);
}
}
$order->addCartRule($cartRule->id, $cartRule->name, $value);
if ($id_order_state != Configuration::get('PS_OS_ERROR') AND $id_order_state != Configuration::get('PS_OS_CANCELED'))
$cartRule->quantity = $cartRule->quantity - 1;
$cartRule->update();
$cartRulesList .= '
<tr style="background-color:#EBECEE;">
<td colspan="4" style="padding:0.6em 0.4em;text-align:right">'.$this->l('Voucher name:').' '.$cartRule->name.'</td>
<td style="padding:0.6em 0.4em;text-align:right">'.($value != 0.00 ? '-' : '').Tools::displayPrice($value, $currency, false).'</td>
</tr>';
}
// Specify order id for message
$oldMessage = Message::getMessageByCartId((int)($cart->id));
if ($oldMessage)
@@ -347,7 +342,7 @@ abstract class PaymentModuleCore extends Module
$message->id_order = (int)$order->id;
$message->update();
}
// Hook validate order
$orderStatus = new OrderState((int)$id_order_state, (int)$order->id_lang);
if (Validate::isLoadedObject($orderStatus))
@@ -357,7 +352,7 @@ abstract class PaymentModuleCore extends Module
if ($orderStatus->logable)
ProductSale::addProductSale((int)$product['id_product'], (int)$product['cart_quantity']);
}
if (Configuration::get('PS_STOCK_MANAGEMENT') && $order_detail->getStockState())
{
$history = new OrderHistory();
@@ -373,8 +368,8 @@ abstract class PaymentModuleCore extends Module
$new_history->changeIdOrderState((int)$id_order_state, (int)$order->id);
$new_history->addWithemail(true, $extraVars);
unset($order_detail, $pcc);
unset($order_detail);
// Order is reloaded because the status just changed
$order = new Order($order->id);
@@ -385,7 +380,7 @@ abstract class PaymentModuleCore extends Module
$delivery = new Address((int)($order->id_address_delivery));
$delivery_state = $delivery->id_state ? new State((int)($delivery->id_state)) : false;
$invoice_state = $invoice->id_state ? new State((int)($invoice->id_state)) : false;
$data = array(
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
@@ -434,10 +429,10 @@ abstract class PaymentModuleCore extends Module
'{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false),
'{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false),
'{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false));
if (is_array($extraVars))
$data = array_merge($data, $extraVars);
// Join PDF invoice
if ((int)(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number)
{
@@ -447,7 +442,7 @@ abstract class PaymentModuleCore extends Module
}
else
$fileAttachment = NULL;
if (Validate::isEmail($customer->email))
Mail::Send((int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, $fileAttachment);
}
@@ -470,22 +465,6 @@ abstract class PaymentModuleCore extends Module
die($errorMessage);
}
}
/**
* Add new PaymentCC to the order
* @var int id_order
* @var int id_currency
* @var float amount
*/
private function addPCC($reference, $id_currency, $amount)
{
// Other information are set by the module
$this->pcc->order_reference = (int)$reference;
$this->pcc->id_currency = (int)$id_currency;
$this->pcc->amount = (float)$amount;
$this->pcc->add();
}
/**
* @param Object Address $the_address that needs to be txt formated
+2 -1
View File
@@ -2715,7 +2715,8 @@ class ProductCore extends ObjectModel
$resultsArray = array();
foreach ($result as $row)
{
$row['price'] = Product::getPriceStatic($row['id_product'], true, null, 2);
$row['price_tax_incl'] = Product::getPriceStatic($row['id_product'], true, null, 2);
$row['price_tax_excl'] = Product::getPriceStatic($row['id_product'], false, null, 2);
$resultsArray[] = $row;
}
return $resultsArray;
+210 -29
View File
@@ -91,13 +91,13 @@ class OrderCore extends ObjectModel
/** @var float Total to pay tax excluded */
public $total_paid_tax_excl;
/** @var float Total really paid */
/** @var float Total really paid @deprecated 1.5.0.1 */
public $total_paid_real;
/** @var float Products total */
public $total_products;
/** @var float Products total tax excluded */
/** @var float Products total tax included */
public $total_products_wt;
/** @var float Shipping total */
@@ -467,8 +467,14 @@ class OrderCore extends ObjectModel
');
}
/**
*
* @deprecated 1.5.0.1
* @see OrderInvoice::setProductPrices
*/
public function setProductPrices(&$row)
{
//Tools::displayAsDeprecated();
$tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']);
$row['tax_calculator'] = $tax_calculator;
$row['tax_rate'] = $tax_calculator->getTotalRate();
@@ -979,36 +985,50 @@ class OrderCore extends ObjectModel
return ((int)(Configuration::get('PS_ORDER_RETURN')) == 1 AND (int)($this->getCurrentState()) == Configuration::get('PS_OS_DELIVERED') AND $this->getNumberOfDays());
}
public static function getLastInvoiceNumber()
{
return (int)Db::getInstance()->getValue('
SELECT MAX(`invoice_number`) AS `invoice_number`
FROM `'._DB_PREFIX_.'orders`');
public static function getLastInvoiceNumber()
{
return Db::getInstance()->getValue('
SELECT MAX(`number`)
FROM `'._DB_PREFIX_.'order_invoice`
');
}
public function setInvoice()
{
$number = (int)Configuration::get('PS_INVOICE_START_NUMBER');
if ($number)
$order_invoice = new OrderInvoice();
$order_invoice->id_order = $this->id;
$order_invoice->number = Configuration::get('PS_INVOICE_START_NUMBER');
// If invoice start number has been set, you clean the value of this configuration
if ($order_invoice->number)
Configuration::updateValue('PS_INVOICE_START_NUMBER', false);
else
$number = '(SELECT `invoice_number`
FROM (
SELECT MAX(`invoice_number`) + 1 AS `invoice_number`
FROM `'._DB_PREFIX_.'orders`)
tmp )';
// a way to avoid duplicate invoice number
$order_invoice->number = self::getLastInvoiceNumber() + 1;
$order_invoice->total_discount_tax_excl = $this->total_discount_tax_excl;
$order_invoice->total_discount_tax_incl = $this->total_discount_tax_incl;
$order_invoice->total_paid_tax_excl = $this->total_paid_tax_excl;
$order_invoice->total_paid_tax_incl = $this->total_paid_tax_incl;
$order_invoice->total_products = $this->total_products;
$order_invoice->total_products_wt = $this->total_products_wt;
$order_invoice->total_shipping_tax_excl = $this->total_shipping_tax_excl;
$order_invoice->total_shipping_tax_incl = $this->total_shipping_tax_incl;
$order_invoice->total_wrapping_tax_excl = $this->total_wrapping_tax_excl;
$order_invoice->total_wrapping_tax_incl = $this->total_wrapping_tax_incl;
// Save Order invoice
$order_invoice->add();
// Update order_carrier
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'orders`
SET `invoice_number` = '.$number.', `invoice_date` = \''.date('Y-m-d H:i:s').'\'
WHERE `id_order` = '.(int)$this->id
);
$res = Db::getInstance()->getRow('
SELECT `invoice_number`, `invoice_date`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int)$this->id
);
UPDATE `'._DB_PREFIX_.'order_carrier`
SET `id_order_invoice` = '.(int)$order_invoice->id.'
WHERE `id_order` = '.(int)$order_invoice->id_order);
// Update order detail
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'order_detail`
SET `id_order_invoice` = '.(int)$order_invoice->id.'
WHERE `id_order` = '.(int)$order_invoice->id_order);
$this->invoice_date = $res['invoice_date'];
$this->invoice_number = $res['invoice_number'];
@@ -1070,8 +1090,14 @@ class OrderCore extends ObjectModel
return (float)($result['weight']);
}
/**
*
* @param int $id_invoice
* @deprecated 1.5.0.1
*/
public static function getInvoice($id_invoice)
{
Tools::displayAsDeprecated();
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `invoice_number`, `id_order`
FROM `'._DB_PREFIX_.'orders`
@@ -1128,9 +1154,9 @@ class OrderCore extends ObjectModel
$history->id_employee = (int)$id_employee;
$history->changeIdOrderState((int)$id_order_state, (int)$this->id);
$res = Db::getInstance()->getRow('
SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int)$this->id);
SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int)$this->id);
$this->invoice_date = $res['invoice_date'];
$this->invoice_number = $res['invoice_number'];
$this->delivery_date = $res['delivery_date'];
@@ -1156,6 +1182,7 @@ class OrderCore extends ObjectModel
/**
* This method return the ID of the previous order
* @since 1.5.0.1
* @return int
*/
public function getPreviousOrderId()
@@ -1169,6 +1196,7 @@ class OrderCore extends ObjectModel
/**
* This method return the ID of the next order
* @since 1.5.0.1
* @return int
*/
public function getNextOrderId()
@@ -1243,9 +1271,162 @@ class OrderCore extends ObjectModel
WHERE od.`id_order` = '.(int)$this->id.'
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
);
}
/**
* This method allows to get all Order Payment for the current order
* @since 1.5.0.1
* @return array Collection of Order Payment
*/
public function getOrderPaymentCollection()
{
$order_payment = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_payment`
WHERE `id_order` = '.(int)$this->id);
return ObjectModel::hydrateCollection('OrderPayment', $order_payment);
}
/**
*
* This method allows to add a payment to the current order
* @since 1.5.0.1
* @param float $amount_paid
* @param string $payment_method
* @param string $payment_transaction_id
* @param Currency $currency
* @param string $date
* @return bool
*/
public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null)
{
$order_payment = new OrderPayment();
$order_payment->id_order = $this->id;
$order_payment->id_currency = ($currency ? $currency->id : $this->id_currency);
// we kept the currency rate for historization reasons
$order_payment->conversion_rate = ($currency ? $currency->conversion_rate : 1);
// if payment_method is define, we used this
$order_payment->payment_method = ($payment_method ? $payment_method : $this->payment);
$order_payment->transacation_id = $payment_transaction_id;
$order_payment->amount = $amount_paid;
$order_payment->date_add = ($date ? $date : null);
// Update total_paid_real value for backward compatibility reasons
if ($order_payment->id_currency == $this->id_currency)
$this->total_paid_real += $order_payment->amount;
else
$this->total_paid_real += Tools::ps_round(Tools::convertPrice($order_payment->amount, $order_payment->id_currency, false), 2);
return $order_payment->add() && $this->update();
}
/**
* Returns the correct product taxes breakdown.
*
* Get all documents linked to the current order
*
* @since 1.5.0.1
* @return array
*/
public function getDocuments()
{
// TODO
$invoices = $this->getInvoicesCollection();
return $invoices;
}
public function getReturn()
{
return OrderReturn::getOrdersReturn($this->id_customer, $this->id);
}
public function getShipping()
{
$shipping = Db::getInstance()->ExecuteS('
SELECT DISTINCT oc.`id_order_invoice`, oc.`weight`, oc.`shipping_cost_tax_excl`, oc.`shipping_cost_tax_incl`, c.`url`, oc.`id_carrier`, c.`name` as `state_name`, oc.`date_add`, "Delivery" as `type`, "true" as `can_edit`, oc.`tracking_number`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_history` oh
ON (o.`id_order` = oh.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'order_carrier` oc
ON (o.`id_order` = oc.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'carrier` c
ON (oc.`id_carrier` = c.`id_carrier`)
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl
ON (oh.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)Context::getContext()->language->id.')
WHERE o.`id_order` = '.(int)$this->id);
return $shipping;
}
/**
*
* Get all invoices for the current order
* @since 1.5.0.1
* @return array Collection of Order invoice
*/
public function getInvoicesCollection()
{
$invoices = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_invoice`
WHERE `id_order` = '.(int)$this->id);
return ObjectModel::hydrateCollection('OrderInvoice', $invoices);
}
/**
* Get total paid
*
* @since 1.5.0.1
* @param Currency $currency currency used for the total paid of the current order
* @return float amount in the $currency
*/
public function getTotalPaid($currency = null)
{
if (!$currency)
$currency = new Currency($this->id_currency);
$total = 0;
// Retrieve all payments
$payments = $this->getOrderPaymentCollection();
foreach($payments as $payment)
{
if ($payment->id_currency == $currency->id)
$total += $payment->amount;
else
{
$amount = Tools::convertPrice($payment->amount, $payment->id_currency, false);
if ($currency->id == Configuration::get('PS_DEFAULT_CURRENCY'))
$total += $amount;
else
$total += Tool::convertPrice($amount, $currency->id, true);
}
}
return Tools::ps_round($total, 2);
}
/**
*
* This method allows to change the shipping cost of the current order
* @since 1.5.0.1
* @param float $amount
* @return bool
*/
public function updateShippingCost($amount)
{
$difference = $amount - $this->total_shipping;
// if the current amount is same as the new, we return true
if ($difference == 0)
return true;
// update the total_shipping value
$this->total_shipping = $amount;
// update the total of this order
$this->total_paid += $difference;
// update database
return $this->update();
}
/**
* Returns the correct product taxes breakdown.
+42 -20
View File
@@ -33,6 +33,9 @@ class OrderDetailCore extends ObjectModel
/** @var integer */
public $id_order;
/** @var integer */
public $id_order_invoice;
/** @var integer */
public $product_id;
@@ -133,6 +136,7 @@ class OrderDetailCore extends ObjectModel
protected $fieldsValidate = array(
'id_order' => 'isUnsignedId',
'id_order_invoice' => 'isUnsignedId',
'product_id' => 'isUnsignedId',
'product_attribute_id' => 'isUnsignedId',
'product_name' => 'isGenericName',
@@ -213,6 +217,7 @@ class OrderDetailCore extends ObjectModel
$this->validateFields();
$fields['id_order'] = (int)$this->id_order;
$fields['id_order_invoice'] = (int)$this->id_order_invoice;
$fields['product_id'] = (int)$this->product_id;
$fields['product_attribute_id'] = (int)$this->product_attribute_id;
$fields['product_name'] = pSQL($this->product_name);
@@ -229,7 +234,7 @@ class OrderDetailCore extends ObjectModel
$fields['product_ean13'] = pSQL($this->product_ean13);
$fields['product_upc'] = pSQL($this->product_upc);
$fields['product_reference'] = pSQL($this->product_reference);
$fields['product_supplier_reference'] = pSQL($this->product_reference);
$fields['product_supplier_reference'] = pSQL($this->product_supplier_reference);
$fields['product_weight'] = (float)$this->product_weight;
$fields['tax_name'] = pSQL($this->tax_name);
$fields['tax_rate'] = (float)$this->tax_rate;
@@ -405,11 +410,11 @@ class OrderDetailCore extends ObjectModel
$this->tax_calculator = $tax_manager->getTaxCalculator();
}
$this->ecotax_tax_rate = 0;
if (!empty($product['ecotax']))
$this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->ecotax_tax_rate = 0;
if (!empty($product['ecotax']))
$this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->tax_computation_method = (int)$this->tax_calculator->computation_method;
$this->tax_computation_method = (int)$this->tax_calculator->computation_method;
}
/**
@@ -445,12 +450,14 @@ class OrderDetailCore extends ObjectModel
$customer = new Customer((int)$order->id_customer);
$customer_address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->specificPrice = SpecificPrice::getSpecificPrice((int)$product['id_product'],
(int)$order->id_shop,
(int)$order->id_currency,
(int)$customer_address->id_country,
(int)$customer->id_default_group,
(int)$product['cart_quantity']);
$this->specificPrice = SpecificPrice::getSpecificPrice(
(int)$product['id_product'],
(int)$order->id_shop,
(int)$order->id_currency,
(int)$customer_address->id_country,
(int)$customer->id_default_group,
(int)$product['cart_quantity']
);
$this->product_price = (float)$product['price'];
$this->unit_price_tax_incl = (float)$product['price_wt'];
@@ -462,7 +469,12 @@ class OrderDetailCore extends ObjectModel
$this->group_reduction = (float)(Group::getReduction((int)($order->id_customer)));
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $this->context->shop->getID(),
if (isset($this->context->shop))
$shop_id = $this->context->shop->getID();
else
$shop_id = $cart->id_shop;
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $shop_id,
(int)$cart->id_currency, (int)$this->vat_address->id_country,
(int)$this->customer->id_default_group, (int)$product['cart_quantity']);
@@ -484,10 +496,13 @@ class OrderDetailCore extends ObjectModel
* @param object $cart
* @param array $product
* @param int $id_order_status
* @param int $id_order_invoice
* @param bool $use_taxes set to false if you don't want to use taxes
*/
protected function create(Order $order, Cart $cart, $product, $id_order_state)
protected function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true)
{
$this->tax_calculator = new TaxCalculator();
if ($use_taxes)
$this->tax_calculator = new TaxCalculator();
$this->id = null;
@@ -510,13 +525,19 @@ class OrderDetailCore extends ObjectModel
$this->setVirtualProductInformation($product);
$this->checkProductStock($product, $id_order_state);
$this->setProductTax($order, $product);
if ($use_taxes)
$this->setProductTax($order, $product);
$this->setDetailProductPrice($order, $cart, $product);
// Set order invoice id
$this->id_order_invoice = (int)$id_order_invoice;
// Add new entry to the table
$this->save();
$this->saveTaxCalculator();
if ($use_taxes)
$this->saveTaxCalculator();
unset($this->tax_calculator);
}
@@ -525,18 +546,19 @@ class OrderDetailCore extends ObjectModel
* @param object $order
* @param object $cart
* @param int $id_order_status
* @param int $id_order_invoice
* @param bool $use_taxes set to false if you don't want to use taxes
*/
public function createList(Order $order, Cart $cart, $id_order_state, $product_list)
public function createList(Order $order, Cart $cart, $id_order_state, $product_list, $id_order_invoice, $use_taxes = true)
{
$this->vat_address = new Address((int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$this->customer = new Customer((int)($order->id_customer));
$this->id_order = $order->id;
$products = $product_list;
$this->outOfStock = false;
foreach ($products as $product)
$this->create($order, $cart, $product, $id_order_state);
foreach ($product_list as $product)
$this->create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes);
unset($this->vat_address);
unset($products);
+387
View File
@@ -0,0 +1,387 @@
<?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: 10418 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class OrderInvoiceCore extends ObjectModel
{
/** @var integer */
public $id_order;
/** @var integer */
public $number;
/** @var float */
public $total_discount_tax_excl;
/** @var float */
public $total_discount_tax_incl;
/** @var float */
public $total_paid_tax_excl;
/** @var float */
public $total_paid_tax_incl;
/** @var float */
public $total_products;
/** @var float */
public $total_products_wt;
/** @var float */
public $total_shipping_tax_excl;
/** @var float */
public $total_shipping_tax_incl;
/** @var float */
public $total_wrapping_tax_excl;
/** @var float */
public $total_wrapping_tax_incl;
/** @var intger */
public $date_add;
protected $fieldsRequired = array('id_order', 'number');
protected $fieldsValidate = array('id_order' => 'isUnsignedId', 'number' => 'isUnsignedId');
protected $table = 'order_invoice';
protected $identifier = 'id_order_invoice';
public function getFields()
{
$this->validateFields();
$fields['id_order'] = (int)$this->id_order;
$fields['number'] = (int)$this->number;
$fields['total_discount_tax_excl'] = (float)$this->total_discount_tax_excl;
$fields['total_discount_tax_incl'] = (float)$this->total_discount_tax_incl;
$fields['total_paid_tax_excl'] = (float)$this->total_paid_tax_excl;
$fields['total_paid_tax_incl'] = (float)$this->total_paid_tax_incl;
$fields['total_products'] = (float)$this->total_products;
$fields['total_products_wt'] = (float)$this->total_products_wt;
$fields['total_shipping_tax_excl'] = (float)$this->total_shipping_tax_excl;
$fields['total_shipping_tax_incl'] = (float)$this->total_shipping_tax_incl;
$fields['total_wrapping_tax_excl'] = (float)$this->total_wrapping_tax_excl;
$fields['total_wrapping_tax_incl'] = (float)$this->total_wrapping_tax_incl;
$fields['date_add'] = pSQL($this->date_add);
return $fields;
}
public function getProductsDetail()
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` od
WHERE od.`id_order` = '.(int)$this->id_order.'
AND od.`id_order_invoice` = '.(int)$this->id);
}
/**
* Get order products
*
* @return array Products with price, quantity (with taxe and without)
*/
public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
{
if (!$products)
$products = $this->getProductsDetail();
$order = new Order($this->id_order);
$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
$resultArray = array();
foreach ($products AS $row)
{
// Change qty if selected
if ($selectedQty)
{
$row['product_quantity'] = 0;
foreach ($selectedProducts AS $key => $id_product)
if ($row['id_order_detail'] == $id_product)
$row['product_quantity'] = (int)($selectedQty[$key]);
if (!$row['product_quantity'])
continue ;
}
$this->setProductImageInformations($row);
$this->setProductCurrentStock($row);
$this->setProductPrices($row, $order);
$this->setProductCustomizedDatas($row, $customized_datas);
// Add information for virtual product
if ($row['download_hash'] && !empty($row['download_hash']))
{
if ($row['product_attribute_id'] && !empty($row['product_attribute_id']))
$row['filename'] = ProductDownload::getFilenameFromIdAttribute((int)$row['product_id'], (int)$row['product_attribute_id']);
else
$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
// Get the display filename
$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
}
/* Stock product */
$resultArray[(int)$row['id_order_detail']] = $row;
}
if ($customized_datas)
Product::addCustomizationPrice($resultArray, $customized_datas);
return $resultArray;
}
protected function setProductCustomizedDatas(&$product, $customized_datas)
{
$product['customizedDatas'] = null;
if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']]))
$product['customizedDatas'] = $customized_datas[$product['product_id']][$product['product_attribute_id']];
else
$product['customizationQuantityTotal'] = 0;
}
/**
*
* This method allow to add stock information on a product detail
* @param array &$product
*/
protected function setProductCurrentStock(&$product)
{
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
}
/**
*
* This method allow to add image information on a product detail
* @param array &$product
*/
protected function setProductImageInformations(&$product)
{
if (isset($product['product_attribute_id']) && $product['product_attribute_id'])
$id_image = Db::getInstance()->getValue('
SELECT id_image
FROM '._DB_PREFIX_.'product_attribute_image
WHERE id_product_attribute = '.(int)$product['product_attribute_id']);
if (!isset($image['id_image']) || !$image['id_image'])
$id_image = Db::getInstance()->getValue('
SELECT id_image
FROM '._DB_PREFIX_.'image
WHERE id_product = '.(int)($product['product_id']).' AND cover = 1
');
$product['image'] = null;
$product['image_size'] = null;
if ($id_image)
$product['image'] = new Image($id_image);
}
public function setProductPrices(&$row, $order)
{
$tax_calculator = OrderDetail::getTaxCalculatorStatic((int)$row['id_order_detail']);
$row['tax_calculator'] = $tax_calculator;
$row['tax_rate'] = $tax_calculator->getTotalRate();
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
$row['product_price'] = Tools::ps_round($row['product_price'], 2);
else
$row['product_price_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['product_price']), 2);
$group_reduction = 1;
if ($row['group_reduction'] > 0)
$group_reduction = 1 - $row['group_reduction'] / 100;
if ($row['reduction_percent'] != 0)
{
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
$row['product_price'] = ($row['product_price'] - $row['product_price'] * ($row['reduction_percent'] * 0.01));
else
$row['product_price_wt'] = Tools::ps_round(($row['product_price_wt'] - $row['product_price_wt'] * ($row['reduction_percent'] * 0.01)), 2);
}
if ($row['reduction_amount'] != 0)
{
if ($this->_taxCalculationMethod == PS_TAX_EXC)
$row['product_price'] = ($row['product_price'] - ($tax_calculator->removeTaxes($row['reduction_amount'])));
else
$row['product_price_wt'] = Tools::ps_round(($row['product_price_wt'] - $row['reduction_amount']), 2);
}
if ($row['group_reduction'] > 0)
{
if ($this->_taxCalculationMethod == PS_TAX_EXC)
$row['product_price'] = $row['product_price'] * $group_reduction;
else
$row['product_price_wt'] = Tools::ps_round($row['product_price_wt'] * $group_reduction , 2);
}
if (($row['reduction_percent'] OR $row['reduction_amount'] OR $row['group_reduction']) AND $order->getTaxCalculationMethod() == PS_TAX_EXC)
$row['product_price'] = Tools::ps_round($row['product_price'], 2);
if ($order->getTaxCalculationMethod() == PS_TAX_EXC)
$row['product_price_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['product_price']), 2) + Tools::ps_round($row['ecotax'] * (1 + $row['ecotax_tax_rate'] / 100), 2);
else
{
$row['product_price_wt_but_ecotax'] = $row['product_price_wt'];
$row['product_price_wt'] = Tools::ps_round($row['product_price_wt'] + $row['ecotax'] * (1 + $row['ecotax_tax_rate'] / 100), 2);
}
$row['total_wt'] = $row['product_quantity'] * $row['product_price_wt'];
$row['total_price'] = $row['product_quantity'] * $row['product_price'];
}
/**
* This method returns true if at least one order details uses the
* One After Another tax computation method.
*
* @since 1.5.0.1
* @return boolean
*/
public function useOneAfterAnotherTaxComputationMethod()
{
// if one of the order details use the tax computation method the display will be different
return Db::getInstance()->getValue('
SELECT od.`tax_computation_method`
FROM `'._DB_PREFIX_.'order_detail_tax` odt
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = '.(int)$this->id_order.'
AND od.`id_order_invoice` = '.(int)$this->id.'
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
);
}
/**
* Returns the correct product taxes breakdown.
*
* @since 1.5.0.1
* @return array
*/
public function getProductTaxesBreakdown()
{
$tmp_tax_infos = array();
if ($this->useOneAfterAnotherTaxComputationMethod())
{
// sum by taxes
$taxes_by_tax = Db::getInstance()->executeS('
SELECT odt.`id_order_detail`, t.`name`, t.`rate`, SUM(`total_amount`) AS `total_amount`
FROM `'._DB_PREFIX_.'order_detail_tax` odt
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = '.(int)$this->id_order.'
AND od.`id_order_invoice` = '.(int)$this->id.'
GROUP BY odt.`id_tax`
');
// format response
$tmp_tax_infos = array();
foreach ($taxes_infos as $tax_infos)
{
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] = $tax_infos['tax_amount'];
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
}
}
else
{
// sum by order details in order to retrieve real taxes rate
$taxes_infos = Db::getInstance()->executeS('
SELECT odt.`id_order_detail`, t.`rate` AS `name`, SUM(od.`total_price_tax_excl`) AS total_price_tax_excl, SUM(t.`rate`) AS rate, SUM(`total_amount`) AS `total_amount`
FROM `'._DB_PREFIX_.'order_detail_tax` odt
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = '.(int)$this->id_order.'
AND od.`id_order_invoice` = '.(int)$this->id.'
GROUP BY odt.`id_order_detail`
');
// sum by taxes
$tmp_tax_infos = array();
foreach ($taxes_infos as $tax_infos)
{
if (!isset($tmp_tax_infos[$tax_infos['rate']]))
$tmp_tax_infos[$tax_infos['rate']] = array('total_amount' => 0,
'name' => 0,
'total_price_tax_excl' => 0);
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] += $tax_infos['total_amount'];
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
$tmp_tax_infos[$tax_infos['rate']]['total_price_tax_excl'] += $tax_infos['total_price_tax_excl'];
}
}
return $tmp_tax_infos;
}
/**
* Returns the shipping taxes breakdown
*
* @since 1.5.0.1
* @return array
*/
public function getShippingTaxesBreakdown($order)
{
$taxes_breakdown = array();
$shipping_tax_amount = $this->total_shipping_tax_incl - $this->total_shipping_tax_excl;
if ($shipping_tax_amount > 0)
$taxes_breakdown[] = array(
'rate' => $order->carrier_tax_rate,
'total_amount' => $shipping_tax_amount
);
return $taxes_breakdown;
}
/**
* Returns the wrapping taxes breakdown
* @todo
* @since 1.5.0.1
* @return array
*/
public function getWrappingTaxesBreakdown()
{
$taxes_breakdown = array();
return $taxes_breakdown;
}
/**
* Returns the ecotax taxes breakdown
*
* @since 1.5.0.1
* @return array
*/
public function getEcoTaxTaxesBreakdown()
{
return Db::getInstance()->executeS('
SELECT `ecotax_tax_rate`, SUM(`ecotax`) as `ecotax_tax_excl`, SUM(`ecotax`) as `ecotax_tax_incl`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int)$this->id_order.'
AND `id_order_invoice` = '.(int)$this->id
);
}
}
+99
View File
@@ -0,0 +1,99 @@
<?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: 10336 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class OrderPaymentCore extends ObjectModel
{
public $id_order;
public $id_currency;
public $amount;
public $payment_method;
public $conversion_rate;
public $transaction_id;
public $card_number;
public $card_brand;
public $card_expiration;
public $card_holder;
public $date_add;
protected $fieldsRequired = array('id_order', 'id_currency', 'amount');
protected $fieldsSize = array('transaction_id' => 254, 'card_number' => 254, 'card_brand' => 254, 'card_expiration' => 254, 'card_holder' => 254);
protected $fieldsValidate = array(
'id_order' => 'isUnsignedId',
'id_currency' => 'isUnsignedId',
'amount' => 'isPrice',
'payment_method' => 'isName',
'conversion_rate' => 'isFloat',
'transaction_id' => 'isAnything',
'card_number' => 'isAnything',
'card_brand' => 'isAnything',
'card_expiration' => 'isAnything',
'card_holder' => 'isAnything'
);
protected $table = 'order_payment';
protected $identifier = 'id_order_payment';
public function getFields()
{
$this->validateFields();
$fields['id_order'] = (int)($this->id_order);
$fields['id_currency'] = (int)($this->id_currency);
$fields['amount'] = (float)($this->amount);
$fields['payment_method'] = pSQL($this->payment_method);
$fields['transaction_id'] = pSQL($this->transaction_id);
$fields['card_number'] = pSQL($this->card_number);
$fields['card_brand'] = pSQL($this->card_brand);
$fields['card_expiration'] = pSQL($this->card_expiration);
$fields['card_holder'] = pSQL($this->card_holder);
$fields['date_add'] = pSQL($this->date_add);
return $fields;
}
public function add($autodate = true, $nullValues = false)
{
if (parent::add($autodate, $nullValues))
{
Hook::exec('paymentCCAdded', array('paymentCC' => $this));
return true;
}
return false;
}
/**
* Get the detailed payment of an order
* @param int $id_order
* @return array
*/
public static function getByOrderId($id_order)
{
return Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'payment_order`
WHERE `id_order` = '.(int)$id_order);
}
}
+4 -1
View File
@@ -143,10 +143,13 @@ class OrderReturnCore extends ObjectModel
($order_id ? ' AND `id_order` = '.(int)($order_id) : '').
($no_denied ? ' AND `state` != 4' : '').'
ORDER BY `date_add` DESC');
foreach ($data AS $k => $or)
foreach ($data as $k => $or)
{
$state = new OrderReturnState($or['state']);
$data[$k]['state_name'] = $state->name[$context->language->id];
$data[$k]['type'] = 'Return';
$data[$k]['tracking_number'] = $or['id_order_return'];
$data[$k]['can_edit'] = false;
}
return $data;
}
+1
View File
@@ -97,6 +97,7 @@ class OrderSlipCore extends ObjectModel
.($id_order_detail ? ' WHERE `id_order_detail` = '.(int)($id_order_detail) : ''));
}
// TODO clean getProducts($resTab) => now getProducts method don't use his parameters
public static function getOrdersSlipProducts($orderSlipId, $order)
{
$cart_rules = $order->getCartRules(true);
+14 -12
View File
@@ -34,17 +34,18 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
public $available_in_your_account = false;
public function __construct(Order $order, $smarty)
public function __construct(OrderInvoice $order_invoice, $smarty)
{
$this->order = $order;
$this->smarty = $smarty;
$this->order_invoice = $order_invoice;
$this->order = new Order($this->order_invoice->id_order);
$this->smarty = $smarty;
// header informations
$this->date = Tools::displayDate($order->invoice_date, (int)$order->id_lang);
$this->title = self::l('Invoice ').Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order->invoice_number);
$this->date = Tools::displayDate($order_invoice->date_add, (int)$this->order->id_lang);
$this->title = self::l('Invoice ').Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order_invoice->number);
// footer informations
$shop = new Shop((int)$order->id_shop);
$shop = new Shop((int)$this->order->id_shop);
$this->address = $shop->getAddress();
}
@@ -69,7 +70,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order->getProducts(),
'order_details' => $this->order_invoice->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
@@ -91,11 +92,12 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
$this->smarty->assign(array(
'tax_exempt' => $tax_exempt,
'use_one_after_another_method' => $this->order->useOneAfterAnotherTaxComputationMethod(),
'product_tax_breakdown' => $this->order->getProductTaxesBreakdown(),
'shipping_tax_breakdown' => $this->order->getShippingTaxesBreakdown(),
'ecotax_tax_breakdown' => $this->order->getEcoTaxTaxesBreakdown(),
'use_one_after_another_method' => $this->order_invoice->useOneAfterAnotherTaxComputationMethod(),
'product_tax_breakdown' => $this->order_invoice->getProductTaxesBreakdown(),
'shipping_tax_breakdown' => $this->order_invoice->getShippingTaxesBreakdown($this->order),
'ecotax_tax_breakdown' => $this->order_invoice->getEcoTaxTaxesBreakdown(),
'order' => $this->order,
'order_invoice' => $this->order_invoice
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/invoice.tax-tab.tpl');
@@ -131,7 +133,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
*/
public function getFilename()
{
return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order->invoice_number).'.pdf';
return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order_invoice->number).'.pdf';
}
}