/** * Replace original configurable product with first child * * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @param \Magento\Catalog\Block\Product\AbstractProduct $subject * @param \Magento\Catalog\Model\Product $product * @param string $location * @param array $attributes * @return array */ public function beforeGetImage(\Magento\Catalog\Block\Product\AbstractProduct $subject, \Magento\Catalog\Model\Product $product, $location, array $attributes = []) { if ($product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE && ($location == self::CATEGORY_PAGE_GRID_LOCATION || $location == self::CATEGORY_PAGE_LIST_LOCATION)) { $request = $this->request->getParams(); if (is_array($request)) { $filterArray = $this->getFilterArray($request); if (!empty($filterArray)) { $product = $this->loadSimpleVariation($product, $filterArray); } } } return [$product, $location, $attributes]; }
/** * @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; }