diff --git a/core/lib/Thelia/Action/Product.php b/core/lib/Thelia/Action/Product.php index 8865f25b2..5b80436a3 100644 --- a/core/lib/Thelia/Action/Product.php +++ b/core/lib/Thelia/Action/Product.php @@ -53,6 +53,7 @@ use Thelia\Model\FeatureProduct; use Thelia\Model\FeatureQuery; use Thelia\Core\Event\FeatureProductDeleteEvent; use Thelia\Model\FeatureProductQuery; +use Thelia\Model\ProductCategoryQuery; class Product extends BaseAction implements EventSubscriberInterface { @@ -101,11 +102,16 @@ class Product extends BaseAction implements EventSubscriberInterface ->setDescription($event->getDescription()) ->setChapo($event->getChapo()) ->setPostscriptum($event->getPostscriptum()) - - ->setParent($event->getParent()) ->setVisible($event->getVisible()) - ->save(); + ->save() + ; + + // Update the rewriten URL, if required + $product->setRewrittenUrl($event->getLocale(), $event->getUrl()); + + // Update default category (ifd required) + $product->updateDefaultCategory($event->getDefaultCategory()); $event->setProduct($product); } @@ -293,6 +299,7 @@ echo " Create !"; else { $featureProduct->setFeatureAvId($event->getFeatureValue()); } +echo "value=".$event->getFeatureValue(); $featureProduct->save(); @@ -311,7 +318,7 @@ echo " Create !"; ->delete(); ; -echo "
Delete p=".$event->getProductId()." f=".$event->getFeatureId(); +echo "
Delete p=".$event->getProductId().", f=".$event->getFeatureId(); $event->setFeatureProduct($featureProduct); } diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index f3c4cb136..45bd94186 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -114,7 +114,7 @@ class ProductController extends AbstractCrudController ->setPostscriptum($formData['postscriptum']) ->setVisible($formData['visible']) ->setUrl($formData['url']) - ->setParent($formData['parent']) + ->setDefaultCategory($formData['default_category']) ; return $changeEvent; @@ -144,6 +144,7 @@ class ProductController extends AbstractCrudController // Prepare the data that will hydrate the form $data = array( 'id' => $object->getId(), + 'ref' => $object->getRef(), 'locale' => $object->getLocale(), 'title' => $object->getTitle(), 'chapo' => $object->getChapo(), @@ -500,7 +501,7 @@ class ProductController extends AbstractCrudController // Update all features values $featureValues = $this->getRequest()->get('feature_value', array()); -print_r($featureValues); +echo "
list: "; print_r($featureValues); foreach($featureValues as $featureId => $featureValueList) { // Delete all values for this feature. @@ -520,7 +521,7 @@ print_r($featureValues); // Update then features text values $featureTextValues = $this->getRequest()->get('feature_text_value', array()); -print_r($featureTextValues); +echo "
free text"; print_r($featureTextValues); foreach($featureTextValues as $featureId => $featureValue) { // considere empty text as empty feature value (e.g., we will delete it) @@ -537,7 +538,7 @@ print_r($featureTextValues); foreach($allFeatures as $feature) { if (! in_array($feature->getId(), $updatedFeatures)) { $event = new FeatureProductDeleteEvent($productId, $feature->getId()); -echo "delete $productId, ".$feature->getId()." - "; +echo "
delete $productId, ".$feature->getId()." - "; $this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event); } } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php index f1249697a..e0f5f54e4 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php @@ -70,6 +70,9 @@ class UrlGenerator extends AbstractSmartyPlugin $mode ); + // FIXME: potentially dangerous ? + $url = str_replace('&', '&', $url); + if ($target != null) $url .= '#'.$target; return $url; diff --git a/core/lib/Thelia/Form/ProductCreationForm.php b/core/lib/Thelia/Form/ProductCreationForm.php index 9329ca2ec..8050dcff9 100644 --- a/core/lib/Thelia/Form/ProductCreationForm.php +++ b/core/lib/Thelia/Form/ProductCreationForm.php @@ -47,19 +47,17 @@ class ProductCreationForm extends BaseForm "label_attr" => array("for" => "ref") )) ->add("title", "text", array( - "constraints" => array( - new NotBlank() - ), + // "constraints" => array(new NotBlank()), "label" => "Product title *", "label_attr" => array("for" => "title") )) ->add("default_category", "integer", array( - "constraints" => array(new NotBlank()), + // "constraints" => array(new NotBlank()), "label" => Translator::getInstance()->trans("Default product category."), "label_attr" => array("for" => "default_category_field") )) ->add("locale", "text", array( - "constraints" => array(new NotBlank()) + //"constraints" => array(new NotBlank()) )) ->add("visible", "integer", array( "label" => Translator::getInstance()->trans("This product is online."), diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index cbb6c0051..8521d8dc5 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -87,6 +87,32 @@ class Product extends BaseProduct return $this; } + public function updateDefaultCategory($defaultCategoryId) { + + // Update the default category + $productCategory = ProductCategoryQuery::create() + ->filterByProductId($this->getId()) + ->filterByDefaultCategory(true) + ->findOne() + ; + + if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) { + + // Delete the old default category + if ($productCategory !== null) $productCategory->delete(); + + // Add the new default category + $productCategory = new ProductCategory(); + + $productCategory + ->setProduct($this) + ->setCategoryId($defaultCategoryId) + ->setDefaultCategory(true) + ->save($con) + ; + } + } + /** * Create a new product, along with the default category ID * @@ -105,14 +131,7 @@ class Product extends BaseProduct $this->save($con); // Add the default category - $pc = new ProductCategory(); - - $pc - ->setProduct($this) - ->setCategoryId($defaultCategoryId) - ->setDefaultCategory(true) - ->save($con) - ; + $this->updateDefaultCategory($defaultCategoryId); // Set the position $this->setPosition($this->getNextPosition())->save($con); diff --git a/templates/admin/default/includes/generic-confirm-dialog.html b/templates/admin/default/includes/generic-confirm-dialog.html index be1f4b63d..63f59eca8 100644 --- a/templates/admin/default/includes/generic-confirm-dialog.html +++ b/templates/admin/default/includes/generic-confirm-dialog.html @@ -29,7 +29,7 @@ Parameters: {$dialog_message nofilter} -
+ {$form_content nofilter} diff --git a/templates/admin/default/includes/product-attributes-tab.html b/templates/admin/default/includes/product-attributes-tab.html index 4e4216670..c02e4093a 100644 --- a/templates/admin/default/includes/product-attributes-tab.html +++ b/templates/admin/default/includes/product-attributes-tab.html @@ -28,7 +28,7 @@ {/loop} - + @@ -37,7 +37,7 @@ {ifloop rel="product_template"} - {* -- Begin attributes management ----------------------------------- *} + {* -- Begin attributes management ------------------------------- *}
{loop name="product_template" type="template" id={$TEMPLATE|default:0}}{/loop} @@ -45,14 +45,13 @@

{intl l='Product Attributes'}

-

{intl l='You can attach here some content to this product'}

- {* -- End attributes management -------------------------------------- *} + {* -- End attributes management ---------------------------------- *} - {* -- Begin features management -------------------------------------- *} + {* -- Begin features management ---------------------------------- *}
@@ -139,9 +138,9 @@
- {* -- End features management --------- *} - {/ifloop} - + {* -- End features management ------------------------------- *} + + {/ifloop} {elseloop rel="product_template"}
diff --git a/templates/admin/default/includes/product-general-tab.html b/templates/admin/default/includes/product-general-tab.html index 792d09ad9..71a7247b2 100644 --- a/templates/admin/default/includes/product-general-tab.html +++ b/templates/admin/default/includes/product-general-tab.html @@ -12,6 +12,10 @@ {form_hidden_fields form=$form} + {form_field form=$form field='id'} + + {/form_field} + {form_field form=$form field='success_url'} {/form_field} @@ -23,11 +27,16 @@ {if $form_error}
{$form_error_message}
{/if}
-
{include file="includes/standard-description-form-fields.html"} @@ -56,7 +65,7 @@ {loop name="cat-parent" type="category-tree" category="0" visible="*" product="0"} - + {/loop} @@ -84,7 +93,7 @@
-   +

{intl l='Product created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}