diff --git a/core/lib/Thelia/Action/ProductSaleElement.php b/core/lib/Thelia/Action/ProductSaleElement.php index facadfc4b..d3c34c293 100644 --- a/core/lib/Thelia/Action/ProductSaleElement.php +++ b/core/lib/Thelia/Action/ProductSaleElement.php @@ -215,10 +215,14 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface // If we just deleted the last PSE, create a default one $product->createDefaultProductSaleElement($con, 0, 0, $event->getCurrencyId(), true); } - else if ($product->getDefaultSaleElements() == null) { + else if ($pse->getIsDefault()) { // If we deleted the default PSE, make the last created one the default - $pse = ProductSaleElementsQuery::create()->filterByProductId($this->id)->orderByCreatedAt(Criteria::DESC)->findOne($con); + $pse = ProductSaleElementsQuery::create() + ->filterByProductId($product->getId()) + ->orderByCreatedAt(Criteria::DESC) + ->findOne($con) + ; $pse->setIsDefault(true)->save($con); } diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 019abcfa0..a23d99485 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -364,8 +364,8 @@ Thelia\Controller\Admin\ProductController::deleteProductSaleElementAction - - Thelia\Controller\Admin\ProductController::updateProductSaleElementAction + + Thelia\Controller\Admin\ProductController::updateProductSaleElementsAction diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index 85f35f398..fb93e3c01 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -206,10 +206,14 @@ class ProductController extends AbstractCrudController } } + protected function appendValue(&$array, $key, $value) { + if (! isset($array[$key])) $array[$key] = array(); + + $array[$key][] = $value; + } + protected function hydrateObjectForm($object) { - $defaultPseData = $combinationPseData = array(); - // Find product's sale elements $saleElements = ProductSaleElementsQuery::create() ->filterByProduct($object) @@ -218,6 +222,12 @@ class ProductController extends AbstractCrudController $defaultCurrency = Currency::getDefaultCurrency(); $currentCurrency = $this->getCurrentEditionCurrency(); + // Common parts + $defaultPseData = $combinationPseData = array( + "product_id" => $object->getId(), + "tax_rule" => $object->getTaxRuleId() + ); + foreach($saleElements as $saleElement) { // Get the product price for the current currency @@ -251,15 +261,12 @@ class ProductController extends AbstractCrudController // If this PSE has no combination -> this is the default one // affect it to the thelia.admin.product_sale_element.update form if ($isDefaultPse) { - $defaultPseData = array( - "product_id" => $object->getId(), "product_sale_element_id" => $saleElement->getId(), "reference" => $saleElement->getRef(), "price" => $productPrice->getPrice(), "price_with_tax" => $this->computePrice($productPrice->getPrice(), 'without_tax', $object), "use_exchange_rate" => $productPrice->getFromDefaultCurrency() ? 1 : 0, - "tax_rule" => $object->getTaxRuleId(), "currency" => $productPrice->getCurrencyId(), "weight" => $saleElement->getWeight(), "quantity" => $saleElement->getQuantity(), @@ -272,6 +279,25 @@ class ProductController extends AbstractCrudController ); } else { + + if ($saleElement->getIsDefault()) { + $combinationPseData['default_pse'] = $saleElement->getId(); + $combinationPseData['currency'] = $currentCurrency->getId(); + $combinationPseData['use_exchange_rate'] = $productPrice->getFromDefaultCurrency() ? 1 : 0; + } + + $this->appendValue($combinationPseData, "product_sale_element_id" , $saleElement->getId()); + $this->appendValue($combinationPseData, "reference" , $saleElement->getRef()); + $this->appendValue($combinationPseData, "price" , $productPrice->getPrice()); + $this->appendValue($combinationPseData, "price_with_tax" , $this->computePrice($productPrice->getPrice(), 'without_tax', $object)); + $this->appendValue($combinationPseData, "weight" , $saleElement->getWeight()); + $this->appendValue($combinationPseData, "quantity" , $saleElement->getQuantity()); + $this->appendValue($combinationPseData, "sale_price" , $productPrice->getPromoPrice()); + $this->appendValue($combinationPseData, "sale_price_with_tax" , $this->computePrice($productPrice->getPromoPrice(), 'without_tax', $object)); + $this->appendValue($combinationPseData, "onsale" , $saleElement->getPromo() > 0 ? 1 : 0); + $this->appendValue($combinationPseData, "isnew" , $saleElement->getNewness() > 0 ? 1 : 0); + $this->appendValue($combinationPseData, "isdefault" , $saleElement->getIsDefault() > 0 ? 1 : 0); + $this->appendValue($combinationPseData, "ean_code" , $saleElement->getEanCode()); } $defaultPseForm = new ProductDefaultSaleElementUpdateForm($this->getRequest(), "form", $defaultPseData); @@ -281,7 +307,7 @@ class ProductController extends AbstractCrudController $this->getParserContext()->addForm($combinationPseForm); } - // Prepare the data that will hydrate the form(s) + // The "General" tab form $data = array( 'id' => $object->getId(), 'ref' => $object->getRef(), @@ -878,11 +904,47 @@ class ProductController extends AbstractCrudController $this->redirectToEditionTemplate(); } + /** + * Process a single PSE update, using form data array. + * + * @param array $data the form data + * @throws Exception is someting goes wrong. + */ + protected function processSingleProductSaleElementUpdate($data) + { + $event = new ProductSaleElementUpdateEvent( + $this->getExistingObject(), + $data['product_sale_element_id'] + ); + + $event + ->setReference($data['reference']) + ->setPrice($data['price']) + ->setCurrencyId($data['currency']) + ->setWeight($data['weight']) + ->setQuantity($data['quantity']) + ->setSalePrice($data['sale_price']) + ->setOnsale($data['onsale']) + ->setIsnew($data['isnew']) + ->setIsdefault($data['isdefault']) + ->setEanCode($data['ean_code']) + ->setTaxRuleId($data['tax_rule']) + ->setFromDefaultCurrency($data['use_exchange_rate']) + ; + + $this->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $event); + + // Log object modification + if (null !== $changedObject = $event->getProductSaleElement()) { + $this->adminLogAppend(sprintf("Product Sale Element (ID %s) for product reference %s modified", $changedObject->getId(), $event->getProduct()->getRef())); + } + } + /** * Change a product sale element */ - protected function processProductSaleElementUpdate($changeForm) { - + protected function processProductSaleElementUpdate($changeForm) + { // Check current user authorization if (null !== $response = $this->checkAuth($this->resourceCode, AccessManager::UPDATE)) return $response; @@ -896,31 +958,35 @@ class ProductController extends AbstractCrudController // Get the form field values $data = $form->getData(); - $event = new ProductSaleElementUpdateEvent( - $this->getExistingObject(), - $data['product_sale_element_id'] - ); + if (is_array($data['product_sale_element_id'])) { - $event - ->setReference($data['reference']) - ->setPrice($data['price']) - ->setCurrencyId($data['currency']) - ->setWeight($data['weight']) - ->setQuantity($data['quantity']) - ->setSalePrice($data['sale_price']) - ->setOnsale($data['onsale']) - ->setIsnew($data['isnew']) - ->setIsdefault($data['isdefault']) - ->setEanCode($data['ean_code']) - ->setTaxRuleId($data['tax_rule']) - ->setFromDefaultCurrency($data['use_exchange_rate']) - ; + // Common fields + $tmp_data = array( + 'tax_rule' => $data['tax_rule'], + 'currency' => $data['currency'], + 'use_exchange_rate' => $data['use_exchange_rate'], + ); - $this->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $event); + $count = count($data['product_sale_element_id']); - // Log object modification - if (null !== $changedObject = $event->getProductSaleElement()) { - $this->adminLogAppend(sprintf("Product Sale Element (ID %s) for product reference %s modified", $changedObject->getId(), $event->getProduct()->getRef())); + for($idx = 0; $idx < $count; $idx++) { + $tmp_data['product_sale_element_id'] = $pse_id = $data['product_sale_element_id'][$idx]; + $tmp_data['reference'] = $data['reference'][$idx]; + $tmp_data['price'] = $data['price'][$idx]; + $tmp_data['weight'] = $data['weight'][$idx]; + $tmp_data['quantity'] = $data['quantity'][$idx]; + $tmp_data['sale_price'] = $data['sale_price'][$idx]; + $tmp_data['onsale'] = isset($data['onsale'][$idx]) ? 1 : 0; + $tmp_data['isnew'] = isset($data['isnew'][$idx]) ? 1 : 0; + $tmp_data['isdefault'] = $data['default_pse'] == $pse_id; + $tmp_data['ean_code'] = $data['ean_code'][$idx]; + + $this->processSingleProductSaleElementUpdate($tmp_data); + } + } + else { + // No need to preprocess data + $this->processSingleProductSaleElementUpdate($data); } // If we have to stay on the same page, do not redirect to the succesUrl, just redirect to the edit page again. @@ -948,9 +1014,9 @@ class ProductController extends AbstractCrudController } /** - * Change a product sale element attached to a combination + * Process the change of product's PSE list. */ - public function updateProductSaleElementAction() { + public function updateProductSaleElementsAction() { return $this->processProductSaleElementUpdate( new ProductSaleElementUpdateForm($this->getRequest()) ); @@ -960,14 +1026,13 @@ class ProductController extends AbstractCrudController * Update default product sale element (not attached to any combination) */ public function updateProductDefaultSaleElementAction() { - return $this->processProductSaleElementUpdate( new ProductDefaultSaleElementUpdateForm($this->getRequest()) ); } /** - * Invoked through Ajax; this methow calculate the taxed price from the unaxed price, and + * Invoked through Ajax; this method calculates the taxed price from the unaxed price, and * vice versa. */ public function priceCaclulator() { @@ -999,6 +1064,11 @@ class ProductController extends AbstractCrudController return new JsonResponse(array('result' => $return_price)); } + /** + * Calculate all prices + * + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ public function loadConvertedPrices() { $product_sale_element_id = intval($this->getRequest()->get('product_sale_element_id', 0)); diff --git a/core/lib/Thelia/Controller/Admin/TestController.php b/core/lib/Thelia/Controller/Admin/TestController.php deleted file mode 100644 index 5fbdb58e8..000000000 --- a/core/lib/Thelia/Controller/Admin/TestController.php +++ /dev/null @@ -1,93 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Thelia\Controller\Admin; - -use Thelia\Form\TestForm; -/** - * Manages variables - * - * @author Franck Allimant - */ -class TestController extends BaseAdminController -{ - /** - * Load a object for modification, and display the edit template. - * - * @return Symfony\Component\HttpFoundation\Response the response - */ - public function updateAction() - { - // Prepare the data that will hydrate the form - $data = array( - 'title' => "test title", - 'test' => array('a', 'b', 'toto' => 'c') - ); - - // Setup the object form - $changeForm = new TestForm($this->getRequest(), "form", $data); - - // Pass it to the parser - $this->getParserContext()->addForm($changeForm); - - return $this->render('test-form'); - } - - /** - * Save changes on a modified object, and either go back to the object list, or stay on the edition page. - * - * @return Symfony\Component\HttpFoundation\Response the response - */ - public function processUpdateAction() - { - $error_msg = false; - - // Create the form from the request - $changeForm = new TestForm($this->getRequest()); - - try { - - // Check the form against constraints violations - $form = $this->validateForm($changeForm, "POST"); - - // Get the form field values - $data = $form->getData(); - - echo "data="; - - var_dump($data); - } - catch (FormValidationException $ex) { - // Form cannot be validated - $error_msg = $this->createStandardFormValidationErrorMessage($ex); - } - catch (\Exception $ex) { - // Any other error - $error_msg = $ex->getMessage(); - } - - echo "Error = $error_msg"; - - exit; - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 8539796b0..97986e146 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -119,7 +119,7 @@ class Form extends AbstractSmartyPlugin } } - protected function assignFieldValues($template, $fieldName, $fieldValue, $fieldVars) + protected function assignFieldValues($template, $fieldName, $fieldValue, $fieldVars, $total_value_count = 1) { $template->assign("name", $fieldName); @@ -136,6 +136,8 @@ class Form extends AbstractSmartyPlugin $template->assign('required', isset($fieldVars['required']) ? $fieldVars['required'] : false); + $template->assign('total_value_count', $total_value_count); + $errors = $fieldVars["errors"]; $template->assign("error", empty($errors) ? false : true); @@ -208,23 +210,19 @@ class Form extends AbstractSmartyPlugin $value = $formFieldView->vars["value"]; // We have a collection - if (count($formFieldView->children) > 0) { + if (0 < $value_count = count($formFieldView->children)) { - $key = $this->getParam($params, 'value_key'); + $key = $this->getParam($params, 'value_key', null); - if ($key != null) { + if ($key !== null) { + // If the field is not found, use an empty value + $val = array_key_exists($key, $value) ? $value[$key] : ''; - if (isset($value[$key])) { + $name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key); - $name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key); + $val = $value[$key]; - $val = $value[$key]; - - $this->assignFieldValues($template, $name, $val, $formFieldView->vars); - } - else { - throw new \LogicException(sprintf("Cannot find a value for key '%s' in field '%s'", $key, $formFieldView->vars["name"])); - } + $this->assignFieldValues($template, $name, $val, $formFieldView->vars, $value_count); } else { throw new \InvalidArgumentException(sprintf("Missing or empty parameter 'value_key' for field '%s'", $formFieldView->vars["name"])); diff --git a/core/lib/Thelia/Form/ProductDefaultSaleElementUpdateForm.php b/core/lib/Thelia/Form/ProductDefaultSaleElementUpdateForm.php index ebc081faf..ad0a852c9 100644 --- a/core/lib/Thelia/Form/ProductDefaultSaleElementUpdateForm.php +++ b/core/lib/Thelia/Form/ProductDefaultSaleElementUpdateForm.php @@ -22,8 +22,91 @@ /*************************************************************************************/ namespace Thelia\Form; +use Symfony\Component\Validator\Constraints\GreaterThan; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Model\Currency; +use Thelia\Core\Translation\Translator; + class ProductDefaultSaleElementUpdateForm extends ProductSaleElementUpdateForm { + use StandardDescriptionFieldsTrait; + + protected function buildForm() + { + $this->formBuilder + ->add("product_id", "integer", array( + "label" => Translator::getInstance()->trans("Product ID *"), + "label_attr" => array("for" => "product_id_field"), + "constraints" => array(new GreaterThan(array('value' => 0))) + )) + ->add("product_sale_element_id", "integer", array( + "label" => Translator::getInstance()->trans("Product sale element ID *"), + "label_attr" => array("for" => "product_sale_element_id_field") + )) + ->add("reference", "text", array( + "label" => Translator::getInstance()->trans("Reference *"), + "label_attr" => array("for" => "reference_field") + )) + ->add("price", "number", array( + "constraints" => array(new NotBlank()), + "label" => Translator::getInstance()->trans("Product price excluding taxes *"), + "label_attr" => array("for" => "price_field") + )) + ->add("price_with_tax", "number", array( + "label" => Translator::getInstance()->trans("Product price including taxes"), + "label_attr" => array("for" => "price_with_tax_field") + )) + ->add("currency", "integer", array( + "constraints" => array(new NotBlank()), + "label" => Translator::getInstance()->trans("Price currency *"), + "label_attr" => array("for" => "currency_field") + )) + ->add("tax_rule", "integer", array( + "constraints" => array(new NotBlank()), + "label" => Translator::getInstance()->trans("Tax rule for this product *"), + "label_attr" => array("for" => "tax_rule_field") + )) + ->add("weight", "number", array( + "constraints" => array(new NotBlank()), + "label" => Translator::getInstance()->trans("Weight *"), + "label_attr" => array("for" => "weight_field") + )) + ->add("quantity", "number", array( + "constraints" => array(new NotBlank()), + "label" => Translator::getInstance()->trans("Available quantity *"), + "label_attr" => array("for" => "quantity_field") + )) + ->add("sale_price", "number", array( + "label" => Translator::getInstance()->trans("Sale price without taxes"), + "label_attr" => array("for" => "price_with_tax_field") + )) + ->add("sale_price_with_tax", "number", array( + "label" => Translator::getInstance()->trans("Sale price including taxes"), + "label_attr" => array("for" => "sale_price_with_tax_field") + )) + ->add("onsale", "integer", array( + "label" => Translator::getInstance()->trans("This product is on sale"), + "label_attr" => array("for" => "onsale_field") + )) + ->add("isnew", "integer", array( + "label" => Translator::getInstance()->trans("Advertise this product as new"), + "label_attr" => array("for" => "isnew_field") + )) + ->add("isdefault", "integer", array( + "label" => Translator::getInstance()->trans("Is it the default product sale element ?"), + "label_attr" => array("for" => "isdefault_field") + )) + ->add("ean_code", "text", array( + "label" => Translator::getInstance()->trans("EAN Code"), + "label_attr" => array("for" => "ean_code_field") + )) + ->add("use_exchange_rate", "integer", array( + "label" => Translator::getInstance()->trans("Apply exchange rates on price in %sym", array("%sym" => Currency::getDefaultCurrency()->getSymbol())), + "label_attr" => array("for" => "use_exchange_rate_field") + )) + ; + } + public function getName() { return "thelia_product_default_sale_element_update_form"; diff --git a/core/lib/Thelia/Form/ProductSaleElementUpdateForm.php b/core/lib/Thelia/Form/ProductSaleElementUpdateForm.php index f93a4e251..da831545a 100644 --- a/core/lib/Thelia/Form/ProductSaleElementUpdateForm.php +++ b/core/lib/Thelia/Form/ProductSaleElementUpdateForm.php @@ -23,9 +23,9 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints\GreaterThan; -use Thelia\Core\Translation\Translator; use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Model\Currency; +use Thelia\Core\Translation\Translator; class ProductSaleElementUpdateForm extends BaseForm { @@ -34,76 +34,124 @@ class ProductSaleElementUpdateForm extends BaseForm protected function buildForm() { $this->formBuilder + ->add("tax_rule", "integer", array( + "constraints" => array(new NotBlank()), + "label" => Translator::getInstance()->trans("Tax rule for this product *"), + "label_attr" => array("for" => "tax_rule_field") + )) ->add("product_id", "integer", array( - "label" => Translator::getInstance()->trans("Product ID *"), - "label_attr" => array("for" => "product_id_field"), - "constraints" => array(new GreaterThan(array('value' => 0))) + "label" => Translator::getInstance()->trans("Product ID *"), + "label_attr" => array("for" => "product_id_field"), + "constraints" => array(new GreaterThan(array('value' => 0))) )) - ->add("product_sale_element_id", "integer", array( - "label" => Translator::getInstance()->trans("Product sale element ID *"), - "label_attr" => array("for" => "product_sale_element_id_field") - )) - ->add("reference", "text", array( - "label" => Translator::getInstance()->trans("Reference *"), - "label_attr" => array("for" => "reference_field") - )) - ->add("price", "number", array( - "constraints" => array(new NotBlank()), - "label" => Translator::getInstance()->trans("Product price excluding taxes *"), - "label_attr" => array("for" => "price_field") - )) - ->add("price_with_tax", "number", array( - "label" => Translator::getInstance()->trans("Product price including taxes"), - "label_attr" => array("for" => "price_with_tax_field") + ->add("default_pse", "integer", array( + "label" => Translator::getInstance()->trans("Default product sale element"), + "label_attr" => array("for" => "default_pse_field"), )) ->add("currency", "integer", array( - "constraints" => array(new NotBlank()), - "label" => Translator::getInstance()->trans("Price currency *"), - "label_attr" => array("for" => "currency_field") - )) - ->add("tax_rule", "integer", array( - "constraints" => array(new NotBlank()), - "label" => Translator::getInstance()->trans("Tax rule for this product *"), - "label_attr" => array("for" => "tax_rule_field") - )) - ->add("weight", "number", array( - "constraints" => array(new NotBlank()), - "label" => Translator::getInstance()->trans("Weight *"), - "label_attr" => array("for" => "weight_field") - )) - ->add("quantity", "number", array( - "constraints" => array(new NotBlank()), - "label" => Translator::getInstance()->trans("Available quantity *"), - "label_attr" => array("for" => "quantity_field") - )) - ->add("sale_price", "number", array( - "label" => Translator::getInstance()->trans("Sale price without taxes"), - "label_attr" => array("for" => "price_with_tax_field") - )) - ->add("sale_price_with_tax", "number", array( - "label" => Translator::getInstance()->trans("Sale price including taxes"), - "label_attr" => array("for" => "sale_price_with_tax_field") - )) - ->add("onsale", "integer", array( - "label" => Translator::getInstance()->trans("This product is on sale"), - "label_attr" => array("for" => "onsale_field") - )) - ->add("isnew", "integer", array( - "label" => Translator::getInstance()->trans("Advertise this product as new"), - "label_attr" => array("for" => "isnew_field") - )) - ->add("isdefault", "integer", array( - "label" => Translator::getInstance()->trans("Is it the default product sale element ?"), - "label_attr" => array("for" => "isdefault_field") - )) - ->add("ean_code", "text", array( - "label" => Translator::getInstance()->trans("EAN Code"), - "label_attr" => array("for" => "ean_code_field") + "constraints" => array(new NotBlank()), + "label" => Translator::getInstance()->trans("Price currency *"), + "label_attr" => array("for" => "currency_field") )) ->add("use_exchange_rate", "integer", array( "label" => Translator::getInstance()->trans("Apply exchange rates on price in %sym", array("%sym" => Currency::getDefaultCurrency()->getSymbol())), "label_attr" => array("for" => "use_exchange_rate_field") )) + + // -- Collections + + ->add('product_sale_element_id', 'collection', array( + 'type' => 'integer', + 'label' => Translator::getInstance()->trans('Product sale element ID *'), + 'label_attr' => array('for' => 'product_sale_element_id_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) + ->add('reference', 'collection', array( + 'type' => 'text', + 'label' => Translator::getInstance()->trans('Reference *'), + 'label_attr' => array('for' => 'reference_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) + ->add('price', 'collection', array( + 'type' => 'number', + 'label' => Translator::getInstance()->trans('Product price excluding taxes *'), + 'label_attr' => array('for' => 'price_field'), + 'allow_add' => true, + 'allow_delete' => true, + 'options' => array( + 'constraints' => array(new NotBlank()), + ) + )) + ->add('price_with_tax', 'collection', array( + 'type' => 'number', + 'label' => Translator::getInstance()->trans('Product price including taxes'), + 'label_attr' => array('for' => 'price_with_tax_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) + ->add('weight', 'collection', array( + 'type' => 'number', + 'label' => Translator::getInstance()->trans('Weight *'), + 'label_attr' => array('for' => 'weight_field'), + 'allow_add' => true, + 'allow_delete' => true, + 'options' => array( + 'constraints' => array(new NotBlank()), + ) + )) + ->add('quantity', 'collection', array( + 'type' => 'number', + 'label' => Translator::getInstance()->trans('Available quantity *'), + 'label_attr' => array('for' => 'quantity_field'), + 'allow_add' => true, + 'allow_delete' => true, + 'options' => array( + 'constraints' => array(new NotBlank()), + ) + )) + ->add('sale_price', 'collection', array( + 'label' => Translator::getInstance()->trans('Sale price without taxes'), + 'label_attr' => array('for' => 'price_with_tax_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) + ->add('sale_price_with_tax', 'collection', array( + 'type' => 'number', + 'label' => Translator::getInstance()->trans('Sale price including taxes'), + 'label_attr' => array('for' => 'sale_price_with_tax_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) + ->add('onsale', 'collection', array( + 'type' => 'integer', + 'label' => Translator::getInstance()->trans('This product is on sale'), + 'label_attr' => array('for' => 'onsale_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) + ->add('isnew', 'collection', array( + 'type' => 'integer', + 'label' => Translator::getInstance()->trans('Advertise this product as new'), + 'label_attr' => array('for' => 'isnew_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) + ->add('isdefault', 'collection', array( + 'type' => 'integer', + 'label' => Translator::getInstance()->trans('Is it the default product sale element ?'), + 'label_attr' => array('for' => 'isdefault_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) + ->add('ean_code', 'collection', array( + 'type' => 'text', + 'label' => Translator::getInstance()->trans('EAN Code'), + 'label_attr' => array('for' => 'ean_code_field'), + 'allow_add' => true, + 'allow_delete' => true, + )) ; } diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 5ec2abf4c..1441810b0 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -192,6 +192,7 @@ class Product extends BaseProduct ->setNewness(0) ->setWeight($weight) ->setIsDefault($isDefault) + ->setEanCode('') ->save($con) ; diff --git a/install/faker.php b/install/faker.php index 58a954ebf..d834e294c 100755 --- a/install/faker.php +++ b/install/faker.php @@ -426,7 +426,7 @@ try { $stock->setNewness($faker->randomNumber(0,1)); $stock->setWeight($faker->randomFloat(2, 100,10000)); $stock->setIsDefault($i == 0); - $stock->setEanCode(strtoupper($faker->text(13))); + $stock->setEanCode(substr(str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 13)); $stock->save(); $productPrice = new \Thelia\Model\ProductPrice(); diff --git a/templates/admin/default/includes/product-details-tab.html b/templates/admin/default/includes/product-details-tab.html index 57dda78cf..1d4ebc4c5 100644 --- a/templates/admin/default/includes/product-details-tab.html +++ b/templates/admin/default/includes/product-details-tab.html @@ -257,37 +257,79 @@ {form name="thelia.admin.product_sale_element.update"}
+
+
-
-
+ {include + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = false + show_currencies = true + page_url = "{url path='/admin/products/update' product_id=$ID}" + close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" + } - {include - file = "includes/inner-form-toolbar.html" - hide_submit_buttons = false - show_currencies = true - page_url = "{url path='/admin/products/update' product_id=$ID}" - close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}" - } + {* Be sure to get the product ID, even if the form could not be validated *} + - {if $form_error}
{$form_error_message}
{/if} + -
-
- {form_field form=$form field='tax_rule'} -
- -
- -
-
- {/form_field} -
-
+ {form_hidden_fields form=$form} + + {form_field form=$form field='product_id'} + + {/form_field} + + {form_field form=$form field='success_url'} + + {/form_field} + + {if $form_error}
{$form_error_message}
{/if} + + {loop type="currency" name="get-currency-symbol" id=$edit_currency_id backend_context="1"} + {$currency_symbol = $SYMBOL} + {$current_currency_is_default = $IS_DEFAULT} + + {form_field form=$form field='currency'} + + {/form_field} + {/loop} + +
+
+ {form_field form=$form field='tax_rule'} +
+ +
+ +
+
+ {/form_field} +
+
+ {form_field form=$form field='use_exchange_rate'} + {if $current_currency_is_default} + + {$show_pricing_fields = true} + {else} +
+ +
+ +
+
+ {$show_pricing_fields = ($value == 0)} + {/if} + {/form_field} +
+
{module_include location='product_before_combinations'} @@ -298,6 +340,9 @@ {module_include location='product_combinations_list_caption'} {loop type="auth" name="can_create" role="ADMIN" resource="admin.product" access="UPDATE"} + + {intl l='Combination builder'} + @@ -322,43 +367,91 @@ - {loop name="product.sales.elements" type="product_sale_elements" product=$product_id currency=$edit_currency_id backend_context="1"} + {* Get number of PSE defined, assumin the form have the same number of values for each fields *} + + {form_field form=$form field='product_sale_element_id' value_key=0} + {$pse_count = $total_value_count} + {/form_field} + + {for $idx = 0 to $total_value_count-1} - {$ID}: {loop name="product.sales.elements.combinations" type="attribute_combination" product_sale_elements=$ID backend_context="1"} - {if $LOOP_COUNT > 1} - {/if}{$ATTRIBUTE_TITLE} - {/loop} + + {form_field form=$form field='product_sale_element_id' value_key=$idx} + + + {$current_pse_id = $value} + + {$current_pse_id}: {loop name="product.sales.elements.combinations" type="attribute_combination" product_sale_elements=$current_pse_id backend_context="1"} + {if $LOOP_COUNT > 1} - {/if}{$ATTRIBUTE_TITLE} + {/loop} + {/form_field} - - - - - - - + + {form_field form=$form field='reference' value_key=$idx} + + {/form_field} - - + {form_field form=$form field='ean_code' value_key=$idx} + + {/form_field} + + {form_field form=$form field='quantity' value_key=$idx} + + + {/form_field} - - - + {form_field form=$form field='price' value_key=$idx} + + {/form_field} - - - + {form_field form=$form field='price_with_tax' value_key=$idx} + + {/form_field} - - + {form_field form=$form field='weight' value_key=$idx} + + {/form_field} - - - - - {/loop} + + {form_field form=$form field='default_pse'} + + + + {/form_field} + + {form_field form=$form field='onsale' value_key=$idx} + + + + {/form_field} + + {form_field form=$form field='isnew' value_key=$idx} + + + + {/form_field} + + {form_field form=$form field='sale_price' value_key=$idx} + + + + {/form_field} + + {form_field form=$form field='sale_price_with_tax' value_key=$idx} + + + + {/form_field} + + + + + + {/for} diff --git a/templates/admin/default/product-edit.html b/templates/admin/default/product-edit.html index bf40dc0ac..446e1fd7f 100644 --- a/templates/admin/default/product-edit.html +++ b/templates/admin/default/product-edit.html @@ -348,7 +348,8 @@ $(function() { // will update the untaxed (resp. taxed) one $('.automatic_price_field').typeWatch({ captureLength: 1, - callback: function () { + wait : 300, + callback : function () { update_price($(this).val(), $(this).data('price-type'), $(this).data('rel-price')); } });