[-] Classes : fixed bug #PSTEST-550 - Add current_state attribute on Order class

[~] Deprecated : OrderHistory::getLastOrderState()

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12898 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
aFolletete
2012-02-01 14:34:17 +00:00
parent 558efddd17
commit 5615dca5c1
7 changed files with 48 additions and 35 deletions
+30 -26
View File
@@ -52,6 +52,9 @@ class OrderCore extends ObjectModel
/** @var integer Carrier id */
public $id_carrier;
/** @var integer Order State id */
public $current_state;
/** @var string Secure key */
public $secure_key;
@@ -163,6 +166,7 @@ class OrderCore extends ObjectModel
'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'current_state' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5'),
'payment' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true),
'module' => array('type' => self::TYPE_STRING),
@@ -210,13 +214,13 @@ class OrderCore extends ObjectModel
'id_lang' => array('xlink_resource'=> 'languages'),
'id_customer' => array('xlink_resource'=> 'customers'),
'id_carrier' => array('xlink_resource'=> 'carriers'),
'current_state' => array('xlink_resource'=> 'order_states'),
'module' => array('required' => true),
'invoice_number' => array(),
'invoice_date' => array(),
'delivery_number' => array(),
'delivery_date' => array(),
'valid' => array(),
'current_state' => array('getter' => 'getCurrentState', 'setter' => 'setCurrentState', 'xlink_resource'=> 'order_states'),
'date_add' => array(),
'date_upd' => array(),
),
@@ -696,14 +700,11 @@ class OrderCore extends ObjectModel
/**
* Get current order state (eg. Awaiting payment, Delivered...)
*
* @return array Order state details
* @return int Order state id
*/
public function getCurrentState()
{
$orderHistory = OrderHistory::getLastOrderState($this->id);
if (!isset($orderHistory) || !$orderHistory)
return false;
return $orderHistory->id;
return $this->current_state;
}
/**
@@ -714,13 +715,10 @@ class OrderCore extends ObjectModel
public function getCurrentStateFull($id_lang)
{
return Db::getInstance()->getRow('
SELECT oh.`id_order_state`, osl.`name`, os.`logable`, os.`shipped`
FROM `'._DB_PREFIX_.'order_history` oh
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (osl.`id_order_state` = oh.`id_order_state`)
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`id_order_state`)
WHERE osl.`id_lang` = '.(int)($id_lang).' AND oh.`id_order` = '.(int)($this->id).'
ORDER BY `date_add` DESC, `id_order_history` DESC
');
SELECT os.`id_order_state`, osl.`name`, os.`logable`, os.`shipped`
FROM `'._DB_PREFIX_.'order_state` os
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (osl.`id_order_state` = os.`id_order_state`)
WHERE osl.`id_lang` = '.(int)$id_lang.' AND os.`id_order_state` = '.(int)$this->current_state);
}
public function hasBeenDelivered()
@@ -804,12 +802,10 @@ class OrderCore extends ObjectModel
$context = Context::getContext();
$sql = 'SELECT *, (
SELECT `name`
FROM `'._DB_PREFIX_.'order_history` oh
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (osl.`id_order_state` = oh.`id_order_state`)
WHERE oh.`id_order` = o.`id_order`
SELECT osl.`name`
FROM `'._DB_PREFIX_.'order_state_lang` osl
WHERE osl.`id_order_state` = o.`current_state`
AND osl.`id_lang` = '.(int)$context->language->id.'
ORDER BY oh.`date_add` DESC
LIMIT 1
) AS `state_name`
FROM `'._DB_PREFIX_.'orders` o
@@ -862,13 +858,7 @@ class OrderCore extends ObjectModel
Tools::displayAsDeprecated();
$sql = 'SELECT id_order
FROM '._DB_PREFIX_.'orders o
WHERE '.(int)$id_order_state.' = (
SELECT id_order_state
FROM '._DB_PREFIX_.'order_history oh
WHERE oh.id_order = o.id_order
ORDER BY date_add DESC, id_order_history DESC
LIMIT 1
)
WHERE o.`current_state` = '.(int)$id_order_state.'
'.Context::getContext()->shop->addSqlRestriction(false, 'o').'
ORDER BY invoice_date ASC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
@@ -1124,7 +1114,7 @@ class OrderCore extends ObjectModel
public static function printPDFIcons($id_order, $tr)
{
$order = new Order($id_order);
$orderState = OrderHistory::getLastOrderState($id_order);
$orderState = $order->getCurrentOrderState();
if (!Validate::isLoadedObject($orderState) || !Validate::isLoadedObject($order))
die(Tools::displayError('Invalid objects'));
echo '<span style="width:20px; margin-right:5px;">';
@@ -1233,6 +1223,9 @@ class OrderCore extends ObjectModel
$this->delivery_date = $res['delivery_date'];
$this->delivery_number = $res['delivery_number'];
$history->addWithemail();
$this->current_state = $id_order_state;
$this->update();
}
public function addWs($autodate = true, $nullValues = false)
@@ -1702,5 +1695,16 @@ class OrderCore extends ObjectModel
return $warehouse_list;
}
/**
* @since 1.5.0.4
* @return OrderState or null if Order haven't a state
*/
public function getCurrentOrderState()
{
if ($this->current_state)
return new OrderState($this->current_state);
return null;
}
}
+8 -3
View File
@@ -81,7 +81,7 @@ class OrderHistoryCore extends ObjectModel
// sets order and states
$order = new Order($id_order);
$new_os = new OrderState((int)$new_order_state, $order->id_lang);
$old_os = OrderHistory::getLastOrderState((int)$id_order);
$old_os = $order->getCurrentOrderState();
$is_validated = $this->isValidated();
// executes hook
@@ -209,6 +209,8 @@ class OrderHistoryCore extends ObjectModel
// the order is valid if and only if the invoice is available and the order is not cancelled
$order->valid = $new_os->logable;
// Update id_order_state attribute in Order
$order->current_state = $new_os->id;
$order->update();
if ($new_os->invoice && !$order->invoice_number)
@@ -251,9 +253,12 @@ class OrderHistoryCore extends ObjectModel
* Returns the last order state
* @param int $id_order
* @return OrderState|bool
* @deprecated 1.5.0.4
* @see Order->current_state
*/
public static function getLastOrderState($id_order)
{
Tools::displayAsDeprecated();
$id_order_state = Db::getInstance()->getValue('
SELECT `id_order_state`
FROM `'._DB_PREFIX_.'order_history`
@@ -278,7 +283,8 @@ class OrderHistoryCore extends ObjectModel
{
if (!$context)
$context = Context::getContext();
$last_order_state = $this->getLastOrderState($this->id_order);
$order = new Order($this->id_order);
$last_order_state = $order->getCurrentOrderState();
if (!parent::add($autodate))
return false;
@@ -298,7 +304,6 @@ class OrderHistoryCore extends ObjectModel
$data = array('{lastname}' => $result['lastname'], '{firstname}' => $result['firstname'], '{id_order}' => (int)$this->id_order);
if ($template_vars)
$data = array_merge($data, $template_vars);
$order = new Order((int)$this->id_order);
$data['{total_paid}'] = Tools::displayPrice((float)$order->total_paid, new Currency((int)$order->id_currency), false);
$data['{order_name}'] = sprintf('#%06d', (int)$order->id);
+4 -4
View File
@@ -158,7 +158,7 @@ class AdminOrdersControllerCore extends AdminController
public function printPDFIcons($id_order, $tr)
{
$order = new Order($id_order);
$order_state = OrderHistory::getLastOrderState($id_order);
$order_state = $order->getCurrentOrderState();
if (!Validate::isLoadedObject($order_state) || !Validate::isLoadedObject($order))
die(Tools::displayError('Invalid objects'));
@@ -239,7 +239,7 @@ class AdminOrdersControllerCore extends AdminController
$this->errors[] = Tools::displayError('Invalid new order status');
else
{
$current_order_state = OrderHistory::getLastOrderState($order->id);
$current_order_state = $order->getCurrentOrderState();
if ($current_order_state->id != $order_state->id)
{
// Create new OrderHistory
@@ -1092,7 +1092,7 @@ class AdminOrdersControllerCore extends AdminController
'states' => OrderState::getOrderStates($this->context->language->id),
'warehouse_list' => $warehouse_list,
'sources' => ConnectionsSource::getOrderSources($order->id),
'currentState' => OrderHistory::getLastOrderState($order->id),
'currentState' => $order->getCurrentOrderState(),
'currency' => new Currency($order->id_currency),
'currencies' => Currency::getCurrencies(),
'previousOrder' => $order->getPreviousOrderId(),
@@ -1398,7 +1398,7 @@ class AdminOrdersControllerCore extends AdminController
// Create Order detail information
$order_detail = new OrderDetail();
$order_detail->createList($order, $cart, OrderHistory::getLastOrderState($order->id), $cart->getProducts(), (isset($order_invoice) ? $order_invoice->id : 0), $use_taxes, (int)Tools::getValue('add_product_warehouse'));
$order_detail->createList($order, $cart, $order->getCurrentOrderState(), $cart->getProducts(), (isset($order_invoice) ? $order_invoice->id : 0), $use_taxes, (int)Tools::getValue('add_product_warehouse'));
// update totals amount of order
$order->total_products += (float)$cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
+1
View File
@@ -1020,6 +1020,7 @@ CREATE TABLE `PREFIX_orders` (
`id_currency` int(10) unsigned NOT NULL,
`id_address_delivery` int(10) unsigned NOT NULL,
`id_address_invoice` int(10) unsigned NOT NULL,
`current_state` int(10) unsigned NOT NULL,
`secure_key` varchar(32) NOT NULL default '-1',
`payment` varchar(255) NOT NULL,
`conversion_rate` decimal(13,6) NOT NULL default 1,
+1 -1
View File
@@ -19,7 +19,7 @@
<field name="is_guest"/>
</fields>
<entities>
<customer id="John" id_gender="" id_default_group="3" firstname="John" lastname="DOE" passwd="291ef87dd3531037a5f81c19036f2510" last_passwd_gen="2012-01-02 05:14:05" birthday="1970-01-15" newsletter="1" ip_registration_newsletter="" newsletter_date_add="0000-00-00 00:00:00" optin="1" secure_key="ec04c88d18dc5f8d86ff2a3754daa421" active="1" is_guest="0">
<customer id="John" id_gender="" id_default_group="3" firstname="John" lastname="DOE" passwd="75b019568bc6c84dda367661e855bdc2" last_passwd_gen="2012-02-01 09:08:06" birthday="1970-01-15" newsletter="1" ip_registration_newsletter="" newsletter_date_add="0000-00-00 00:00:00" optin="1" secure_key="b59e02456693eb0903a3645512ac9e1a" active="1" is_guest="0">
<email>pub@prestashop.com</email>
<note/>
</customer>
+2 -1
View File
@@ -10,6 +10,7 @@
<field name="id_currency"/>
<field name="id_address_delivery" relation="address"/>
<field name="id_address_invoice" relation="address"/>
<field name="current_state"/>
<field name="secure_key"/>
<field name="payment"/>
<field name="conversion_rate"/>
@@ -40,7 +41,7 @@
<field name="valid"/>
</fields>
<entities>
<orders id="orders_1" reference="XKBKNABJ" id_group_shop="1" id_shop="1" id_carrier="My_carrier" id_customer="John" id_cart="cart_1" id_currency="1" id_address_delivery="Mon_adresse" id_address_invoice="Mon_adresse" secure_key="47ce86627c1f3c792a80773c5d2deaf8" conversion_rate="1.000000" recyclable="0" gift="0" shipping_number="" total_discounts="0.00" total_discounts_tax_incl="0.00" total_paid="626.37" total_paid_tax_incl="626.37" total_paid_tax_excl="523.72" total_paid_real="626.37" total_products="516.72" total_products_wt="618.00" total_shipping="7.98" total_shipping_tax_incl="8.37" total_shipping_tax_excl="7.00" carrier_tax_rate="19.600" total_wrapping="0.00" total_wrapping_tax_incl="0.00" total_wrapping_tax_excl="0.00" invoice_number="0" delivery_number="0" invoice_date="0000-00-00 00:00:00" delivery_date="0000-00-00 00:00:00" valid="0">
<orders id="orders_1" reference="XKBKNABJ" id_group_shop="1" id_shop="1" id_carrier="My_carrier" id_customer="John" id_cart="cart_1" id_currency="1" id_address_delivery="Mon_adresse" id_address_invoice="Mon_adresse" current_state="1" secure_key="47ce86627c1f3c792a80773c5d2deaf8" conversion_rate="1.000000" recyclable="0" gift="0" shipping_number="" total_discounts="0.00" total_discounts_tax_incl="0.00" total_paid="626.37" total_paid_tax_incl="626.37" total_paid_tax_excl="523.72" total_paid_real="626.37" total_products="516.72" total_products_wt="618.00" total_shipping="7.98" total_shipping_tax_incl="8.37" total_shipping_tax_excl="7.00" carrier_tax_rate="19.600" total_wrapping="0.00" total_wrapping_tax_incl="0.00" total_wrapping_tax_excl="0.00" invoice_number="0" delivery_number="0" invoice_date="0000-00-00 00:00:00" delivery_date="0000-00-00 00:00:00" valid="0">
<payment>Chèque</payment>
<module>cheque</module>
<gift_message/>
+2
View File
@@ -46,3 +46,5 @@ ALTER TABLE `PREFIX_cart_rule_product_rule` CHANGE `id_cart_rule` `id_product_ru
ALTER TABLE `PREFIX_cart_rule_product_rule` CHANGE `type` `type` ENUM('products', 'categories', 'attributes', 'manufacturers', 'suppliers') NOT NULL;
ALTER TABLE `PREFIX_cart_rule` ADD `partial_use` tinyint(1) unsigned NOT NULL default 0 AFTER `priority`;
ALTER TABLE `PREFIX_orders` ADD `current_state` int(10) unsigned NOT NULL default 0 AFTER `id_address_invoice`;