Skip to content

Commit

Permalink
Merge pull request #685 from romainruaud/fix-autocomplete-special-price
Browse files Browse the repository at this point in the history
Fix autocomplete special price
  • Loading branch information
afoucret authored Jan 17, 2018
2 parents 1005118 + 58f4a05 commit b539329
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AttributeConfig
/**
* @var string[]
*/
private $defaultSelectedAttributes = ['name', 'thumbnail'];
private $defaultSelectedAttributes = ['name', 'thumbnail', 'special_price', 'special_from_date', 'special_to_date'];

/**
* @var string[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ItemFactory extends \Magento\Search\Model\Autocomplete\ItemFactory
/**
* @var \Magento\Framework\Pricing\Render
*/
private $priceRenderer;
private $priceRenderer = null;

/**
* @var ObjectManagerInterface
Expand All @@ -58,19 +58,16 @@ class ItemFactory extends \Magento\Search\Model\Autocomplete\ItemFactory
*
* @param ObjectManagerInterface $objectManager Object manager used to instantiate new item.
* @param ImageHelper $imageHelper Catalog product image helper.
* @param Render $priceRenderer Catalog product price renderer.
* @param AttributeConfig $attributeConfig Autocomplete attribute config.
*/
public function __construct(
ObjectManagerInterface $objectManager,
ImageHelper $imageHelper,
Render $priceRenderer,
AttributeConfig $attributeConfig
) {
parent::__construct($objectManager);
$this->attributes = $attributeConfig->getAdditionalSelectedAttributes();
$this->imageHelper = $imageHelper;
$this->priceRenderer = $priceRenderer;
$this->objectManager = $objectManager;
}

Expand Down Expand Up @@ -169,19 +166,23 @@ private function renderProductPrice(\Magento\Catalog\Model\Product $product, $pr
*/
private function getPriceRenderer()
{
/** @var \Magento\Framework\View\LayoutInterface $layout */
$layout = $this->objectManager->get('\Magento\Framework\View\LayoutInterface');
$layout->getUpdate()->addHandle('default');
$priceRenderer = $layout->getBlock('product.price.render.default');

if (!$priceRenderer) {
$priceRenderer = $layout->createBlock(
'Magento\Framework\Pricing\Render',
'product.price.render.default',
['data' => ['price_render_handle' => 'catalog_product_prices']]
);
if (null === $this->priceRenderer) {
/** @var \Magento\Framework\View\LayoutInterface $layout */
$layout = $this->objectManager->get('\Magento\Framework\View\LayoutInterface');
$layout->getUpdate()->addHandle('default');
$priceRenderer = $layout->getBlock('product.price.render.default');

if (!$priceRenderer) {
$priceRenderer = $layout->createBlock(
'Magento\Framework\Pricing\Render',
'product.price.render.default',
['data' => ['price_render_handle' => 'catalog_product_prices']]
);
}

$this->priceRenderer = $priceRenderer;
}

return $priceRenderer;
return $this->priceRenderer;
}
}

0 comments on commit b539329

Please sign in to comment.