// clean code && fix norm
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13081 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
1 parent
29002976ed
commit
11a74c652a
6 files changed
+241
-214
No files matched your search
+12
-1
@@ -654,7 +654,7 @@ class ValidateCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check url valdity (disallowed empty string)
|
* Check url validity (disallowed empty string)
|
||||||
*
|
*
|
||||||
* @param string $url Url to validate
|
* @param string $url Url to validate
|
||||||
* @return boolean Validity is ok or not
|
* @return boolean Validity is ok or not
|
||||||
@@ -664,6 +664,17 @@ class ValidateCore
|
|||||||
return preg_match('/^[~:#,%&_=\(\)\.\? \+\-@\/a-zA-Z0-9]+$/', $url);
|
return preg_match('/^[~:#,%&_=\(\)\.\? \+\-@\/a-zA-Z0-9]+$/', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check tracking number validity (disallowed empty string)
|
||||||
|
*
|
||||||
|
* @param string $tracking_number Tracking number to validate
|
||||||
|
* @return boolean Validity is ok or not
|
||||||
|
*/
|
||||||
|
public static function isTrackingNumber($tracking_number)
|
||||||
|
{
|
||||||
|
return preg_match('/^[~:#,%&_=\(\)\.\? \+\-@\/a-zA-Z0-9]+$/', $tracking_number);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check url validity (allowed empty string)
|
* Check url validity (allowed empty string)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -76,7 +76,11 @@ class OrderCore extends ObjectModel
|
|||||||
/** @var string Gift message if specified */
|
/** @var string Gift message if specified */
|
||||||
public $gift_message;
|
public $gift_message;
|
||||||
|
|
||||||
/** @var string Shipping number */
|
/**
|
||||||
|
* @var string Shipping number
|
||||||
|
* @deprecated 1.5.0.4
|
||||||
|
* @see OrderCarrier->tracking_number
|
||||||
|
*/
|
||||||
public $shipping_number;
|
public $shipping_number;
|
||||||
|
|
||||||
/** @var float Discounts total */
|
/** @var float Discounts total */
|
||||||
@@ -189,7 +193,7 @@ class OrderCore extends ObjectModel
|
|||||||
'total_wrapping' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
'total_wrapping' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||||
'total_wrapping_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
'total_wrapping_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||||
'total_wrapping_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
'total_wrapping_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice'),
|
||||||
'shipping_number' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl'),
|
'shipping_number' => array('type' => self::TYPE_STRING, 'validate' => 'isTrackingNumber'),
|
||||||
'conversion_rate' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true),
|
'conversion_rate' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat', 'required' => true),
|
||||||
'invoice_number' => array('type' => self::TYPE_INT),
|
'invoice_number' => array('type' => self::TYPE_INT),
|
||||||
'delivery_number' => array('type' => self::TYPE_INT),
|
'delivery_number' => array('type' => self::TYPE_INT),
|
||||||
@@ -1505,7 +1509,7 @@ class OrderCore extends ObjectModel
|
|||||||
if ($currency->id == Configuration::get('PS_DEFAULT_CURRENCY'))
|
if ($currency->id == Configuration::get('PS_DEFAULT_CURRENCY'))
|
||||||
$total += $amount;
|
$total += $amount;
|
||||||
else
|
else
|
||||||
$total += Tool::convertPrice($amount, $currency->id, true);
|
$total += Tools::convertPrice($amount, $currency->id, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class OrderCarrierCore extends ObjectModel
|
|||||||
'weight' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
'weight' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||||
'shipping_cost_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
'shipping_cost_tax_excl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||||
'shipping_cost_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
'shipping_cost_tax_incl' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||||
'tracking_number' => array('type' => self::TYPE_STRING, 'validate' => 'isAnything'),
|
'tracking_number' => array('type' => self::TYPE_STRING, 'validate' => 'isTrackingNumber'),
|
||||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ class StockMvtCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public static function getNegativeStockMvts($id_order, $id_product, $id_product_attribute, $quantity, $id_warehouse = null)
|
public static function getNegativeStockMvts($id_order, $id_product, $id_product_attribute, $quantity, $id_warehouse = null)
|
||||||
{
|
{
|
||||||
$mvts = array();
|
$movements = array();
|
||||||
$quantity_total = 0;
|
$quantity_total = 0;
|
||||||
|
|
||||||
$query = new DbQuery();
|
$query = new DbQuery();
|
||||||
@@ -205,10 +205,10 @@ class StockMvtCore extends ObjectModel
|
|||||||
if ($quantity_total >= $quantity)
|
if ($quantity_total >= $quantity)
|
||||||
break;
|
break;
|
||||||
$quantity_total += (int)$row['physical_quantity'];
|
$quantity_total += (int)$row['physical_quantity'];
|
||||||
$mvts[] = $row;
|
$movements[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $mvts;
|
return $movements;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -68,8 +68,6 @@ class AdminLoginControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (file_exists(_PS_ADMIN_DIR_.'/../install') || file_exists(_PS_ADMIN_DIR_.'/../admin')
|
if (file_exists(_PS_ADMIN_DIR_.'/../install') || file_exists(_PS_ADMIN_DIR_.'/../admin')
|
||||||
|| (file_exists(_PS_ADMIN_DIR_.'/../install-dev') && (!defined('_PS_MODE_DEV_') || !_PS_MODE_DEV_)))
|
|| (file_exists(_PS_ADMIN_DIR_.'/../install-dev') && (!defined('_PS_MODE_DEV_') || !_PS_MODE_DEV_)))
|
||||||
$this->context->smarty->assign(
|
$this->context->smarty->assign(
|
||||||
|
|||||||
@@ -78,10 +78,15 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$this->shopLinkType = 'shop';
|
$this->shopLinkType = 'shop';
|
||||||
$this->shopShareDatas = Shop::SHARE_ORDER;
|
$this->shopShareDatas = Shop::SHARE_ORDER;
|
||||||
|
|
||||||
// Save context (in order to apply cart rule)
|
if (Tools::isSubmit('id_order'))
|
||||||
$order = new Order((int)Tools::getValue('id_order'));
|
{
|
||||||
$this->context->cart = new Cart($order->id_cart);
|
// Save context (in order to apply cart rule)
|
||||||
$this->context->customer = new Customer($order->id_customer);
|
$order = new Order((int)Tools::getValue('id_order'));
|
||||||
|
if (!Validate::isLoadedObject($order))
|
||||||
|
throw new PrestaShopException('Cannot load Order object');
|
||||||
|
$this->context->cart = new Cart($order->id_cart);
|
||||||
|
$this->context->customer = new Customer($order->id_customer);
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
@@ -99,7 +104,7 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
'currencies' => Currency::getCurrencies(),
|
'currencies' => Currency::getCurrencies(),
|
||||||
'langs' => Language::getLanguages(true, Context::getContext()->shop->id),
|
'langs' => Language::getLanguages(true, Context::getContext()->shop->id),
|
||||||
'payment_modules' => PaymentModule::getInstalledPaymentModules(),
|
'payment_modules' => PaymentModule::getInstalledPaymentModules(),
|
||||||
'order_states' => OrderState::getOrderStates((int)Context::getContext()->cookie->id_lang),
|
'order_states' => OrderState::getOrderStates((int)Context::getContext()->language->id),
|
||||||
'show_toolbar' => $this->show_toolbar,
|
'show_toolbar' => $this->show_toolbar,
|
||||||
'toolbar_btn' => $this->toolbar_btn,
|
'toolbar_btn' => $this->toolbar_btn,
|
||||||
'toolbar_fix' => $this->toolbar_fix,
|
'toolbar_fix' => $this->toolbar_fix,
|
||||||
@@ -189,7 +194,7 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$order_carrier = new OrderCarrier(Tools::getValue('id_order_carrier'));
|
$order_carrier = new OrderCarrier(Tools::getValue('id_order_carrier'));
|
||||||
if (!Validate::isLoadedObject($order_carrier))
|
if (!Validate::isLoadedObject($order_carrier))
|
||||||
$this->errors[] = Tools::displayError('Order carrier ID is invalid');
|
$this->errors[] = Tools::displayError('Order carrier ID is invalid');
|
||||||
elseif (!Validate::isUrl(Tools::getValue('tracking_number')))
|
elseif (!Validate::isTrackingNumber(Tools::getValue('tracking_number')))
|
||||||
$this->errors[] = Tools::displayError('Tracking number is incorrect');
|
$this->errors[] = Tools::displayError('Tracking number is incorrect');
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -215,11 +220,15 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
'{lastname}' => $customer->lastname,
|
'{lastname}' => $customer->lastname,
|
||||||
'{id_order}' => $order->id
|
'{id_order}' => $order->id
|
||||||
);
|
);
|
||||||
@Mail::Send((int)$order->id_lang, 'in_transit', Mail::l('Package in transit', (int)$order->id_lang), $templateVars,
|
if (@Mail::Send((int)$order->id_lang, 'in_transit', Mail::l('Package in transit', (int)$order->id_lang), $templateVars,
|
||||||
$customer->email, $customer->firstname.' '.$customer->lastname, null, null, null, null,
|
$customer->email, $customer->firstname.' '.$customer->lastname, null, null, null, null,
|
||||||
_PS_MAIL_DIR_, true);
|
_PS_MAIL_DIR_, true))
|
||||||
Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order));
|
{
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
|
Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order));
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->errors[] = Tools::displayError('An error occurred while sending e-mail to customer.');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('Order carrier can\'t be updated');
|
$this->errors[] = Tools::displayError('Order carrier can\'t be updated');
|
||||||
@@ -290,7 +299,6 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Get message rules and and check fields validity */
|
/* Get message rules and and check fields validity */
|
||||||
// TODO review
|
|
||||||
$rules = call_user_func(array('Message', 'getValidationRules'), 'Message');
|
$rules = call_user_func(array('Message', 'getValidationRules'), 'Message');
|
||||||
foreach ($rules['required'] as $field)
|
foreach ($rules['required'] as $field)
|
||||||
if (($value = Tools::getValue($field)) == false && (string)$value != '0')
|
if (($value = Tools::getValue($field)) == false && (string)$value != '0')
|
||||||
@@ -331,7 +339,7 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$customer_message->private = Tools::getValue('visibility');
|
$customer_message->private = Tools::getValue('visibility');
|
||||||
|
|
||||||
if (!$customer_message->add())
|
if (!$customer_message->add())
|
||||||
$this->errors[] = Tools::displayError('An error occurred while sending message.');
|
$this->errors[] = Tools::displayError('An error occurred while saving message.');
|
||||||
elseif ($customer_message->private)
|
elseif ($customer_message->private)
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&vieworder&conf=11&token='.$this->token);
|
Tools::redirectAdmin(self::$currentIndex.'&id_order='.(int)$order->id.'&vieworder&conf=11&token='.$this->token);
|
||||||
else
|
else
|
||||||
@@ -364,30 +372,35 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] == '1')
|
if ($this->tabAccess['edit'] == '1')
|
||||||
{
|
{
|
||||||
$amount = 0;
|
if (is_array($_POST['partialRefundProduct']))
|
||||||
$order_detail_list = array();
|
|
||||||
foreach ($_POST['partialRefundProduct'] as $id_order_detail => $amount_detail)
|
|
||||||
if (isset($amount_detail) && !empty($amount_detail))
|
|
||||||
{
|
|
||||||
$amount += $amount_detail;
|
|
||||||
$order_detail_list[$id_order_detail]['quantity'] = (int)$_POST['partialRefundProductQuantity'][$id_order_detail];
|
|
||||||
$order_detail_list[$id_order_detail]['amount'] = (float)$amount_detail;
|
|
||||||
}
|
|
||||||
$shipping_cost_amount = (float)Tools::getValue('partialRefundShippingCost');
|
|
||||||
if ($shipping_cost_amount > 0)
|
|
||||||
$amount += $shipping_cost_amount;
|
|
||||||
|
|
||||||
if ($amount > 0)
|
|
||||||
{
|
{
|
||||||
if (!OrderSlip::createPartialOrderSlip($order, $amount, $shipping_cost_amount, $order_detail_list))
|
$amount = 0;
|
||||||
$this->errors[] = Tools::displayError('Cannot generate partial credit slip');
|
$order_detail_list = array();
|
||||||
|
foreach ($_POST['partialRefundProduct'] as $id_order_detail => $amount_detail)
|
||||||
|
if (isset($amount_detail) && !empty($amount_detail))
|
||||||
|
{
|
||||||
|
$amount += $amount_detail;
|
||||||
|
$order_detail_list[$id_order_detail]['quantity'] = (int)$_POST['partialRefundProductQuantity'][$id_order_detail];
|
||||||
|
$order_detail_list[$id_order_detail]['amount'] = (float)$amount_detail;
|
||||||
|
}
|
||||||
|
$shipping_cost_amount = (float)Tools::getValue('partialRefundShippingCost');
|
||||||
|
if ($shipping_cost_amount > 0)
|
||||||
|
$amount += $shipping_cost_amount;
|
||||||
|
|
||||||
|
if ($amount > 0)
|
||||||
|
{
|
||||||
|
if (!OrderSlip::createPartialOrderSlip($order, $amount, $shipping_cost_amount, $order_detail_list))
|
||||||
|
$this->errors[] = Tools::displayError('Cannot generate partial credit slip');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$this->errors[] = Tools::displayError('You have to write an amount if you want to do a partial credit slip');
|
||||||
|
|
||||||
|
// Redirect if no errors
|
||||||
|
if (!count($this->errors))
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=24&token='.$this->token);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('You have to write an amount if you want to do a partial credit slip');
|
$this->errors[] = Tools::displayError('Partial refund data are incorrect');
|
||||||
|
|
||||||
// Redirect if no errors
|
|
||||||
if (!count($this->errors))
|
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=24&token='.$this->token);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('You do not have permission to delete here.');
|
$this->errors[] = Tools::displayError('You do not have permission to delete here.');
|
||||||
@@ -398,207 +411,215 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
if ($this->tabAccess['delete'] === '1')
|
if ($this->tabAccess['delete'] === '1')
|
||||||
{
|
{
|
||||||
$productList = Tools::getValue('id_order_detail');
|
if (!Tools::isSubmit('id_order_detail'))
|
||||||
$customizationList = Tools::getValue('id_customization');
|
$this->errors[] = Tools::displayError('You must select a product');
|
||||||
$qtyList = Tools::getValue('cancelQuantity');
|
elseif (!Tools::isSubmit('cancelQuantity'))
|
||||||
$customizationQtyList = Tools::getValue('cancelCustomizationQuantity');
|
$this->errors[] = Tools::displayError('You must enter a quantity');
|
||||||
|
else
|
||||||
$full_product_list = $productList;
|
|
||||||
$full_quantity_list = $qtyList;
|
|
||||||
|
|
||||||
if ($customizationList)
|
|
||||||
foreach ($customizationList as $key => $id_order_detail)
|
|
||||||
{
|
|
||||||
$full_product_list[$id_order_detail] = $id_order_detail;
|
|
||||||
$full_quantity_list[$id_order_detail] = $customizationQtyList[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($productList || $customizationList)
|
|
||||||
{
|
{
|
||||||
if ($productList)
|
$productList = Tools::getValue('id_order_detail');
|
||||||
{
|
$customizationList = Tools::getValue('id_customization');
|
||||||
$id_cart = Cart::getCartIdByOrderId($order->id);
|
$qtyList = Tools::getValue('cancelQuantity');
|
||||||
$customization_quantities = Customization::countQuantityByCart($id_cart);
|
$customizationQtyList = Tools::getValue('cancelCustomizationQuantity');
|
||||||
|
|
||||||
foreach ($productList as $key => $id_order_detail)
|
$full_product_list = $productList;
|
||||||
{
|
$full_quantity_list = $qtyList;
|
||||||
$qtyCancelProduct = abs($qtyList[$key]);
|
|
||||||
if (!$qtyCancelProduct)
|
|
||||||
$this->errors[] = Tools::displayError('No quantity selected for product.');
|
|
||||||
|
|
||||||
// check actionable quantity
|
|
||||||
$order_detail = new OrderDetail($id_order_detail);
|
|
||||||
$customization_quantity = 0;
|
|
||||||
if (array_key_exists($order_detail->product_id, $customization_quantities) && array_key_exists($order_detail->product_attribute_id, $customization_quantities[$order_detail->product_id]))
|
|
||||||
$customization_quantity = (int)$customization_quantities[$order_detail->product_id][$order_detail->product_attribute_id];
|
|
||||||
|
|
||||||
if (($order_detail->product_quantity - $customization_quantity - $order_detail->product_quantity_refunded - $order_detail->product_quantity_return) < $qtyCancelProduct)
|
|
||||||
$this->errors[] = Tools::displayError('Invalid quantity selected for product.');
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($customizationList)
|
if ($customizationList)
|
||||||
{
|
foreach ($customizationList as $key => $id_order_detail)
|
||||||
$customization_quantities = Customization::retrieveQuantitiesFromIds(array_keys($customizationList));
|
|
||||||
|
|
||||||
foreach ($customizationList as $id_customization => $id_order_detail)
|
|
||||||
{
|
{
|
||||||
$qtyCancelProduct = abs($customizationQtyList[$id_customization]);
|
$full_product_list[$id_order_detail] = $id_order_detail;
|
||||||
$customization_quantity = $customization_quantities[$id_customization];
|
$full_quantity_list[$id_order_detail] = $customizationQtyList[$key];
|
||||||
|
|
||||||
if (!$qtyCancelProduct)
|
|
||||||
$this->errors[] = Tools::displayError('No quantity selected for product.');
|
|
||||||
|
|
||||||
if ($qtyCancelProduct > ($customization_quantity['quantity'] - ($customization_quantity['quantity_refunded'] + $customization_quantity['quantity_returned'])))
|
|
||||||
$this->errors[] = Tools::displayError('Invalid quantity selected for product.');
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!count($this->errors) && $productList)
|
if ($productList || $customizationList)
|
||||||
foreach ($productList as $key => $id_order_detail)
|
{
|
||||||
|
if ($productList)
|
||||||
{
|
{
|
||||||
$qty_cancel_product = abs($qtyList[$key]);
|
$id_cart = Cart::getCartIdByOrderId($order->id);
|
||||||
$order_detail = new OrderDetail((int)($id_order_detail));
|
$customization_quantities = Customization::countQuantityByCart($id_cart);
|
||||||
|
|
||||||
// Reinject product
|
foreach ($productList as $key => $id_order_detail)
|
||||||
if (!$order->hasBeenDelivered() || ($order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities')))
|
|
||||||
{
|
{
|
||||||
$reinjectable_quantity = (int)$order_detail->product_quantity - (int)$order_detail->product_quantity_reinjected;
|
$qtyCancelProduct = abs($qtyList[$key]);
|
||||||
$quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
|
if (!$qtyCancelProduct)
|
||||||
|
$this->errors[] = Tools::displayError('No quantity selected for product.');
|
||||||
|
|
||||||
// @since 1.5.0 : Advanced Stock Management
|
$order_detail = new OrderDetail($id_order_detail);
|
||||||
$product_to_inject = new Product($order_detail->product_id, false, $this->context->language->id, $order->id_shop);
|
$customization_quantity = 0;
|
||||||
|
if (array_key_exists($order_detail->product_id, $customization_quantities) && array_key_exists($order_detail->product_attribute_id, $customization_quantities[$order_detail->product_id]))
|
||||||
|
$customization_quantity = (int)$customization_quantities[$order_detail->product_id][$order_detail->product_attribute_id];
|
||||||
|
|
||||||
$product = new Product($order_detail->product_id);
|
if (($order_detail->product_quantity - $customization_quantity - $order_detail->product_quantity_refunded - $order_detail->product_quantity_return) < $qtyCancelProduct)
|
||||||
|
$this->errors[] = Tools::displayError('Invalid quantity selected for product.');
|
||||||
|
|
||||||
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
|
}
|
||||||
&& $product->advanced_stock_management
|
}
|
||||||
&& $order_detail->id_warehouse != 0)
|
if ($customizationList)
|
||||||
|
{
|
||||||
|
$customization_quantities = Customization::retrieveQuantitiesFromIds(array_keys($customizationList));
|
||||||
|
|
||||||
|
foreach ($customizationList as $id_customization => $id_order_detail)
|
||||||
|
{
|
||||||
|
$qtyCancelProduct = abs($customizationQtyList[$id_customization]);
|
||||||
|
$customization_quantity = $customization_quantities[$id_customization];
|
||||||
|
|
||||||
|
if (!$qtyCancelProduct)
|
||||||
|
$this->errors[] = Tools::displayError('No quantity selected for product.');
|
||||||
|
|
||||||
|
if ($qtyCancelProduct > ($customization_quantity['quantity'] - ($customization_quantity['quantity_refunded'] + $customization_quantity['quantity_returned'])))
|
||||||
|
$this->errors[] = Tools::displayError('Invalid quantity selected for product.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!count($this->errors) && $productList)
|
||||||
|
foreach ($productList as $key => $id_order_detail)
|
||||||
|
{
|
||||||
|
$qty_cancel_product = abs($qtyList[$key]);
|
||||||
|
$order_detail = new OrderDetail((int)($id_order_detail));
|
||||||
|
|
||||||
|
// Reinject product
|
||||||
|
if (!$order->hasBeenDelivered() || ($order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities')))
|
||||||
{
|
{
|
||||||
|
$reinjectable_quantity = (int)$order_detail->product_quantity - (int)$order_detail->product_quantity_reinjected;
|
||||||
|
$quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
|
||||||
|
|
||||||
$manager = StockManagerFactory::getManager();
|
// @since 1.5.0 : Advanced Stock Management
|
||||||
|
$product_to_inject = new Product($order_detail->product_id, false, $this->context->language->id, $order->id_shop);
|
||||||
|
|
||||||
$mvts = StockMvt::getNegativeStockMvts(
|
$product = new Product($order_detail->product_id);
|
||||||
$order_detail->id_order,
|
|
||||||
$order_detail->product_id,
|
|
||||||
$order_detail->product_attribute_id,
|
|
||||||
$quantity_to_reinject
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($mvts as $mvt)
|
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
|
||||||
|
&& $product->advanced_stock_management
|
||||||
|
&& $order_detail->id_warehouse != 0)
|
||||||
{
|
{
|
||||||
$manager->addProduct(
|
|
||||||
|
$manager = StockManagerFactory::getManager();
|
||||||
|
|
||||||
|
$movements = StockMvt::getNegativeStockMvts(
|
||||||
|
$order_detail->id_order,
|
||||||
$order_detail->product_id,
|
$order_detail->product_id,
|
||||||
$order_detail->product_attribute_id,
|
$order_detail->product_attribute_id,
|
||||||
new Warehouse($mvt['id_warehouse']),
|
$quantity_to_reinject
|
||||||
$mvt['physical_quantity'],
|
);
|
||||||
null,
|
|
||||||
$mvt['price_te'],
|
foreach ($movements as $movement)
|
||||||
true
|
{
|
||||||
|
$manager->addProduct(
|
||||||
|
$order_detail->product_id,
|
||||||
|
$order_detail->product_attribute_id,
|
||||||
|
new Warehouse($movement['id_warehouse']),
|
||||||
|
$movement['physical_quantity'],
|
||||||
|
null,
|
||||||
|
$movement['price_te'],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
StockAvailable::synchronize($order_detail->product_id);
|
||||||
|
}
|
||||||
|
else if ($order_detail->id_warehouse == 0)
|
||||||
|
{
|
||||||
|
StockAvailable::updateQuantity(
|
||||||
|
$order_detail->product_id,
|
||||||
|
$order_detail->product_attribute_id,
|
||||||
|
$quantity_to_reinject,
|
||||||
|
$order->id_shop
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
StockAvailable::synchronize($order_detail->product_id);
|
else
|
||||||
|
$this->errors[] = Tools::displayError('Cannot re-stock product');
|
||||||
}
|
}
|
||||||
else if ($order_detail->id_warehouse == 0)
|
|
||||||
{
|
// Delete product
|
||||||
StockAvailable::updateQuantity(
|
$order_detail = new OrderDetail((int)$id_order_detail);
|
||||||
$order_detail->product_id,
|
if (!$order->deleteProduct($order, $order_detail, $qtyCancelProduct))
|
||||||
$order_detail->product_attribute_id,
|
$this->errors[] = Tools::displayError('An error occurred during deletion of the product.').' <span class="bold">'.$order_detail->product_name.'</span>';
|
||||||
$quantity_to_reinject,
|
Hook::exec('actionProductCancel', array('order' => $order, 'id_order_detail' => $id_order_detail));
|
||||||
$order->id_shop
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$this->errors[] = Tools::displayError('Cannot re-stock product');
|
|
||||||
}
|
}
|
||||||
|
if (!count($this->errors) && $customizationList)
|
||||||
// Delete product
|
foreach ($customizationList as $id_customization => $id_order_detail)
|
||||||
$order_detail = new OrderDetail((int)$id_order_detail);
|
{
|
||||||
if (!$order->deleteProduct($order, $order_detail, $qtyCancelProduct))
|
$order_detail = new OrderDetail((int)($id_order_detail));
|
||||||
$this->errors[] = Tools::displayError('An error occurred during deletion of the product.').' <span class="bold">'.$order_detail->product_name.'</span>';
|
$qtyCancelProduct = abs($customizationQtyList[$id_customization]);
|
||||||
Hook::exec('actionProductCancel', array('order' => $order, 'id_order_detail' => $id_order_detail));
|
if (!$order->deleteCustomization($id_customization, $qtyCancelProduct, $order_detail))
|
||||||
}
|
$this->errors[] = Tools::displayError('An error occurred during deletion of product customization.').' '.$id_customization;
|
||||||
if (!count($this->errors) && $customizationList)
|
}
|
||||||
foreach ($customizationList as $id_customization => $id_order_detail)
|
// E-mail params
|
||||||
|
if ((Tools::isSubmit('generateCreditSlip') || Tools::isSubmit('generateDiscount')) && !count($this->errors))
|
||||||
{
|
{
|
||||||
$order_detail = new OrderDetail((int)($id_order_detail));
|
$customer = new Customer((int)($order->id_customer));
|
||||||
$qtyCancelProduct = abs($customizationQtyList[$id_customization]);
|
$params['{lastname}'] = $customer->lastname;
|
||||||
if (!$order->deleteCustomization($id_customization, $qtyCancelProduct, $order_detail))
|
$params['{firstname}'] = $customer->firstname;
|
||||||
$this->errors[] = Tools::displayError('An error occurred during deletion of product customization.').' '.$id_customization;
|
$params['{id_order}'] = $order->id;
|
||||||
}
|
}
|
||||||
// E-mail params
|
|
||||||
if ((isset($_POST['generateCreditSlip']) || isset($_POST['generateDiscount'])) && !count($this->errors))
|
|
||||||
{
|
|
||||||
$customer = new Customer((int)($order->id_customer));
|
|
||||||
$params['{lastname}'] = $customer->lastname;
|
|
||||||
$params['{firstname}'] = $customer->firstname;
|
|
||||||
$params['{id_order}'] = $order->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate credit slip
|
// Generate credit slip
|
||||||
if (isset($_POST['generateCreditSlip']) && !count($this->errors))
|
if (Tools::isSubmit('generateCreditSlip') && !count($this->errors))
|
||||||
{
|
|
||||||
if (!OrderSlip::createOrderSlip($order, $full_product_list, $full_quantity_list, isset($_POST['shippingBack'])))
|
|
||||||
$this->errors[] = Tools::displayError('Cannot generate credit slip');
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Hook::exec('actionOrderSlipAdd', array('order' => $order, 'productList' => $full_product_list, 'qtyList' => $full_quantity_list));
|
if (!OrderSlip::createOrderSlip($order, $full_product_list, $full_quantity_list, Tools::isSubmit('shippingBack')))
|
||||||
@Mail::Send(
|
$this->errors[] = Tools::displayError('Cannot generate credit slip');
|
||||||
(int)$order->id_lang,
|
else
|
||||||
'credit_slip',
|
{
|
||||||
Mail::l('New credit slip regarding your order', $order->id_lang),
|
Hook::exec('actionOrderSlipAdd', array('order' => $order, 'productList' => $full_product_list, 'qtyList' => $full_quantity_list));
|
||||||
$params,
|
@Mail::Send(
|
||||||
$customer->email,
|
(int)$order->id_lang,
|
||||||
$customer->firstname.' '.$customer->lastname,
|
'credit_slip',
|
||||||
null,
|
Mail::l('New credit slip regarding your order', $order->id_lang),
|
||||||
null,
|
$params,
|
||||||
null,
|
$customer->email,
|
||||||
null,
|
$customer->firstname.' '.$customer->lastname,
|
||||||
_PS_MAIL_DIR_,
|
null,
|
||||||
true
|
null,
|
||||||
);
|
null,
|
||||||
|
null,
|
||||||
|
_PS_MAIL_DIR_,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate voucher
|
||||||
|
if (Tools::isSubmit('generateDiscount') && !count($this->errors))
|
||||||
|
{
|
||||||
|
// @todo generate a voucher using cartrules
|
||||||
|
if (true || !$voucher = Discount::createOrderDiscount($order, $full_product_list, $full_quantity_list, $this->l('Credit Slip concerning the order #'), Tools::isSubmit('shippingBack')))
|
||||||
|
$this->errors[] = Tools::displayError('Cannot generate voucher');
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$currency = $this->context->currency;
|
||||||
|
$params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false);
|
||||||
|
$params['{voucher_num}'] = $voucher->name;
|
||||||
|
@Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order', (int)$order->id_lang),
|
||||||
|
$params, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null,
|
||||||
|
null, _PS_MAIL_DIR_, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
$this->errors[] = Tools::displayError('No product or quantity selected.');
|
||||||
|
|
||||||
// Generate voucher
|
// Redirect if no errors
|
||||||
if (isset($_POST['generateDiscount']) && !count($this->errors))
|
if (!count($this->errors))
|
||||||
{
|
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=24&token='.$this->token);
|
||||||
// @todo generate a voucher using cartrules
|
|
||||||
if (true || !$voucher = Discount::createOrderDiscount($order, $full_product_list, $full_quantity_list, $this->l('Credit Slip concerning the order #'), isset($_POST['shippingBack'])))
|
|
||||||
$this->errors[] = Tools::displayError('Cannot generate voucher');
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$currency = $this->context->currency;
|
|
||||||
$params['{voucher_amount}'] = Tools::displayPrice($voucher->value, $currency, false);
|
|
||||||
$params['{voucher_num}'] = $voucher->name;
|
|
||||||
@Mail::Send((int)$order->id_lang, 'voucher', Mail::l('New voucher regarding your order', (int)$order->id_lang),
|
|
||||||
$params, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null,
|
|
||||||
null, _PS_MAIL_DIR_, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
$this->errors[] = Tools::displayError('No product or quantity selected.');
|
|
||||||
|
|
||||||
// Redirect if no errors
|
|
||||||
if (!count($this->errors))
|
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=24&token='.$this->token);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('You do not have permission to delete here.');
|
$this->errors[] = Tools::displayError('You do not have permission to delete here.');
|
||||||
}
|
}
|
||||||
elseif (Tools::isSubmit('messageReaded'))
|
elseif (Tools::isSubmit('messageReaded'))
|
||||||
Message::markAsReaded($_GET['messageReaded'], $this->context->employee->id);
|
Message::markAsReaded(Tools::getValue('messageReaded'), $this->context->employee->id);
|
||||||
else if (Tools::isSubmit('submitAddPayment') && isset($order))
|
elseif (Tools::isSubmit('submitAddPayment') && isset($order))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
{
|
{
|
||||||
$amount = str_replace(',', '.', Tools::getValue('payment_amount'));
|
$amount = str_replace(',', '.', Tools::getValue('payment_amount'));
|
||||||
$currency = new Currency(Tools::getValue('payment_currency'));
|
$currency = new Currency(Tools::getValue('payment_currency'));
|
||||||
if ($order->hasInvoice())
|
$order_has_invoice = $order->hasInvoice();
|
||||||
|
if ($order_has_invoice)
|
||||||
$order_invoice = new OrderInvoice(Tools::getValue('payment_invoice'));
|
$order_invoice = new OrderInvoice(Tools::getValue('payment_invoice'));
|
||||||
else
|
else
|
||||||
$order_invoice = null;
|
$order_invoice = null;
|
||||||
|
|
||||||
if (!Validate::isLoadedObject($order))
|
if (!Validate::isLoadedObject($order))
|
||||||
$this->errors[] = Tools::displayError('Order can\'t be found');
|
$this->errors[] = Tools::displayError('Order can\'t be found');
|
||||||
elseif (!Validate::isPrice($amount))
|
elseif (!Validate::isPrice($amount))
|
||||||
@@ -609,14 +630,14 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$this->errors[] = Tools::displayError('Transaction ID is invalid');
|
$this->errors[] = Tools::displayError('Transaction ID is invalid');
|
||||||
elseif (!Validate::isLoadedObject($currency))
|
elseif (!Validate::isLoadedObject($currency))
|
||||||
$this->errors[] = Tools::displayError('Currency is invalid');
|
$this->errors[] = Tools::displayError('Currency is invalid');
|
||||||
elseif ($order->hasInvoice() && !Validate::isLoadedObject($order_invoice))
|
elseif ($order_has_invoice && !Validate::isLoadedObject($order_invoice))
|
||||||
$this->errors[] = Tools::displayError('Invoice is invalid');
|
$this->errors[] = Tools::displayError('Invoice is invalid');
|
||||||
elseif (!Validate::isDate(Tools::getValue('payment_date')))
|
elseif (!Validate::isDate(Tools::getValue('payment_date')))
|
||||||
$this->errors[] = Tools::displayError('Date is invalid');
|
$this->errors[] = Tools::displayError('Date is invalid');
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date'), $order_invoice))
|
if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date'), $order_invoice))
|
||||||
$this->errors[] = Tools::displayError('An error occured on adding of order payment');
|
$this->errors[] = Tools::displayError('An error occurred on adding of order payment');
|
||||||
else
|
else
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
|
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);
|
||||||
}
|
}
|
||||||
@@ -626,9 +647,8 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
elseif (Tools::isSubmit('submitEditNote'))
|
elseif (Tools::isSubmit('submitEditNote'))
|
||||||
{
|
{
|
||||||
$id_order_invoice = (int)Tools::getValue('id_order_invoice');
|
|
||||||
$note = Tools::getValue('note');
|
$note = Tools::getValue('note');
|
||||||
$order_invoice = new OrderInvoice($id_order_invoice);
|
$order_invoice = new OrderInvoice((int)Tools::getValue('id_order_invoice'));
|
||||||
if (Validate::isLoadedObject($order_invoice) && Validate::isCleanHtml($note))
|
if (Validate::isLoadedObject($order_invoice) && Validate::isCleanHtml($note))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
@@ -645,7 +665,9 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('Unable to load invoice for edit note.');
|
$this->errors[] = Tools::displayError('Unable to load invoice for edit note.');
|
||||||
}
|
}
|
||||||
elseif (Tools::isSubmit('submitAddOrder') == 1 && ($id_cart = Tools::getValue('id_cart')) && ($module_name = pSQL(Tools::getValue('payment_module_name'))) && ($id_order_state = Tools::getValue('id_order_state')))
|
elseif (Tools::isSubmit('submitAddOrder') && ($id_cart = Tools::getValue('id_cart')) &&
|
||||||
|
($module_name = Tools::getValue('payment_module_name')) &&
|
||||||
|
($id_order_state = Tools::getValue('id_order_state')))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
{
|
{
|
||||||
@@ -706,21 +728,13 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
$order_detail->update();
|
$order_detail->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update order payment amount
|
|
||||||
foreach ($order->getOrderPaymentCollection() as $payment)
|
|
||||||
{
|
|
||||||
$payment->id_currency = (int)$currency->id;
|
|
||||||
$payment->amount = Tools::convertPriceFull((float)$payment->amount, $old_currency, $currency);
|
|
||||||
$payment->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$id_order_carrier = Db::getInstance()->getValue('
|
$id_order_carrier = Db::getInstance()->getValue('
|
||||||
SELECT `id_order_carrier`
|
SELECT `id_order_carrier`
|
||||||
FROM `'._DB_PREFIX_.'order_carrier`
|
FROM `'._DB_PREFIX_.'order_carrier`
|
||||||
WHERE `id_order` = '.(int)$order->id);
|
WHERE `id_order` = '.(int)$order->id);
|
||||||
$order_carrier = new OrderCarrier($id_order_carrier);
|
$order_carrier = new OrderCarrier($id_order_carrier);
|
||||||
$order_carrier->shipping_cost_tax_excl = (float)Tools::convertPriceFull($order_carrier['shipping_cost_tax_excl'], $old_currency, $currency);
|
$order_carrier->shipping_cost_tax_excl = (float)Tools::convertPriceFull($order_carrier->shipping_cost_tax_excl, $old_currency, $currency);
|
||||||
$order_carrier->shipping_cost_tax_incl = (float)Tools::convertPriceFull($order_carrier['shipping_cost_tax_incl'], $old_currency, $currency);
|
$order_carrier->shipping_cost_tax_incl = (float)Tools::convertPriceFull($order_carrier->shipping_cost_tax_incl, $old_currency, $currency);
|
||||||
$order_carrier->update();
|
$order_carrier->update();
|
||||||
|
|
||||||
// Update order amount
|
// Update order amount
|
||||||
|
|||||||
Reference in new issue
Block a user