diff --git a/core/lib/Thelia/Action/Product.php b/core/lib/Thelia/Action/Product.php index 5d827be8e..2ef61a268 100644 --- a/core/lib/Thelia/Action/Product.php +++ b/core/lib/Thelia/Action/Product.php @@ -99,6 +99,7 @@ class Product extends BaseAction implements EventSubscriberInterface ->setChapo($event->getChapo()) ->setPostscriptum($event->getPostscriptum()) ->setVisible($event->getVisible() ? 1 : 0) + ->setBrandId($event->getBrandId() <= 0 ? null : $event->getBrandId()) ->save() ; diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index 4cbfbad42..f3a625807 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -164,6 +164,7 @@ class ProductController extends AbstractSeoCrudController ->setPostscriptum($formData['postscriptum']) ->setVisible($formData['visible']) ->setDefaultCategory($formData['default_category']) + ->setBrandId($formData['brand_id']) ; // Create and dispatch the change event @@ -213,6 +214,10 @@ class ProductController extends AbstractSeoCrudController $array[$key][] = $value; } + /** + * @param Product $object + * @return ProductModificationForm + */ protected function hydrateObjectForm($object) { // Find product's sale elements @@ -320,7 +325,8 @@ class ProductController extends AbstractSeoCrudController 'description' => $object->getDescription(), 'postscriptum' => $object->getPostscriptum(), 'visible' => $object->getVisible(), - 'default_category' => $object->getDefaultCategoryId() + 'default_category' => $object->getDefaultCategoryId(), + 'brand_id' => $object->getBrandId() ); // Setup the object form diff --git a/core/lib/Thelia/Core/Event/Product/ProductUpdateEvent.php b/core/lib/Thelia/Core/Event/Product/ProductUpdateEvent.php index 1768f3384..4a20b491c 100644 --- a/core/lib/Thelia/Core/Event/Product/ProductUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Product/ProductUpdateEvent.php @@ -19,6 +19,8 @@ class ProductUpdateEvent extends ProductCreateEvent protected $chapo; protected $description; protected $postscriptum; + protected $brand_id; + public function __construct($product_id) { @@ -72,4 +74,22 @@ class ProductUpdateEvent extends ProductCreateEvent return $this; } + + /** + * @param int $brand_id + * @return $this + */ + public function setBrandId($brand_id) + { + $this->brand_id = $brand_id; + return $this; + } + + /** + * @return int + */ + public function getBrandId() + { + return $this->brand_id; + } } diff --git a/core/lib/Thelia/Tests/Action/ProductTest.php b/core/lib/Thelia/Tests/Action/ProductTest.php index 89c6d3a17..15a6d7424 100644 --- a/core/lib/Thelia/Tests/Action/ProductTest.php +++ b/core/lib/Thelia/Tests/Action/ProductTest.php @@ -26,6 +26,7 @@ use Thelia\Core\Event\Product\ProductSetTemplateEvent; use Thelia\Core\Event\Product\ProductToggleVisibilityEvent; use Thelia\Core\Event\Product\ProductUpdateEvent; use Thelia\Model\AccessoryQuery; +use Thelia\Model\BrandQuery; use Thelia\Model\CategoryQuery; use Thelia\Model\ContentQuery; use Thelia\Model\CurrencyQuery; @@ -115,6 +116,7 @@ class ProductTest extends TestCaseWithURLToolSetup { $event = new ProductUpdateEvent($product->getId()); $defaultCategory = CategoryQuery::create()->select('id')->addAscendingOrderByColumn('RAND()')->findOne(); + $brandId = BrandQuery::create()->findOne()->getId(); $event ->setLocale('fr_FR') ->setTitle('test MAJ titre en français') @@ -123,6 +125,7 @@ class ProductTest extends TestCaseWithURLToolSetup ->setPostscriptum('test postscriptum fr') ->setVisible(1) ->setDefaultCategory($defaultCategory) + ->setBrandId($brandId) ->setDispatcher($this->getDispatcher()); ;