_productCollectionFactory = $productCollectionFactory; $this->helper = $helperData; $this->outputHelper = $output; $this->catalogProductTypeConfigurable = $catalogProductTypeConfigurable; $this->productRepository = $productRepository; parent::__construct($context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper, $data); } /** * @return Output */ public function getHelper() { return $this->outputHelper; } /** * @return mixed */ public function relatedMode() { return $this->helper->getModuleConfig('product_post/post_detail/related_mode'); } /** * @return mixed */ public function hasProduct() { $collection = $this->_getProductCollection(); return $collection->getSize(); } /** * Get ProductCollection in same brand (filter by Attribute Option_Id) * * @return mixed */ public function _getProductCollection() { if ($this->_productCollection === null) { $postId = $this->getRequest()->getParam('id'); $collection = $this->_productCollectionFactory->create() ->addAttributeToSelect('*') ->addStoreFilter(); $collection->getSelect() ->join( ['product_post' => $collection->getTable('mageplaza_blog_post_product')], 'e.entity_id = product_post.entity_id' ) ->where('product_post.post_id = ' . $postId) ->order('product_post.position ASC') ->limit((int) $this->helper->getBlogConfig('product_post/post_detail/product_limit') ?: self::LIMIT); $this->_productCollection = $collection; } return $this->_productCollection; } /** * @inheritdoc */ public function getMode() { return 'grid'; } /** * @inheritdoc */ public function getToolbarHtml() { return null; } /** * @inheritdoc */ public function getAdditionalHtml() { return null; } /** * @inheritdoc */ protected function _beforeToHtml() { return $this; } /** * @param Product $product * * @return mixed */ public function getParentProductUrl($product) { $parentByChild = $this->catalogProductTypeConfigurable->getParentIdsByChild($product->getId()); if (isset($parentByChild[0])) { try { $parentProduct = $this->productRepository->getById($parentByChild[0]); return $parentProduct->getProductUrl(); } catch (Exception $e) { return $product->getProductUrl(); } } return $product->getProductUrl(); } }