From bf3d89e1fbc5eebe05c0a4559403cb4d08950df7 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Wed, 2 Nov 2011 09:18:45 +0000 Subject: [PATCH] [+] BO: Add BackOffice orders --- admin-dev/themes/template/orders/form.tpl | 945 ++++++++++++++++++++ classes/Customer.php | 10 + classes/Discount.php | 8 + classes/FrontController.php | 28 + classes/OrderHistory.php | 4 +- classes/PaymentModule.php | 2 +- controllers/admin/AdminCartsController.php | 39 +- controllers/admin/AdminOrdersController.php | 106 ++- css/admin.css | 40 + 9 files changed, 1156 insertions(+), 26 deletions(-) create mode 100755 admin-dev/themes/template/orders/form.tpl diff --git a/admin-dev/themes/template/orders/form.tpl b/admin-dev/themes/template/orders/form.tpl new file mode 100755 index 000000000..2bf887e1f --- /dev/null +++ b/admin-dev/themes/template/orders/form.tpl @@ -0,0 +1,945 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 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/afl-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 +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8971 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +
{l s='Customer'} +

+ {l s='Add new customer'}

+
+
+

+
+ +
+ +
+ +
+ +
+ +
+
+
+
+
diff --git a/classes/Customer.php b/classes/Customer.php index fe26b3225..d1fdc3a92 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -677,4 +677,14 @@ class CustomerCore extends ObjectModel Context::getContext()->cookie->mylogout(); $this->logged = 0; } + + public function getLastCart() + { + $carts = Cart::getCustomerCarts((int)$this->id); + if (!count($carts)) + return false; + $cart = array_shift($carts); + $cart = new Cart((int)$cart['id_cart']); + return ($cart->nbProducts() === 0 ? (int)$cart->id : false); + } } \ No newline at end of file diff --git a/classes/Discount.php b/classes/Discount.php index 8f9df5575..158273e74 100644 --- a/classes/Discount.php +++ b/classes/Discount.php @@ -587,4 +587,12 @@ class DiscountCore extends CartRule Tools::displayAsDeprecated(); return CartRule::isFeatureActive(); } + + public static function getVoucherByName($name, $id_lang) + { + return Db::getInstance()->ExecuteS('SELECT d.*, dl.* + FROM '._DB_PREFIX_.'discount d + LEFT JOIN '._DB_PREFIX_.'discount_lang dl ON (d.id_discount = dl.id_discount AND dl.id_lang='.(int)$id_lang.') + WHERE name LIKE \'%'.pSQL($name).'%\''); + } } \ No newline at end of file diff --git a/classes/FrontController.php b/classes/FrontController.php index b79894441..da7627ca2 100755 --- a/classes/FrontController.php +++ b/classes/FrontController.php @@ -119,6 +119,9 @@ class FrontControllerCore extends Controller $link = new Link($protocol_link, $protocol_content); $this->context->link = $link; + if ($id_cart = (int)$this->recoverCart()) + $this->context->cookie->id_cart = (int)$id_cart; + if ($this->auth AND !$this->context->customer->isLogged($this->guestAllowed)) Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : '')); @@ -729,5 +732,30 @@ class FrontControllerCore extends Controller return parent::addJS($js_uri); } + + protected function recoverCart() + { + if (($id_cart = (int)Tools::getValue('recover_cart')) && Tools::getValue('token_cart') == md5(_COOKIE_KEY_.'recover_cart_'.$id_cart)) + { + $cart = new Cart((int)$id_cart); + if (Validate::isLoadedObject($cart)) + { + $customer = new Customer((int)$cart->id_customer); + if(Validate::isLoadedObject($customer)) + { + $this->context->cookie->id_customer = (int)$customer->id; + $this->context->cookie->customer_lastname = $customer->lastname; + $this->context->cookie->customer_firstname = $customer->firstname; + $this->context->cookie->logged = 1; + $this->context->cookie->is_guest = $customer->isGuest(); + $this->context->cookie->passwd = $customer->passwd; + $this->context->cookie->email = $customer->email; + return $id_cart; + } + } + } + else + return false; + } } diff --git a/classes/OrderHistory.php b/classes/OrderHistory.php index d699c6bc0..1ec247025 100644 --- a/classes/OrderHistory.php +++ b/classes/OrderHistory.php @@ -74,12 +74,12 @@ class OrderHistoryCore extends ObjectModel { if ($new_order_state != NULL) { - Hook::updateOrderStatus((int)($new_order_state), (int)($id_order)); + Hook::updateOrderStatus((int)($new_order_state), (int)$id_order); $order = new Order((int)($id_order)); /* Best sellers */ $newOS = new OrderState((int)($new_order_state), $order->id_lang); - $oldOrderStatus = OrderHistory::getLastOrderState((int)($id_order)); + $oldOrderStatus = OrderHistory::getLastOrderState((int)$id_order); $cart = Cart::getCartByOrderId($id_order); $isValidated = $this->isValidated(); if (Validate::isLoadedObject($cart)) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index c8fbc840a..d0cdc9094 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -203,7 +203,7 @@ abstract class PaymentModuleCore extends Module foreach ($products AS $key => $product) { $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')})); + $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']])) diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 6a479fa62..5d5d15588 100755 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -105,8 +105,8 @@ class AdminCartsController extends AdminController return; $customer = new Customer($cart->id_customer); $products = $cart->getProducts(); - $customizedDatas = Product::getAllCustomizedDatas((int)($cart->id)); - Product::addCustomizationPrice($products, $customizedDatas); + $customized_datas = Product::getAllCustomizedDatas((int)($cart->id)); + Product::addCustomizationPrice($products, $customized_datas); $summary = $cart->getSummaryDetails(); $currency = new Currency($cart->id_currency); @@ -153,8 +153,7 @@ class AdminCartsController extends AdminController $productObj = new Product($product['id_product']); $product['qty_in_stock'] = StockAvailable::getStockAvailableForProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int)$order->id_shop); - /* Customization display */ - //$this->displayCustomizedDatas($customizedDatas, $product, $currency, $image, $tokenCatalog, $stock); + $imageProduct = new Image($image['id_image']); $product['image'] = (isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.$imageProduct->getExistingImgPath().'.jpg', 'product_mini_'.(int)($product['id_product']).(isset($product['id_product_attribute']) ? '_'.(int)($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--'); } @@ -169,7 +168,8 @@ class AdminCartsController extends AdminController 'total_discounts' => $total_discounts, 'total_wrapping' => $total_wrapping, 'total_price' => $total_price, - 'total_shipping' => $total_shipping + 'total_shipping' => $total_shipping, + 'customized_datas' => $customized_datas )); } @@ -186,6 +186,8 @@ class AdminCartsController extends AdminController $this->context->cart->id_customer = $id_customer; if ($this->context->cart->OrderExists()) return; + if (!$this->context->cart->id_shop) + $this->context->cart->id_shop = (int)$this->context->shop->id; if (!$this->context->cart->id_lang) $this->context->cart->id_lang = (($id_lang = (int)Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT')); if (!$this->context->cart->id_currency) @@ -203,7 +205,6 @@ class AdminCartsController extends AdminController $this->context->cart->id_address_delivery = $addresses[0]['id_address']; elseif ($id_address_delivery) $this->context->cart->id_address_delivery = (int)$id_address_delivery; - $this->context->cart->save(); $currency = new Currency((int)$this->context->cart->id_currency); $this->context->currency = $currency; @@ -233,11 +234,15 @@ class AdminCartsController extends AdminController $errors[] = Tools::displayError('Invalid product'); elseif (!$qty = Tools::getValue('qty') OR $qty == 0) $errors[] = Tools::displayError('Invalid quantity'); - elseif (($id_product_attribute = Tools::getValue('id_product_attribute')) != 0 && !Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty((int)$id_product_attribute, (int)$qty)) - $errors[] = Tools::displayError('There is not enough product in stock'); - elseif (!$product->checkQty((int)$qty)) - $errors[] = Tools::displayError('There is not enough product in stock'); - elseif (!$id_customization = (int)Tools::getValue('id_customization', 0) AND !$product->hasAllRequiredCustomizableFields()) + if (($id_product_attribute = Tools::getValue('id_product_attribute')) != 0) + { + if(!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty((int)$id_product_attribute, (int)$qty)) + $errors[] = Tools::displayError('There is not enough product in stock'); + } + else + if(!$product->checkQty((int)$qty)) + $errors[] = Tools::displayError('There is not enough product in stock'); + if (!$id_customization = (int)Tools::getValue('id_customization', 0) AND !$product->hasAllRequiredCustomizableFields()) $errors[] = Tools::displayError('Please fill in all required fields'); $this->context->cart->save(); if (!count($errors)) @@ -321,6 +326,18 @@ class AdminCartsController extends AdminController $errors[] = Tools::displayError('Can\'t add the voucher'); echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors))); } + + public function ajaxProcessUpdateAddresses() + { + if (($id_address_delivery = (int)Tools::getValue('id_address_delivery')) && $address_delivery = new Address((int)$id_address_delivery) && $address_delivery->id_customer = $this->context->cart->id_customer) + $this->context->cart->id_address_delivery = (int)$address_delivery->id; + + if (($id_address_invoice = (int)Tools::getValue('id_address_invoice')) && $address_invoice = new Address((int)$id_address_invoice) && $address_invoice->id_customer = $this->context->cart->id_customer) + $this->context->cart->id_address_invoice = (int)$address_invoice->id; + $this->context->cart->save(); + + echo Tools::jsonEncode($this->ajaxReturnVars()); + } protected function getCartSummary() { diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 4d9364343..717243e00 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -32,7 +32,7 @@ class AdminOrdersControllerCore extends AdminController $this->table = 'order'; $this->className = 'Order'; $this->lang = false; - + $this->edit = true; $this->addRowAction('view'); $this->deleted = false; @@ -74,18 +74,20 @@ class AdminOrdersControllerCore extends AdminController parent::__construct(); } - - public function initContent() + + public function initForm() { - $this->display = 'list'; - - if (Tools::isSubmit('view'.$this->table)) - { - $this->display = 'view'; - $this->viewOrder(); - } - - parent::initContent(); + parent::initForm(); + $this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch')); + $cart = new Cart((int)Tools::getValue('id_cart')); + $this->context->smarty->assign(array('recyclable_pack' => (int)Configuration::get('PS_RECYCLABLE_PACK'), + 'gift_wrapping' => (int)Configuration::get('PS_GIFT_WRAPPING'), + 'cart' => $cart, + 'currencies' => Currency::getCurrencies(), + 'langs' => Language::getLanguages(true, Context::getContext()->shop->id), + 'payment_modules' => PaymentModule::getInstalledPaymentModules(), + 'order_states' => OrderState::getOrderStates((int)Context::getContext()->cookie->id_lang))); + $this->content .= $this->context->smarty->fetch('orders/form.tpl'); } public function printPDFIcons($id_order, $tr) @@ -445,6 +447,19 @@ class AdminOrdersControllerCore extends AdminController unset($order, $pcc); } + 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'))) + { + if ($this->tabAccess['edit'] === '1') + { + $payment_module = Module::getInstanceByName($module_name); + $cart = new Cart((int)$id_cart); + $payment_module->validateOrder((int)$cart->id, (int)$id_order_state, $cart->getOrderTotal(true, Cart::BOTH), $payment_module->displayName, $this->l(sprintf('Manual order - ID Employee :%1', (int)Context::getContext()->cookie->id_employee))); + if($payment_module->currentOrder) + Tools::redirectAdmin(self::$currentIndex.'&id_order='.$payment_module->currentOrder.'&vieworder'.'&token='.$this->token); + } + else + $this->_errors[] = Tools::displayError('You do not have permission to add here.'); + } parent::postProcess(); } @@ -536,4 +551,71 @@ class AdminOrdersControllerCore extends AdminController 'HOOK_ADMIN_ORDER' => Module::hookExec('adminOrder', array('id_order' => $order->id)) )); } + public function ajaxProcessSearchCustomers() + { + if ($customers = Customer::searchByName(pSQL(Tools::getValue('customer_search')))) + $to_return = array('customers' => $customers, + 'found' => true); + else + $to_return = array('found' => false); + + $this->content = Tools::jsonEncode($to_return); + } + + public function ajaxProcessSearchProducts() + { + $currency = new Currency((int)Tools::getValue('id_currency')); + if ($products = Product::searchByName((int)$this->context->language->id, pSQL(Tools::getValue('product_search')))) + { + foreach ($products AS &$product) + { + $product['price'] = Tools::displayPrice(Tools::convertPrice($product['price'], $currency), $currency); + $productObj = new Product((int)$product['id_product'], false, (int)$this->context->language->id); + $combinations = array(); + $attributes = $productObj->getAttributesGroups((int)$this->context->language->id); + $product['qty_in_stock'] = StockAvailable::getStockAvailableForProduct((int)$product['id_product'], 0, (int)$this->context->shop->getID()); + foreach($attributes AS $attribute) + { + if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) + $combinations[$attribute['id_product_attribute']]['attributes'] = ''; + $combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'].' - '; + $combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute']; + $combinations[$attribute['id_product_attribute']]['default_on'] = $attribute['default_on']; + if (!isset($combinations[$attribute['id_product_attribute']]['price'])) + $combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int)$product['id_product'], true, $attribute['id_product_attribute']), $currency), $currency); + if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock'])) + $combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getStockAvailableForProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID()); + } + + foreach ($combinations AS &$combination) + $combination['attributes'] = rtrim($combination['attributes'], ' - '); + $product['combinations'] = $combinations; + } + $to_return = array('products' => $products, + 'found' => true); + } + else + $to_return = array('found' => false); + + $this->content = Tools::jsonEncode($to_return); + } + + public function ajaxProcessSendMailValidateOrder() + { + $errors = array(); + $cart = new Cart((int)Tools::getValue('id_cart')); + if (Validate::isLoadedObject($cart)) + { + $customer = new Customer((int)$cart->id_customer); + if (Validate::isLoadedObject($customer)) + { + $mailVars = array('{order_link}' => Context::getContext()->link->getPageLink('order', false, (int)$cart->id_lang, 'step=3&recover_cart='.(int)$cart->id.'&token_cart='.md5(_COOKIE_KEY_.'recover_cart_'.(int)$cart->id)), + '{firstname}' => $customer->firstname, + '{lastname}' => $customer->lastname,); + if (Mail::Send((int)$cart->id_lang, 'backoffice_order', Mail::l('Process the payment of your order'), $mailVars, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL,_PS_MAIL_DIR_, true)) + die(Tools::jsonEncode(array('errors' => false, 'result' => $this->l('The mail was sent to your customer.')))); + } + } + $this->content = Tools::jsonEncode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.'))); + } } diff --git a/css/admin.css b/css/admin.css index 900a1412c..6b4728850 100644 --- a/css/admin.css +++ b/css/admin.css @@ -1715,3 +1715,43 @@ div.progressBarImage #menu .submenu_size .submenu { display: none; position:absolute} #menu .submenu_size:hover > .submenu { display: block; } .submenu li{float:none;clear:left;} +#customer_part #customers ul { + float:left; +} +#customer_part #customers ul li { + display:inline; + list-style-type: none; + float:left; + margin:10px; +} +#customer_part #customers ul li .id_customer { + font-weight:bold; + color:green; +} +#products_part #products_found { + display:none; +} +#vouchers_part #voucher_list { + display:none; +} +#vouchers_part #vouchers_err { + display:none; +} +#loader_container { + display:none; + z-index: 100; + position: absolute; + top: 0; + left: 0; + height: 100%; + width: 100%; + background:transparent url('../img/bg_loader.png') repeat 0 0; +} +#loader { + display:none; + margin: 0 auto; + height:24px; + width:24px; + color:#fff; + background:url(../img/loader.gif); +} \ No newline at end of file