Merge branch 'master' of github.com:thelia/thelia
This commit is contained in:
@@ -157,23 +157,6 @@ class AttributeController extends AbstractCrudController
|
||||
'postscriptum' => $object->getPostscriptum()
|
||||
);
|
||||
|
||||
// Setup attributes values
|
||||
/*
|
||||
* FIXME : doesn't work. "We get a This form should not contain extra fields." error
|
||||
$attr_av_list = AttributeAvQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->filterByAttributeId($object->getId())
|
||||
->find();
|
||||
|
||||
$attr_array = array();
|
||||
|
||||
foreach ($attr_av_list as $attr_av) {
|
||||
$attr_array[$attr_av->getId()] = $attr_av->getTitle();
|
||||
}
|
||||
|
||||
$data['attribute_values'] = $attr_array;
|
||||
*/
|
||||
|
||||
// Setup the object form
|
||||
return new AttributeModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
@@ -157,23 +157,6 @@ class FeatureController extends AbstractCrudController
|
||||
'postscriptum' => $object->getPostscriptum()
|
||||
);
|
||||
|
||||
// Setup features values
|
||||
/*
|
||||
* FIXME : doesn't work. "We get a This form should not contain extra fields." error
|
||||
$attr_av_list = FeatureAvQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->filterByFeatureId($object->getId())
|
||||
->find();
|
||||
|
||||
$attr_array = array();
|
||||
|
||||
foreach ($attr_av_list as $attr_av) {
|
||||
$attr_array[$attr_av->getId()] = $attr_av->getTitle();
|
||||
}
|
||||
|
||||
$data['feature_values'] = $attr_array;
|
||||
*/
|
||||
|
||||
// Setup the object form
|
||||
return new FeatureModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
@@ -136,9 +136,9 @@ class FileController extends BaseAdminController
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Saving images for %parentName% parent id %parentId% (%parentType%)',
|
||||
array(
|
||||
'%parentName%' => $event->getParentName(),
|
||||
'%parentId%' => $event->getParentId(),
|
||||
'%parentType%' => $event->getImageType()
|
||||
'%parentName%' => $imageCreateOrUpdateEvent->getParentName(),
|
||||
'%parentId%' => $imageCreateOrUpdateEvent->getParentId(),
|
||||
'%parentType%' => $imageCreateOrUpdateEvent->getImageType()
|
||||
),
|
||||
'image'
|
||||
)
|
||||
@@ -214,9 +214,9 @@ class FileController extends BaseAdminController
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Saving documents for %parentName% parent id %parentId% (%parentType%)',
|
||||
array(
|
||||
'%parentName%' => $event->getParentName(),
|
||||
'%parentId%' => $event->getParentId(),
|
||||
'%parentType%' => $event->getDocumentType()
|
||||
'%parentName%' => $documentCreateOrUpdateEvent->getParentName(),
|
||||
'%parentId%' => $documentCreateOrUpdateEvent->getParentId(),
|
||||
'%parentType%' => $documentCreateOrUpdateEvent->getDocumentType()
|
||||
),
|
||||
'document'
|
||||
)
|
||||
@@ -549,8 +549,8 @@ class FileController extends BaseAdminController
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Deleting image for %id% with parent id %parentId%',
|
||||
array(
|
||||
'%id%' => $event->getDocumentToDelete()->getId(),
|
||||
'%parentId%' => $event->getDocumentToDelete()->getParentId(),
|
||||
'%id%' => $imageDeleteEvent->getImageToDelete()->getId(),
|
||||
'%parentId%' => $imageDeleteEvent->getImageToDelete()->getParentId(),
|
||||
),
|
||||
'image'
|
||||
)
|
||||
@@ -562,8 +562,8 @@ class FileController extends BaseAdminController
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Fail to delete image for %id% with parent id %parentId% (Exception : %e%)',
|
||||
array(
|
||||
'%id%' => $event->getDocumentToDelete()->getId(),
|
||||
'%parentId%' => $event->getDocumentToDelete()->getParentId(),
|
||||
'%id%' => $imageDeleteEvent->getImageToDelete()->getId(),
|
||||
'%parentId%' => $imageDeleteEvent->getImageToDelete()->getParentId(),
|
||||
'%e%' => $e->getMessage()
|
||||
),
|
||||
'image'
|
||||
@@ -621,8 +621,8 @@ class FileController extends BaseAdminController
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Deleting document for %id% with parent id %parentId%',
|
||||
array(
|
||||
'%id%' => $event->getDocumentToDelete()->getId(),
|
||||
'%parentId%' => $event->getDocumentToDelete()->getParentId(),
|
||||
'%id%' => $documentDeleteEvent->getDocumentToDelete()->getId(),
|
||||
'%parentId%' => $documentDeleteEvent->getDocumentToDelete()->getParentId(),
|
||||
),
|
||||
'document'
|
||||
)
|
||||
@@ -634,8 +634,8 @@ class FileController extends BaseAdminController
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Fail to delete document for %id% with parent id %parentId% (Exception : %e%)',
|
||||
array(
|
||||
'%id%' => $event->getDocumentToDelete()->getId(),
|
||||
'%parentId%' => $event->getDocumentToDelete()->getParentId(),
|
||||
'%id%' => $documentDeleteEvent->getDocumentToDelete()->getId(),
|
||||
'%parentId%' => $documentDeleteEvent->getDocumentToDelete()->getParentId(),
|
||||
'%e%' => $e->getMessage()
|
||||
),
|
||||
'document'
|
||||
|
||||
@@ -64,6 +64,8 @@ use Thelia\Model\Country;
|
||||
use Thelia\Tools\NumberFormat;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Form\ProductCombinationGenerationForm;
|
||||
use Thelia\Core\Event\Product\ProductCombinationGenerationEvent;
|
||||
|
||||
/**
|
||||
* Manages products
|
||||
@@ -1025,6 +1027,108 @@ class ProductController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
// Create combinations
|
||||
protected function combine($input, &$output, &$tmp) {
|
||||
$current = array_shift($input);
|
||||
|
||||
if (count($input) > 0) {
|
||||
foreach($current as $element) {
|
||||
$tmp[] = $element;
|
||||
$this->combine($input, $output, $tmp);
|
||||
array_pop($tmp);
|
||||
}
|
||||
} else {
|
||||
foreach($current as $element) {
|
||||
$tmp[] = $element;
|
||||
$output[] = $tmp;
|
||||
array_pop($tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build combinations from the combination output builder
|
||||
*/
|
||||
public function buildCombinationsAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, AccessManager::UPDATE)) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
$changeForm = new ProductCombinationGenerationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($changeForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
// Rework attributes_av array, to build an array which contains all combinations,
|
||||
// in the form combination[] = array of combination attributes av IDs
|
||||
//
|
||||
// First, create an array of attributes_av ID in the form $attributes_av_list[$attribute_id] = array of attributes_av ID
|
||||
// from the list of attribute_id:attributes_av ID from the form.
|
||||
$combinations = $attributes_av_list = array();
|
||||
|
||||
foreach($data['attribute_av'] as $item) {
|
||||
list($attribute_id, $attribute_av_id) = explode(':', $item);
|
||||
|
||||
if (! isset($attributes_av_list[$attribute_id]))
|
||||
$attributes_av_list[$attribute_id] = array();
|
||||
|
||||
|
||||
$attributes_av_list[$attribute_id][] = $attribute_av_id;
|
||||
}
|
||||
|
||||
// Next, recursively combine array
|
||||
$combinations = $tmp = array();
|
||||
|
||||
$this->combine($attributes_av_list, $combinations, $tmp);
|
||||
|
||||
// Create event
|
||||
$event = new ProductCombinationGenerationEvent(
|
||||
$this->getExistingObject(),
|
||||
$data['currency'],
|
||||
$combinations
|
||||
);
|
||||
|
||||
$event
|
||||
->setReference($data['reference'] == null ? '' : $data['reference'])
|
||||
->setPrice($data['price'] == null ? 0 : $data['price'])
|
||||
->setWeight($data['weight'] == null ? 0 : $data['weight'])
|
||||
->setQuantity($data['quantity'] == null ? 0 : $data['quantity'])
|
||||
->setSalePrice($data['sale_price'] == null ? 0 : $data['sale_price'])
|
||||
->setOnsale($data['onsale'] == null ? false : $data['onsale'])
|
||||
->setIsnew($data['isnew'] == null ? false : $data['isnew'])
|
||||
->setEanCode($data['ean_code'] == null ? '' : $data['ean_code'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::PRODUCT_COMBINATION_GENERATION, $event);
|
||||
|
||||
// Log object modification
|
||||
$this->adminLogAppend(sprintf("Combination generation for product reference %s", $event->getProduct()->getRef()));
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("Combination builder"), $error_msg, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked through Ajax; this method calculates the taxed price from the unaxed price, and
|
||||
* vice versa.
|
||||
|
||||
Reference in New Issue
Block a user