Skip to content

Commit

Permalink
Merge pull request #620 from magento-folks/bugfix
Browse files Browse the repository at this point in the history
[Folks] Bugfix
  • Loading branch information
Oleksii Korshenko authored Nov 30, 2016
2 parents 1387fe0 + 2029e00 commit 6f19a3d
Show file tree
Hide file tree
Showing 24 changed files with 581 additions and 59 deletions.
8 changes: 4 additions & 4 deletions app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ protected function _prepareTierPriceIndex($entityIds = null)
null
)->join(
['e' => $this->getTable('catalog_product_entity')],
"i.entity_id=e.$linkField",
"i.entity_id=e.entity_id",
[]
)->where(
'e.type_id=?',
Expand All @@ -502,7 +502,7 @@ protected function _prepareTierPriceIndex($entityIds = null)

$select = $connection->select()->from(
['tp' => $this->getTable('catalog_product_entity_tier_price')],
[$linkField]
['e.entity_id']
)->join(
['e' => $this->getTable('catalog_product_entity')],
"tp.{$linkField} = e.{$linkField}",
Expand All @@ -523,11 +523,11 @@ protected function _prepareTierPriceIndex($entityIds = null)
)->columns(
new \Zend_Db_Expr('MIN(tp.value)')
)->group(
["tp.{$linkField}", 'cg.customer_group_id', 'cw.website_id']
['e.entity_id', 'cg.customer_group_id', 'cw.website_id']
);

if (!empty($entityIds)) {
$select->where("tp.{$linkField} IN(?)", $entityIds);
$select->where('e.entity_id IN(?)', $entityIds);
}

$query = $select->insertFromSelect($this->_getTierPriceIndexTable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function _construct()
$widget = $this->registry->registry('current_widget_instance');
if ($widget) {
$widgetParameters = $widget->getWidgetParameters();
} elseif($widgetOptions = $this->getLayout()->getBlock('wysiwyg_widget.options')) {
} elseif ($widgetOptions = $this->getLayout()->getBlock('wysiwyg_widget.options')) {
$widgetParameters = $widgetOptions->getWidgetValues();
}

Expand All @@ -100,6 +100,7 @@ protected function _construct()
public function render(AbstractElement $element)
{
$this->element = $element;
$this->rule->getConditions()->setJsFormObject($this->getHtmlId());
return $this->toHtml();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

/**
* Test class for \Magento\CatalogWidget\Block\Product\Widget\Conditions
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ConditionsTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -175,4 +176,116 @@ public function testConstructWithParamsFromBlock()
]
);
}

/**
* @return void
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testRender()
{
$data = ['area' => 'backend'];
$abstractElementMock = $this->getMock(
\Magento\Framework\Data\Form\Element\AbstractElement::class,
['getContainer'],
[],
'',
false
);
$eventManagerMock = $this->getMock(
\Magento\Framework\Event\ManagerInterface::class,
[],
[],
'',
false
);
$scopeConfigMock = $this->getMock(
\Magento\Framework\App\Config\ScopeConfigInterface::class,
[],
[],
'',
false
);
$fieldsetMock = $this->getMock(
\Magento\Framework\Data\Form\Element\Fieldset::class,
[],
[],
'',
false
);
$combineMock = $this->getMock(
\Magento\Rule\Model\Condition\Combine::class,
[],
[],
'',
false
);
$resolverMock = $this->getMock(
\Magento\Framework\View\Element\Template\File\Resolver::class,
[],
[],
'',
false
);
$filesystemMock = $this->getMock(
\Magento\Framework\Filesystem::class,
['getDirectoryRead'],
[],
'',
false
);
$validatorMock = $this->getMock(
\Magento\Framework\View\Element\Template\File\Validator::class,
[],
[],
'',
false
);
$templateEnginePoolMock = $this->getMock(
\Magento\Framework\View\TemplateEnginePool::class,
[],
[],
'',
false
);
$templateEngineMock = $this->getMock(
\Magento\Framework\View\TemplateEngineInterface::class,
[],
[],
'',
false
);
$directoryReadMock = $this->getMock(
\Magento\Framework\Filesystem\Directory\ReadInterface::class,
[],
[],
'',
false
);

$this->ruleMock->expects($this->once())->method('getConditions')->willReturn($combineMock);
$combineMock->expects($this->once())->method('setJsFormObject')->willReturnSelf();
$abstractElementMock->expects($this->any())->method('getContainer')->willReturn($fieldsetMock);
$filesystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($directoryReadMock);
$validatorMock->expects($this->once())->method('isValid')->willReturn(true);
$this->contextMock->expects($this->once())->method('getEnginePool')->willReturn($templateEnginePoolMock);
$templateEnginePoolMock->expects($this->once())->method('get')->willReturn($templateEngineMock);
$templateEngineMock->expects($this->once())->method('render')->willReturn('html');

$this->widgetConditions = $this->objectManagerHelper->getObject(
Conditions::class,
[
'context' => $this->contextMock,
'registry' => $this->registryMock,
'rule' => $this->ruleMock,
'_eventManager' => $eventManagerMock,
'_filesystem' => $filesystemMock,
'_scopeConfig' => $scopeConfigMock,
'validator' => $validatorMock,
'resolver' => $resolverMock,
'data' => $data
]
);

$this->assertEquals($this->widgetConditions->render($abstractElementMock), 'html');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
namespace Magento\OfflineShipping\Model\Quote\Address;

use Magento\Quote\Model\Quote\Address;

class FreeShipping implements \Magento\Quote\Model\Quote\Address\FreeShippingInterface
{
/**
Expand Down Expand Up @@ -48,7 +46,8 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
$quote->getCustomerGroupId(),
$quote->getCouponCode()
);

$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setFreeShipping(0);
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
foreach ($items as $item) {
if ($item->getNoDiscount()) {
Expand All @@ -66,10 +65,14 @@ public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
$itemFreeShipping = (bool)$item->getFreeShipping();
$addressFreeShipping = $addressFreeShipping && $itemFreeShipping;

if ($addressFreeShipping && !$item->getAddress()->getFreeShipping()) {
$item->getAddress()->setFreeShipping(true);
}

/** Parent free shipping we apply to all children*/
$this->applyToChildren($item, $itemFreeShipping);
}
return $addressFreeShipping;
return (bool)$shippingAddress->getFreeShipping();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\OfflineShipping\Test\Unit\Model\Quote\Address;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class FreeShippingTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\OfflineShipping\Model\Quote\Address\FreeShipping
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface
*/
private $storeManagerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\OfflineShipping\Model\SalesRule\Calculator
*/
private $calculatorMock;

protected function setUp()
{
$this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
$this->calculatorMock = $this->getMock(
\Magento\OfflineShipping\Model\SalesRule\Calculator::class,
[],
[],
'',
false
);

$this->model = new \Magento\OfflineShipping\Model\Quote\Address\FreeShipping(
$this->storeManagerMock,
$this->calculatorMock
);
}

public function testIsFreeShippingIfNoItems()
{
$quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false);
$this->assertFalse($this->model->isFreeShipping($quoteMock, []));
}

public function testIsFreeShipping()
{
$storeId = 100;
$websiteId = 200;
$customerGroupId = 300;
$objectManagerMock = new ObjectManagerHelper($this);
$quoteMock = $this->getMock(
\Magento\Quote\Model\Quote::class,
['getShippingAddress', 'getStoreId', 'getCustomerGroupId', 'getCouponCode'],
[],
'',
false
);
$itemMock = $this->getMock(
\Magento\Quote\Model\Quote\Item::class,
[
'getNoDiscount',
'getParentItemId',
'getFreeShipping',
'getAddress',
'isChildrenCalculated',
'getHasChildren',
'getChildren'
],
[],
'',
false
);

$quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
$storeMock = $this->getMock(\Magento\Store\Api\Data\StoreInterface::class);
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
$this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock);

$quoteMock->expects($this->once())->method('getCustomerGroupId')->willReturn($customerGroupId);
$quoteMock->expects($this->once())->method('getCouponCode')->willReturn(null);

$this->calculatorMock->expects($this->once())
->method('init')
->with($websiteId, $customerGroupId, null)
->willReturnSelf();

$itemMock->expects($this->once())->method('getNoDiscount')->willReturn(false);
$itemMock->expects($this->once())->method('getParentItemId')->willReturn(false);
$this->calculatorMock->expects($this->exactly(2))->method('processFreeShipping')->willReturnSelf();
$itemMock->expects($this->once())->method('getFreeShipping')->willReturn(true);

$addressMock = $objectManagerMock->getObject(\Magento\Quote\Model\Quote\Address::class);
$quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($addressMock);
$itemMock->expects($this->exactly(2))->method('getAddress')->willReturn($addressMock);

$itemMock->expects($this->once())->method('getHasChildren')->willReturn(true);
$itemMock->expects($this->once())->method('isChildrenCalculated')->willReturn(true);

$childMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, ['setFreeShipping'], [], '', false);
$childMock->expects($this->once())->method('setFreeShipping')->with(true)->willReturnSelf();
$itemMock->expects($this->once())->method('getChildren')->willReturn([$childMock]);

