Beispiel #1
0
 /**
  * @param $widgetName
  * @param array $context
  * @param string $widgetType
  * @param int $minAmount
  * @param int $amount
  * @param bool $execute
  * @return array|void
  */
 public function getRecommendation($widgetName, $context = array(), $widgetType = '', $minAmount = 3, $amount = 3, $execute = true)
 {
     if (!$execute) {
         if (!isset(self::$choiceContexts[$widgetName])) {
             self::$choiceContexts[$widgetName] = array();
         }
         if (in_array(json_encode($context), self::$choiceContexts[$widgetName])) {
             return;
         }
         self::$choiceContexts[$widgetName][] = json_encode($context);
         if ($widgetType == '') {
             $bxRequest = new \com\boxalino\bxclient\v1\BxRecommendationRequest($this->bxHelperData->getLanguage(), $widgetName, $amount);
             $bxRequest->setGroupBy('products_group_id');
             $bxRequest->setMin($minAmount);
             $bxRequest->setFilters($this->getSystemFilters());
             if (isset($context[0])) {
                 $product = $context[0];
                 $bxRequest->setProductContext($this->getEntityIdFieldName(), $product->getId());
             }
             self::$bxClient->addRequest($bxRequest);
         } else {
             if ($minAmount >= 0 && $amount >= 0 && $minAmount <= $amount) {
                 $bxRequest = new \com\boxalino\bxclient\v1\BxRecommendationRequest($this->bxHelperData->getLanguage(), $widgetName, $amount, $minAmount);
                 $bxRequest->setGroupBy('products_group_id');
                 $bxRequest->setFilters($this->getSystemFilters());
                 $bxRequest->setReturnFields(array($this->getEntityIdFieldName()));
                 if ($widgetType === 'basket' && is_array($context)) {
                     $basketProducts = array();
                     foreach ($context as $product) {
                         $basketProducts[] = array('id' => $product->getId(), 'price' => $product->getPrice());
                     }
                     $bxRequest->setBasketProductWithPrices($this->getEntityIdFieldName(), $basketProducts);
                 } elseif ($widgetType === 'product' && !is_array($context)) {
                     $product = $context;
                     $bxRequest->setProductContext($this->getEntityIdFieldName(), $product->getId());
                 } elseif ($widgetType === 'category' && $context != null) {
                     $filterField = "category_id";
                     $filterValues = is_array($context) ? $context : array($context);
                     $filterNegative = false;
                     $bxRequest->addFilter(new BxFilter($filterField, $filterValues, $filterNegative));
                 }
                 self::$bxClient->addRequest($bxRequest);
             }
         }
         return array();
     }
     $count = array_search(json_encode(array($context)), self::$choiceContexts[$widgetName]);
     return $this->getClientResponse()->getHitIds($widgetName, true, $count, 10, $this->getEntityIdFieldName());
 }