Skip to content

Commit

Permalink
Added support for grouped products
Browse files Browse the repository at this point in the history
  • Loading branch information
sydekumf committed May 8, 2017
1 parent da344b2 commit 24d6661
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Model/Plugin/AfterPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,28 @@ protected function _getAfterPriceHtml()
// check if product is available
if (!$product) return '';

// if a grouped product is given we need the current child
if ($product->getTypeId() == 'grouped') {
$product = $product->getPriceInfo()
->getPrice(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)
->getMinProduct();
}

// check if price for current product has been rendered before
if (!array_key_exists($product->getId(), $this->_afterPriceHtml)) {
$afterPriceBlock = $this->_layout->createBlock(
'Magenerds\BasePrice\Block\AfterPrice',
'baseprice_afterprice_' . $product->getId(),
['product' => $product]
);

// use different templates for configurables and other product types
if ($product->getTypeId() == 'configurable') {
$templateFile = 'Magenerds_BasePrice::configurable/afterprice.phtml';
} else {
$templateFile = 'Magenerds_BasePrice::afterprice.phtml';
}

$afterPriceBlock->setTemplate($templateFile);
$this->_afterPriceHtml[$product->getId()] = $afterPriceBlock->toHtml();
}
Expand Down
67 changes: 67 additions & 0 deletions Model/Plugin/Grouped.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Magenerds\BasePrice\Model\Plugin\Grouped
*
* Copyright (c) 2016 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* [email protected]
*/

/**
* @category Magenerds
* @package Magenerds_BasePrice
* @subpackage Model
* @copyright Copyright (c) 2016 TechDivision GmbH (http://www.techdivision.com)
* @version ${release.version}
* @link http://www.techdivision.com/
* @author Florian Sydekum <[email protected]>
*/
namespace Magenerds\BasePrice\Model\Plugin;

use Magento\GroupedProduct\Model\Product\Type\Grouped as CoreGrouped;

/**
* Class AfterPrice
* @package Magenerds\BasePrice\Model\Plugin
*/
class Grouped extends CoreGrouped
{
/**
* @inheritdoc
* overwritten in order to add base price attributes to select
*/
public function getAssociatedProducts($product)
{
if (!$product->hasData($this->_keyAssociatedProducts)) {
$associatedProducts = [];

$this->setSaleableStatus($product);

$collection = $this->getAssociatedProductCollection(
$product
)->addAttributeToSelect(
[
'name', 'price', 'special_price', 'special_from_date', 'special_to_date',
'baseprice_reference_amount', 'baseprice_product_amount', 'baseprice_product_unit', 'baseprice_reference_unit', 'baseprice_reference_amount'
]
)->addFilterByRequiredOptions()->setPositionOrder()->addStoreFilter(
$this->getStoreFilter($product)
)->addAttributeToFilter(
'status',
['in' => $this->getStatusFilters($product)]
);

foreach ($collection as $item) {
$associatedProducts[] = $item;
}

$product->setData($this->_keyAssociatedProducts, $associatedProducts);
}
return $product->getData($this->_keyAssociatedProducts);
}
}
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
<type name="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable">
<plugin name="magenerds_baseprice_configurablePriceRender" type="Magenerds\BasePrice\Model\Plugin\ConfigurablePrice" />
</type>
<preference for="Magento\GroupedProduct\Model\Product\Type\Grouped" type="Magenerds\BasePrice\Model\Plugin\Grouped"/>
</config>

0 comments on commit 24d6661

Please sign in to comment.