Skip to content

Commit 8892f35

Browse files
committed
Merge pull request #464 from magento-troll/MAGETWO-39957
[Troll] Bugfix
2 parents 6358fee + 8383532 commit 8892f35

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,14 @@ public function getAffectedFields($object)
432432

433433
return $data;
434434
}
435+
436+
/**
437+
* Get resource model instance
438+
*
439+
* @return \Magento\Catalog\Model\Resource\Product\Attribute\Backend\GroupPrice
440+
*/
441+
public function getResource()
442+
{
443+
return $this->_getResource();
444+
}
435445
}

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,17 @@ protected function getRuleProductsStmt($websiteId, $productId = null)
612612
$select->where('rp.product_id=?', $productId);
613613
}
614614

615+
/**
616+
* Join group price to result
617+
*/
618+
$groupPriceAttr = $this->eavConfig->getAttribute(Product::ENTITY, 'group_price');
619+
$select->joinLeft(
620+
['gp' => $groupPriceAttr->getBackend()->getResource()->getMainTable()],
621+
'gp.entity_id=rp.product_id AND gp.customer_group_id=rp.customer_group_id AND '
622+
. $this->getReadAdapter()->getCheckSql('gp.website_id=0', 'TRUE', 'gp.website_id=rp.website_id'),
623+
'value'
624+
);
625+
615626
/**
616627
* Join default price and websites prices to result
617628
*/
@@ -653,7 +664,10 @@ protected function getRuleProductsStmt($websiteId, $productId = null)
653664
[]
654665
);
655666
$select->columns([
656-
'default_price' => $this->getReadAdapter()->getIfNullSql($tableAlias . '.value', 'pp_default.value'),
667+
'default_price' => $this->getReadAdapter()->getIfNullSql(
668+
'gp.value',
669+
$this->getReadAdapter()->getIfNullSql($tableAlias . '.value', 'pp_default.value')
670+
),
657671
]);
658672

659673
return $read->query($select);

app/code/Magento/CatalogRule/Test/Unit/Model/Indexer/IndexBuilderTest.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected function setUp()
148148
$this->priceCurrency = $this->getMock('Magento\Framework\Pricing\PriceCurrencyInterface');
149149
$this->dateFormat = $this->getMock('Magento\Framework\Stdlib\DateTime', [], [], '', false);
150150
$this->dateTime = $this->getMock('Magento\Framework\Stdlib\DateTime\DateTime', [], [], '', false);
151-
$this->eavConfig = $this->getMock('Magento\Eav\Model\Config', [], [], '', false);
151+
$this->eavConfig = $this->getMock('Magento\Eav\Model\Config', ['getAttribute'], [], '', false);
152152
$this->product = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
153153
$this->productFactory = $this->getMock('Magento\Catalog\Model\ProductFactory', ['create'], [], '', false);
154154

@@ -182,7 +182,6 @@ protected function setUp()
182182

183183
$this->combine->expects($this->any())->method('validate')->will($this->returnValue(true));
184184
$this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
185-
$this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->attribute));
186185
$this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
187186

188187
$this->indexBuilder = new \Magento\CatalogRule\Model\Indexer\IndexBuilder(
@@ -206,6 +205,45 @@ protected function setUp()
206205
*/
207206
public function testUpdateCatalogRuleGroupWebsiteData()
208207
{
208+
$groupPriceAttrMock = $this->getMock(
209+
'Magento\Catalog\Model\Entity\Attribute',
210+
['getBackend'],
211+
[],
212+
'',
213+
false
214+
);
215+
$backendModelMock = $this->getMock(
216+
'Magento\Catalog\Model\Product\Attribute\Backend\GroupPrice',
217+
['getResource'],
218+
[],
219+
'',
220+
false
221+
);
222+
$resourceMock = $this->getMock(
223+
'Magento\Catalog\Model\Resource\Product\Attribute\Backend\GroupPrice',
224+
['getMainTable'],
225+
[],
226+
'',
227+
false
228+
);
229+
$resourceMock->expects($this->once())
230+
->method('getMainTable')
231+
->will($this->returnValue('catalog_product_entity_group_price'));
232+
$backendModelMock->expects($this->once())
233+
->method('getResource')
234+
->will($this->returnValue($resourceMock));
235+
$groupPriceAttrMock->expects($this->once())
236+
->method('getBackend')
237+
->will($this->returnValue($backendModelMock));
238+
$this->eavConfig->expects($this->at(0))
239+
->method('getAttribute')
240+
->with(\Magento\Catalog\Model\Product::ENTITY, 'group_price')
241+
->will($this->returnValue($groupPriceAttrMock));
242+
$this->eavConfig->expects($this->at(1))
243+
->method('getAttribute')
244+
->with(\Magento\Catalog\Model\Product::ENTITY, 'price')
245+
->will($this->returnValue($this->attribute));
246+
209247
$this->select->expects($this->once())->method('insertFromSelect')->with('catalogrule_group_website');
210248

211249
$this->indexBuilder->reindexByIds([1]);

0 commit comments

Comments
 (0)