[+] BO: The customizable products are now usable in the BackOffice order

This commit is contained in:
rGaillard
2012-05-09 14:04:13 +00:00
parent 255c92b2bf
commit efd35f4f87
5 changed files with 184 additions and 13 deletions
@@ -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 += '<label>{l s='Product:'}</label><select id="id_product" onclick="displayProductAttributes();">';
products_found += '<label>{l s='Product:'}</label><select id="id_product" onclick="display_product_attributes();display_product_customizations();">';
attributes_html += '<label>{l s='Combination:'}</label>';
$.each(res.products, function() {
products_found += '<option '+(this.combinations.length > 0 ? 'rel="'+this.qty_in_stock+'"' : '')+' value="'+this.id_product+'">'+this.name+(this.combinations.length == 0 ? ' - '+this.formatted_price : '')+'</option>';
attributes_html += '<select class="id_product_attribute" id="ipa_'+this.id_product+'" style="display:none;">';
var id_product = this.id_product;
if (this.customizable == '1')
{
customization_html += '<fieldset class="width3"><legend>{l s='Customization'}</legend><form id="customization_'+id_product+'" class="id_customization" method="post" enctype="multipart/form-data" action="'+admin_cart_link+'" style="display:none;">';
customization_html += '<input type="hidden" name="id_product" value="'+id_product+'"';
customization_html += '<input type="hidden" name="id_cart" value="'+id_cart+'"';
customization_html += '<input type="hidden" name="action" value="updateCustomizationFields"';
customization_html += '<input type="hidden" name="id_customer" value="'+id_customer+'"';
customization_html += '<input type="hidden" name="ajax" value="1"';
$.each(this.customization_fields, function() {
customization_html += '<p><label for="customization_'+id_product+'_'+this.id_customization_field+'">';
if (this.required == 1)
customization_html += '<sup>*</sup>';
customization_html += this.name+'{l s=':'}</label>';
if (this.type == 0)
customization_html += '<input class="customization_field" type="file" name="customization_'+id_product+'_'+this.id_customization_field+'" id="customization_'+id_product+'_'+this.id_customization_field+'">';
else if (this.type == 1)
customization_html += '<input class="customization_field" type="text" name="customization_'+id_product+'_'+this.id_customization_field+'" id="customization_'+id_product+'_'+this.id_customization_field+'">';
customization_html += '</p>';
});
customization_html += '</fieldset></form>';
}
$.each(this.combinations, function() {
attributes_html += '<option rel="'+this.qty_in_stock+'" '+(this.default_on == 1 ? 'selected="selected"' : '')+' value="'+this.id_product_attribute+'">'+this.attributes+' - '+this.formatted_price+'</option>';
});
stock[this.id_product] = this.stock;
attributes_html += '</select>';
});
products_found += '</select>';
$('#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 @@
</div>
<div id="attributes_list">
</div>
<iframe id="customization_list" style="border:0px;overflow:hidden;width:100%">
<html>
<head>
{if isset($css_files_orders)}
{foreach from=$css_files_orders key=css_uri item=media}
<link href="{$css_uri}" rel="stylesheet" type="text/css" media="{$media}" />
{/foreach}
{/if}
</head>
<body>
</body>
</html>
</iframe>
<p><label for="qty">{l s='Quantity:'}</label><input type="text" name="qty" id="qty" value="1" />&nbsp;<b>{l s='In stock:'}</b>&nbsp;<span id="qty_in_stock"></span></p>
<div class="margin-form">
<p><input type="submit" onclick="addProduct();return false;" class="button" id="submitAddProduct" value="{l s='Add to cart'}"/></p>
@@ -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 <contact@prestashop.com>
* @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
*}
<html>
<head>
{if isset($css_files)}
{foreach from=$css_files key=css_uri item=media}
<link href="{$css_uri}" rel="stylesheet" type="text/css" media="{$media}" />
{/foreach}
{/if}
</head>
<body>
<script type="text/javascript">
{if $customization_errors|count}
customization_errors = true;
var id_selected_product = parent.$('#id_product option:selected').val();
if (parent.searchProducts())
{
parent.$('#products_err', window.parent.document).html('{$customization_errors}');
parent.$('#id_product option[value="'+id_selected_product+'"]').attr('selected', true);
parent.$('#id_product').change();
}
{else}
parent.$('#products_err', window.parent.document).hide();
customization_errors = false;
{/if}
</script>
</body>
</html>
+2 -2
View File
@@ -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);
}
+57 -2
View File
@@ -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('<br />', $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'];
@@ -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