$this->assertTrue($this->model->isFreeShipping($quoteMock, [$itemMock]));
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/Sales/Block/Status/Grid/Column/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public function getFrameCallback()
*/
public function decorateState($value, $row, $column, $isExport)
{
$status = $row->getStatus();
if ($value) {
$cell = $value . '[' . $this->_config->getStateLabel($value) . ']';
$cell = $value . '[' . $this->_config->getStateLabelByStateAndStatus($value, $status) . ']';
} else {
$cell = $value;
}
Expand Down
18 changes: 18 additions & 0 deletions app/code/Magento/Sales/Model/Order/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,22 @@ protected function _getStatuses($visibility)
}
return $this->statuses[(bool) $visibility];
}

/**
* Retrieve label by state and status
*
* @param string $state
* @param string $status
* @return \Magento\Framework\Phrase|string
*/
public function getStateLabelByStateAndStatus($state, $status)
{
foreach ($this->_getCollection() as $item) {
if ($item->getData('state') == $state && $item->getData('status') == $status) {
$label = $item->getData('label');
return __($label);
}
}
return $state;
}
}
5 changes: 3 additions & 2 deletions app/code/Magento/Sales/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
'sales_shipment_grid',
];
foreach ($tables as $table) {
$setup->getConnection()->modifyColumn(
$setup->getTable($table),
$salesConnection = $setup->getConnection(self::$connectionName);
$salesConnection->modifyColumn(
$installer->getTable($table, self::$connectionName),
'customer_group_id',
['type' => 'integer']
);
Expand Down
Loading

0 comments on commit 6f19a3d

Please sign in to comment.