From efd35f4f87a67fad8355a2869510f9b08eaaa158 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Wed, 9 May 2012 14:04:13 +0000 Subject: [PATCH] [+] BO: The customizable products are now usable in the BackOffice order --- .../template/controllers/orders/form.tpl | 75 ++++++++++++++++--- .../orders/form_customization_feedback.tpl | 52 +++++++++++++ classes/Product.php | 4 +- controllers/admin/AdminCartsController.php | 59 ++++++++++++++- controllers/admin/AdminOrdersController.php | 7 ++ 5 files changed, 184 insertions(+), 13 deletions(-) create mode 100644 admin-dev/themes/default/template/controllers/orders/form_customization_feedback.tpl diff --git a/admin-dev/themes/default/template/controllers/orders/form.tpl b/admin-dev/themes/default/template/controllers/orders/form.tpl index da9b1f587..ade046406 100755 --- a/admin-dev/themes/default/template/controllers/orders/form.tpl +++ b/admin-dev/themes/default/template/controllers/orders/form.tpl @@ -29,6 +29,7 @@ var changed_shipping_price = false; var shipping_price_selected_carrier = ''; var current_index = '{$current}&token={$token}'; + var admin_cart_link = '{$link->getAdminLink('AdminCarts')}'; var cart_quantity = new Array(); var currencies = new Array(); var id_currency = ''; @@ -36,6 +37,7 @@ var txt_show_carts = '{l s='Show carts and orders for this customer'}'; var txt_hide_carts = '{l s='Hide carts and orders for this customer'}'; var defaults_order_state = new Array(); + var customization_errors = false; {foreach from=$defaults_order_state key='module' item='id_order_state'} defaults_order_state['{$module}'] = '{$id_order_state}'; {/foreach} @@ -524,33 +526,55 @@ { var products_found = ''; var attributes_html = ''; + var customization_html = ''; stock = {}; if(res.found) { $('#products_err').hide(); $('#products_found').show(); - products_found += ''; attributes_html += ''; $.each(res.products, function() { products_found += ''; attributes_html += ''; + if (this.required == 1) + customization_html += '*'; + customization_html += this.name+'{l s=':'}'; + if (this.type == 0) + customization_html += ''; + else if (this.type == 1) + customization_html += ''; + customization_html += '

'; + }); + customization_html += ''; + } $.each(this.combinations, function() { attributes_html += ''; }); stock[this.id_product] = this.stock; - + attributes_html += ''; }); - products_found += ''; - $('#products_found #product_list').html(products_found); $('#products_found #attributes_list').html(attributes_html); - displayProductAttributes(); + $('#products_found #customization_list').contents().find('body').html(customization_html); + display_product_attributes(); + display_product_customizations(); $('#id_product').change(); } else @@ -563,8 +587,21 @@ } }); } - - function displayProductAttributes() + + function display_product_customizations() + { + if ($('#products_found #customization_list').contents().find('#customization_'+$('#id_product option:selected').val()).children().length === 0) + $('#customization_list').hide(); + else + { + $('#customization_list').show(); + $('#products_found #customization_list').contents().find('.id_customization').hide(); + $('#products_found #customization_list').contents().find('#customization_'+$('#id_product option:selected').val()).show(); + $('#products_found #customization_list').css('height',$('#products_found #customization_list').contents().find('#customization_'+$('#id_product option:selected').val()).height()+95+'px'); + } + } + + function display_product_attributes() { if ($('#ipa_'+$('#id_product option:selected').val()+' option').length === 0) $('#attributes_list').hide(); @@ -672,7 +709,7 @@ id_product_attribute: id_product_attribute, qty: qty, id_customer: id_customer, - id_cart: id_cart + id_cart: id_cart, }, success : function(res) { @@ -701,7 +738,14 @@ function addProduct() { var id_product = $('#id_product option:selected').val(); - updateQty(id_product, $('#ipa_'+id_product+' option:selected').val(), $('#qty').val()); + $('#products_found #customization_list').contents().find('#customization_'+id_product).submit(); + if (customization_errors) + $('#products_err').show(); + else + { + $('#products_err').hide(); + updateQty(id_product, $('#ipa_'+id_product+' option:selected').val(), $('#qty').val()); + } } function updateCurrency() @@ -883,6 +927,19 @@
+

 {l s='In stock:'} 

diff --git a/admin-dev/themes/default/template/controllers/orders/form_customization_feedback.tpl b/admin-dev/themes/default/template/controllers/orders/form_customization_feedback.tpl new file mode 100644 index 000000000..f530a4638 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/orders/form_customization_feedback.tpl @@ -0,0 +1,52 @@ +{* +* 2007-2012 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-2012 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 +*} + + +{if isset($css_files)} + {foreach from=$css_files key=css_uri item=media} + + {/foreach} +{/if} + + + + + diff --git a/classes/Product.php b/classes/Product.php index 8774caf45..8db780c65 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3057,7 +3057,7 @@ class ProductCore extends ObjectModel $context = Context::getContext(); $sql = new DbQuery(); - $sql->select('p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`, product_shop.advanced_stock_management'); + $sql->select('p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`, product_shop.advanced_stock_management, p.`customizable`'); $sql->from('category_product', 'cp'); $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`'); $sql->join(Shop::addSqlAssociation('product', 'p')); @@ -3886,7 +3886,7 @@ class ProductCore extends ObjectModel if (!Customization::isFeatureActive()) return array(); return Db::getInstance()->executeS(' - SELECT `id_customization_field`, `type` + SELECT `id_customization_field`, `type`, `required` FROM `'._DB_PREFIX_.'customization_field` WHERE `id_product` = '.(int)$this->id); } diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index dd32d550b..c2359d3d5 100755 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -239,7 +239,63 @@ class AdminCartsControllerCore extends AdminController echo Tools::jsonEncode($this->ajaxReturnVars()); } } - + + public function ajaxProcessUpdateCustomizationFields() + { + $errors = array(); + if ($this->tabAccess['edit'] === '1') + { + if (!$this->context->cart->id || (!$id_product = (int)Tools::getValue('id_product'))) + return; + $product = new Product((int)$id_product); + if (!$customization_fields = $product->getCustomizationFieldIds()) + return; + foreach ($customization_fields as $customization_field) + { + $field_id = 'customization_'.$id_product.'_'.$customization_field['id_customization_field']; + if ($customization_field['type'] == Product::CUSTOMIZE_TEXTFIELD) + { + if (!isset($_POST[$field_id])) + { + if ($customization_field['required']) + $errors[] = Tools::displayError('Please fill in all required fields'); + continue; + } + if (!Validate::isMessage($_POST[$field_id]) || empty($_POST[$field_id])) + $errors[] = Tools::displayError('Invalid message'); + $this->context->cart->addTextFieldToProduct((int)$product->id, (int)$customization_field['id_customization_field'], Product::CUSTOMIZE_TEXTFIELD, $_POST[$field_id]); + } + elseif ($customization_field['type'] == Product::CUSTOMIZE_FILE) + { + if (!isset($_FILES[$field_id]) || !isset($_FILES[$field_id]['tmp_name']) || empty($_FILES[$field_id]['tmp_name'])) + { + if ($customization_field['required']) + $errors[] = Tools::displayError('Please fill in all required fields'); + continue; + } + if ($error = ImageManager::validateUpload($_FILES[$field_id], (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'))) + $errors[] = $error; + if (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES[$field_id]['tmp_name'], $tmp_name)) + $errors[] = Tools::displayError('An error occurred during the image upload.'); + $file_name = md5(uniqid(rand(), true)); + if (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_.$file_name)) + continue; + elseif (!ImageManager::resize($tmp_name, _PS_UPLOAD_DIR_.$file_name.'_small', (int)Configuration::get('PS_PRODUCT_PICTURE_WIDTH'), (int)Configuration::get('PS_PRODUCT_PICTURE_HEIGHT'))) + $errors[] = Tools::displayError('An error occurred during the image upload.'); + elseif (!chmod(_PS_UPLOAD_DIR_.$file_name, 0777) || !chmod(_PS_UPLOAD_DIR_.$file_name.'_small', 0777)) + $errors[] = Tools::displayError('An error occurred during the image upload.'); + else + $this->context->cart->addPictureToProduct((int)$product->id, (int)$customization_field['id_customization_field'], Product::CUSTOMIZE_FILE, $file_name); + unlink($tmp_name); + } + } + $this->setMedia(); + $this->initFooter(); + $this->context->smarty->assign('customization_errors', implode('
', $errors)); + return $this->context->smarty->display('controllers/orders/form_customization_feedback.tpl'); + } + } + public function ajaxProcessUpdateQty() { if ($this->tabAccess['edit'] === '1') @@ -548,7 +604,6 @@ class AdminCartsControllerCore extends AdminController public function ajaxReturnVars() { $id_cart = (int)$this->context->cart->id; - $message_content = ''; if ($message = Message::getMessageByCartId((int)$this->context->cart->id)) $message_content = $message['message']; diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 7ab4f59fe..b94ea219d 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1340,7 +1340,14 @@ class AdminOrdersControllerCore extends AdminController foreach ($combinations as &$combination) $combination['attributes'] = rtrim($combination['attributes'], ' - '); $product['combinations'] = $combinations; + + if ($product['customizable']) + { + $product_instance = new Product((int)$product['id_product']); + $product['customization_fields'] = $product_instance->getCustomizationFields($this->context->language->id); + } } + $to_return = array( 'products' => $products, 'found' => true