コード例 #1
0
ファイル: Adapter.php プロジェクト: boxalino/plugin-magento2
 /**
  * @return \com\boxalino\bxclient\v1\BxFacets
  */
 private function prepareFacets()
 {
     $bxFacets = new \com\boxalino\bxclient\v1\BxFacets();
     $selectedValues = array();
     $requestParams = $this->request->getParams();
     $attributeCollection = $this->bxHelperData->getFilterProductAttributes();
     foreach ($requestParams as $key => $values) {
         if (strpos($key, $this->getUrlParameterPrefix()) === 0) {
             $fieldName = substr($key, 3);
             $selectedValues[$fieldName] = !is_array($values) ? array($values) : $values;
         }
         if (isset($attributeCollection['products_' . $key])) {
             $paramValues = !is_array($values) ? array($values) : $values;
             $attributeModel = $this->_modelConfig->getAttribute('catalog_product', $key)->getSource();
             foreach ($paramValues as $paramValue) {
                 $selectedValues['products_' . $key][] = $attributeModel->getOptionText($paramValue);
             }
         }
     }
     if (!$this->navigation) {
         $catId = isset($selectedValues['category_id']) && sizeof($selectedValues['category_id']) > 0 ? $selectedValues['category_id'][0] : null;
         $bxFacets->addCategoryFacet($catId);
     }
     foreach ($attributeCollection as $code => $attribute) {
         if ($this->navigation && $code == 'categories') {
             $this->bxHelperData->setRemovedAttributes($code);
             continue;
         }
         $bound = $code == 'discountedPrice' ? true : false;
         list($label, $type, $order, $position) = array_values($attribute);
         $selectedValue = isset($selectedValues[$code]) ? $selectedValues[$code][0] : null;
         $bxFacets->addFacet($code, $selectedValue, $type, $label, $order, $bound);
     }
     list($topField, $topOrder) = $this->bxHelperData->getTopFacetValues();
     if ($topField) {
         $selectedValue = isset($selectedValues[$topField][0]) ? $selectedValues[$topField][0] : null;
         $bxFacets->addFacet($topField, $selectedValue, "string", $topField, $topOrder);
     }
     return $bxFacets;
 }