Finished combination creation GUI

This commit is contained in:
franck
2013-09-23 11:41:14 +02:00
parent 915516e679
commit e7974a21a7
8 changed files with 740 additions and 487 deletions

View File

@@ -223,6 +223,19 @@
<default key="_controller">Thelia\Controller\Admin\ProductController::updateAttributesAndFeaturesAction</default>
</route>
<!-- Combinations -->
<route id="admin.product.attribute-values" path="/admin/product/{productId}/attribute-values/{attributeId}.{_format}" methods="GET">
<default key="_controller">Thelia\Controller\Admin\ProductController::getAttributeValuesAction</default>
<requirement key="_format">xml|json</requirement>
</route>
<route id="admin.product.add-attribute-value-to-combination" path="/admin/product/{productId}/add-attribute-value-to-combination/{attributeAvId}/{combination}.{_format}" methods="GET">
<default key="_controller">Thelia\Controller\Admin\ProductController::addAttributeValueToCombinationAction</default>
<requirement key="_format">xml|json</requirement>
</route>
<!-- Folder routes management -->

View File

@@ -51,6 +51,8 @@ use Thelia\Core\Event\ProductSetTemplateEvent;
use Thelia\Model\Base\ProductSaleElementsQuery;
use Thelia\Core\Event\ProductAddCategoryEvent;
use Thelia\Core\Event\ProductDeleteCategoryEvent;
use Thelia\Model\AttributeQuery;
use Thelia\Model\AttributeAvQuery;
/**
* Manages products
@@ -668,4 +670,72 @@ class ProductController extends AbstractCrudController
$this->redirectToEditionTemplate();
}
// -- Product combination management ---------------------------------------
public function getAttributeValuesAction($productId, $attributeId) {
$result = array();
// Get attribute for this product
$attribute = AttributeQuery::create()->findPk($attributeId);
if ($attribute !== null) {
$values = AttributeAvQuery::create()
->joinWithI18n($this->getCurrentEditionLocale())
->filterByAttribute($attribute)
->find();
;
if ($values !== null) {
foreach($values as $value) {
$result[] = array('id' => $value->getId(), 'title' => $value->getTitle());
}
}
}
return $this->jsonResponse(json_encode($result));
}
public function addAttributeValueToCombinationAction($productId, $attributeAvId, $combination) {
$result = array();
// Get attribute for this product
$attributeAv = AttributeAvQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($attributeAvId);
if ($attributeAv !== null) {
$addIt = true;
// Check if this attribute is not already present
$combinationArray = explode(',', $combination);
foreach ($combinationArray as $id) {
$attrAv = AttributeAvQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($id);
if ($attrAv !== null) {
if ($attrAv->getAttributeId() == $attributeAv->getAttributeId()) {
$attribute = AttributeQuery::create()->joinWithI18n($this->getCurrentEditionLocale())->findPk($attributeAv->getAttributeId());
$result['error'] = $this->getTranslator()->trans(
'A value for attribute "%name" is already present in the combination',
array('%name' => $attribute->getTitle())
);
$addIt = false;
}
$result[] = array('id' => $attrAv->getId(), 'title' => $attrAv->getTitle());
}
}
if ($addIt) $result[] = array('id' => $attributeAv->getId(), 'title' => $attributeAv->getTitle());
}
return $this->jsonResponse(json_encode($result));
}
}

View File

@@ -11,7 +11,7 @@
<div class="row">
<div class="col-md-12">
<div class="well">
<div class="well well-sm">
<p>{intl
l="To use features or attributes on this product, please select a product template. You can define product templates in the <a href=\"%tpl_mgmt_url\" target=\"tpl_window\">configuration section</a> of the administration."
tpl_mgmt_url={url path='/admin/configuration/templates'}
@@ -45,7 +45,6 @@
<div class="row">
<div class="col-md-12">
<p class="title title-without-tabs">{intl l='Product Attributes and Features'}</p>
<form method="POST" action="{url path="/admin/product/$ID/update-attributes-and-features"}" id="attribute_form">
@@ -64,6 +63,7 @@
<div class="row">
<div class="col-md-12">
<div class="well well-sm">
<div class="form-group">
<p class="title title-without-tabs">{intl l='Product Attributes'}</p>
@@ -118,11 +118,13 @@
</div>
</div>
</div>
</div>
{* -- Begin features management ---------------------------------- *}
<div class="row">
<div class="col-md-12">
<div class="well well-sm">
<div class="form-group">
<p class="title title-without-tabs">{intl l='Product Features'}</p>
@@ -224,6 +226,7 @@
</div>
</div>
</div>
</div>
</div>
</form>
</div>

View File

@@ -14,6 +14,7 @@
{* -- Begin related content management ------------------------------ *}
<div class="col-md-6">
<div class="well well-sm">
<div class="form-group">
<form method="POST" action="{url path='/admin/products/content/add'}" id="related_content_form">
@@ -125,12 +126,14 @@
</table>
</div>
</div>
</div>
{* -- End related content management -------------------------------- *}
{* -- Begin accessories management ---------------------------------- *}
<div class="col-md-6">
<div class=" well well-sm">
<div class="form-group">
<form method="POST" action="{url path='/admin/products/accessory/add'}" id="accessory_form">
@@ -243,6 +246,7 @@
</table>
</div>
</div>
</div>
{* -- End accessories management ------------------------------------ *}
@@ -253,6 +257,7 @@
{* -- Begin categories management ----------------------------------- *}
<div class="col-md-6">
<div class="well well-sm">
<div class="form-group">
<form method="POST" action="{url path='/admin/products/category/add'}" id="related_content_form">
@@ -347,6 +352,7 @@
</table>
</div>
</div>
</div>
{* -- End categories management ------------------------------------- *}
</div>
@@ -473,7 +479,7 @@ $(function() {
}
});
// Load content on folder selection
// Load accessory on category selection
$('#accessory_category_id').change(function(event) {
var val = $(this).val();

View File

@@ -22,8 +22,8 @@ Parameters:
</ul>
</div>
{if $show_currencies == true}
<div class="col-md-3 inner-actions">
{if $show_currencies == true}
<div class="row">
<div class="col-md-12">
<div class="button-group">
@@ -35,8 +35,8 @@ Parameters:
</div>
</div>
</div>
</div>
{/if}
</div>
<div class="col-md-6 inner-actions">
{if $hide_submit_buttons != true}

View File

@@ -42,7 +42,7 @@
{* -- Pricing ------------------------------------------------------- *}
<div class="col-md-4">
<div class="well well-sm">
<p class="title title-without-tabs">{intl l='Pricing'}</p>
<p></p> <!-- LAME !!! FIXME -->
@@ -85,12 +85,13 @@
{module_include location='product_details_pricing_form'}
</div>
</div>
{* -- Promotion ------------------------------------------------- *}
<div class="col-md-4">
<div class="well well-sm">
<p class="title title-without-tabs">{intl l='Promotion'}</p>
{form_field form=$form field='sale_price'}
@@ -128,11 +129,13 @@
{module_include location='product_details_promotion_form'}
</div>
</div>
{* -- Shipping -------------------------------------------------- *}
<div class="col-md-4">
<div class="well well-sm">
<p class="title title-without-tabs">{intl l='Shipping'}</p>
{form_field form=$form field='weight'}
@@ -146,6 +149,8 @@
</div>
{/form_field}
{module_include location='product_details_shipping_form'}
<p class="title title-without-tabs">{intl l='Quantity'}</p>
{form_field form=$form field='quantity'}
@@ -158,9 +163,11 @@
</div>
{/form_field}
{module_include location='product_details_shipping_form'}
{module_include location='product_details_quantity_form'}
</div>
</div>
</div>
</form>
{/form}
@@ -171,11 +178,76 @@
<p class="title title-without-tabs">{intl l='Attribute Combinations'}</p>
<div class="alert alert-info">
{intl l="This product has no attribute combination"}
{module_include location='product_before_combinations'}
{ifloop rel="product-attributes"}
<form method="POST" action="{url path='/admin/products/combinations/save'}" {form_enctype form=$form} class="clearfix">
<div class="well well-sm">
<p class="title title-without-tabs">{intl l='Create a new combination'}</p>
<div class="form-group">
<label class="control-label">{intl l="Attribute"} : </label>
<select required="required" name="attribute_id" id="attribute_id" class="form-control">
<option value="">{intl l='Select an attribute...'}</option>
{loop name="product-attributes" type="attribute" product=$product_id backend_context="1" lang=$edit_language_id}
<option value="{$ID}">{$TITLE}</option>
{/loop}
</select>
<span class="help-block">{intl l='Select an attribute and click (+) to view available values'}</span>
</div>
<div id="attribute_value_selector" class="hide">
<div class="input-group">
{* <label class="control-label">{intl l="Attribute values"} : </label> *}
<select required="required" name="attribute_value_id" id="attribute_value_id" class="form-control">
<option value="">{intl l='Select an attribute value...'}</option>
</select>
<span class="input-group-btn" id="add_attr_value_button">
<button class="btn btn-default btn-primary action-btn add-value-to-combination" type="button"><span class="glyphicon glyphicon-plus-sign"></span></button>
</span>
</div>
<span class="help-block">{intl l='Select a value click (+) to add it to the combination'}</span>
</div>
<div id="attribute_value_selector_empty" class="hide">
<div class="alert alert-info">
{intl l="No available value for this attribute"}
</div>
</div>
<div class="form-group">
<div class="alert alert-danger hide" id="combination_attributes_error"></div>
<select multiple="multiple" size="5" name="combination_attributes" id="combination_attributes" class="form-control">
</select>
<div class="help-block">
{intl l='To remove a value from the combination, select it and click "remove"'}
<div class="pull-right">
<button class="btn btn-info btn-xs remove-value-from-combination" type="button">
{intl l="Remove selected value"} <span class="glyphicon glyphicon-minus-sign"></span>
</button>
</div>
</div>
</div>
</div>
</form>
{/ifloop}
{elseloop rel="product-attributes"}
<div class="alert alert-info">
{intl l="No attributes are attached to this product."}
</div>
{/elseloop}
{module_include location='product_after_combinations'}
</div> {* com *}
</div> {* row *}
</div>

View File

@@ -144,6 +144,93 @@ $(function() {
// Load active tab
$('.nav-tabs a[href="#{$current_tab}"]').trigger("click");
// -- Product details management tab ---------------------------------------
// Load value on attribute selection
$('#attribute_id').change(function(event) {
var val = $(this).val();
if (val != "") {
$.ajax({
url : '{url path="/admin/product/$product_id/attribute-values/"}' + $(this).val() + '.xml',
type : 'get',
dataType : 'json',
success : function(json) {
$('#attribute_value_id :not(:first-child)').remove();
var have_content = false;
$.each(json, function(idx, value) {
$('#attribute_value_id').append($('<option>').text(value.title).attr('value', value.id));
have_content = true; // Lame...
});
if (have_content) {
$('#attribute_value_selector_empty').addClass('hide');
$('#attribute_value_selector').removeClass('hide');
}
else {
$('#attribute_value_selector_empty').removeClass('hide');
$('#attribute_value_selector').addClass('hide');
}
}
});
}
else {
$('#attribute_value_selector_empty').addClass('hide');
$('#attribute_value_selector').addClass('hide');
}
});
// Add selected value to the combination
$('.add-value-to-combination').click(function(event) {
// Hide error message
$('#combination_attributes_error').text('').addClass('hide');
// Select all elements
$('#combination_attributes option').prop('selected', 'selected');
$.ajax({
url : '{url path="/admin/product/$product_id/add-attribute-value-to-combination/"}'
+ $('#attribute_value_id').val()
+ '/'
+ $('#combination_attributes').val()
+ '.xml',
type : 'get',
dataType : 'json',
success : function(json) {
$('#combination_attributes option').remove();
var have_content = false;
$.each(json, function(idx, value) {
if (idx != 'error')
$('#combination_attributes').append($('<option>').text(value.title).attr('value', value.id));
});
if (json.error)
$('#combination_attributes_error').text(json.error).removeClass('hide');
$('#attribute_id').val('').change();
}
});
event.preventDefault();
});
// Remove selected value from combination
$('.remove-value-from-combination').click(function() {
$('#combination_attributes option:selected').remove();
event.preventDefault();
});
});
</script>
{/block}

View File

@@ -59,20 +59,23 @@
{/form}
</div>
</div>
</div>
<div class="col-md-12">
<div class="row">
<div class="form-container">
<div class="col-md-6">
<div class="well well-sm">
<p class="title title-without-tabs">{intl l='Attributes'}</p>
<p>Manage attributes included in this product templates</p>
<div id="attribute_list_management">
<div class="loading"></div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="well well-sm">
<p class="title title-without-tabs">{intl l='Features'}</p>
<p>Manage features included in this product templates</p>
@@ -82,7 +85,6 @@
</div>
</div>
</div>
</div>
</div>