diff --git a/Controller/SearchController.php b/Controller/SearchController.php index 1a299b3..ab18586 100644 --- a/Controller/SearchController.php +++ b/Controller/SearchController.php @@ -5,6 +5,7 @@ use ElasticProduct\ElasticProduct; +use ElasticProduct\Event\SearchEvent\SearchFilterEvent; use Thelia\Controller\Front\BaseFrontController; use Thelia\Core\HttpFoundation\JsonResponse; use Thelia\Core\HttpFoundation\Request; @@ -35,7 +36,8 @@ public function searchAction(Request $request) $filters = []; - $filters[] = [ + $filters[] = + [ "term" => [ "product.is_visible" => true ] @@ -157,11 +159,16 @@ public function searchAction(Request $request) ]; } + $searchFilterEvent = new SearchFilterEvent($request); + $searchFilterEvent->setFilters($filters); + $this->dispatch(SearchFilterEvent::GET_SEARCH_FILTER_EVENT, $searchFilterEvent); + + $body = [ "size" => 100, "query" => [ "bool" => [ - "filter" => $filters, + "filter" => $searchFilterEvent->getFilters(), "must" => [ "bool" => [ "should" => [ diff --git a/Event/IndexationEvent/ProductIndexationEvent.php b/Event/IndexationEvent/ProductIndexationEvent.php new file mode 100644 index 0000000..a691397 --- /dev/null +++ b/Event/IndexationEvent/ProductIndexationEvent.php @@ -0,0 +1,88 @@ +product = $product; + } + + /** + * @return Product + */ + public function getProduct() + { + return $this->product; + } + + /** + * @param Product $product + * + * @return ProductIndexationEvent + */ + public function setProduct($product) + { + $this->product = $product; + return $this; + } + + /** + * @return array + */ + public function getProductData() + { + return $this->productData; + } + + /** + * @param array $productData + * + * @return ProductIndexationEvent + */ + public function setProductData(array $productData) + { + $this->productData = $productData; + return $this; + } + + /** + * @param $name + * @param $value + * + * @return $this + */ + public function addProductData($name, $value) + { + $this->productData[$name] = $value; + return $this; + } + + /** + * @param $name + * @param $value + * + * @return $this + */ + public function removeProductData($name) + { + unset($this->productData[$name]); + return $this; + } +} \ No newline at end of file diff --git a/Event/PsePriceEvent.php b/Event/PsePriceEvent.php deleted file mode 100644 index efc3658..0000000 --- a/Event/PsePriceEvent.php +++ /dev/null @@ -1,119 +0,0 @@ -pseId = $pseId; - $this->countryId = $countryId; - $this->customerId = $customerId; - } - - /** - * @return mixed - */ - public function getPseId() - { - return $this->pseId; - } - - /** - * @param mixed $pseId - * @return PsePriceEvent - */ - public function setPseId($pseId) - { - $this->pseId = $pseId; - return $this; - } - - /** - * @return mixed - */ - public function getCountryId() - { - return $this->countryId; - } - - /** - * @param mixed $countryId - * @return PsePriceEvent - */ - public function setCountryId($countryId) - { - $this->countryId = $countryId; - return $this; - } - - /** - * @return null - */ - public function getCustomerId() - { - return $this->customerId; - } - - /** - * @param null $customerId - * @return PsePriceEvent - */ - public function setCustomerId($customerId) - { - $this->customerId = $customerId; - return $this; - } - - /** - * @return mixed - */ - public function getPrice() - { - return $this->price; - } - - /** - * @param mixed $price - * @return PsePriceEvent - */ - public function setPrice($price) - { - $this->price = $price; - return $this; - } - - /** - * @return mixed - */ - public function getPromoPrices() - { - return $this->promoPrices; - } - - /** - * @param mixed $promoPrices - * @return PsePriceEvent - */ - public function setPromoPrices($promoPrices) - { - $this->promoPrices = $promoPrices; - return $this; - } -} \ No newline at end of file diff --git a/Event/SearchEvent/SearchFilterEvent.php b/Event/SearchEvent/SearchFilterEvent.php new file mode 100644 index 0000000..b962c34 --- /dev/null +++ b/Event/SearchEvent/SearchFilterEvent.php @@ -0,0 +1,75 @@ +request = $request; + } + + /** + * @return Request + */ + public function getRequest() + { + return $this->request; + } + + /** + * @param Request $request + * + * @return SearchFilterEvent + */ + public function setRequest($request) + { + $this->request = $request; + return $this; + } + + /** + * @return array + */ + public function getFilters() + { + return $this->filters; + } + + /** + * @param array $filters + * + * @return SearchFilterEvent + */ + public function setFilters($filters) + { + $this->filters = $filters; + return $this; + } + + /** + * @param $value + * + * @return $this + */ + public function addFilter($value) + { + $this->filters[] = $value; + return $this; + } +} \ No newline at end of file diff --git a/Service/IndexationService.php b/Service/IndexationService.php index 54671d1..cb2f59e 100644 --- a/Service/IndexationService.php +++ b/Service/IndexationService.php @@ -3,6 +3,7 @@ namespace ElasticProduct\Service; use ElasticProduct\ElasticProduct; +use ElasticProduct\Event\ProductIndexationEvent; use Propel\Runtime\Propel; use Symfony\Component\EventDispatcher\EventDispatcher; use Thelia\Action\Image; @@ -105,7 +106,7 @@ public function indexProduct(Product $product) 'product' => $this->getProductData($product), 'brand' => $this->getBrandData($product), 'categories' => $this->getCategoriesData($product), - 'features' => $this->getFeaturesData($product), + 'features' => $this->getFeaturesData($product) ]; $productSaleElementsRelatedBody = []; @@ -229,7 +230,7 @@ protected function getProductSaleElementsData(ProductSaleElements $productSaleEl ]; } - protected function getFeaturesData(Product $product) + protected function getFeaturesData(Product $product) { $productFeatures = $product->getFeatureProducts(); $features = []; @@ -300,16 +301,23 @@ protected function getProductData(Product $product) $langData = $this->getLangData($product->getProductI18ns(), true, $product, 'product'); $imageData = $this->getImageData($product->getProductImages(), 'product'); - return [ - 'id' => $product->getId(), - 'ref' => $product->getRef(), - 'is_visible' => !!$product->getVisible(), - 'i18ns' => $langData['i18ns'], - 'urls' => $langData['urls'], - 'images' => $imageData, - 'created_at' => $product->getCreatedAt('Y-m-d H:i:s'), - 'updated_at' => $product->getUpdatedAt('Y-m-d H:i:s') - ]; + $productIndexationEvent = new ProductIndexationEvent($product); + $productIndexationEvent->setProductData( + [ + 'id' => $product->getId(), + 'ref' => $product->getRef(), + 'is_visible' => !!$product->getVisible(), + 'i18ns' => $langData['i18ns'], + 'urls' => $langData['urls'], + 'images' => $imageData, + 'created_at' => $product->getCreatedAt('Y-m-d H:i:s'), + 'updated_at' => $product->getUpdatedAt('Y-m-d H:i:s') + ] + ); + $this->eventDispatcher->dispatch(ProductIndexationEvent::GET_PRODUCT_DATA_EVENT, $productIndexationEvent); + + + return $productIndexationEvent->getProductData(); } protected function getLangData($i18ns, $withUrl = false, $model = null, $viewName = '')