Skip to content

Commit

Permalink
MAGETWO-71896: Merge branch 'develop' of github.com:magento/magento2c…
Browse files Browse the repository at this point in the history
…e into MAGETWO-71896-PR-10638
  • Loading branch information
ishakhsuvarov committed Sep 4, 2017
2 parents 4b09ffd + e05217d commit 58694a6
Show file tree
Hide file tree
Showing 56 changed files with 2,000 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function getDefaultValues()
*/
protected function _getSelectedOptions()
{
if (is_null($this->_selectedOptions)) {
if ($this->_selectedOptions === null) {
$this->_selectedOptions = [];

/** @var \Magento\Bundle\Model\Option $option */
Expand All @@ -152,17 +152,29 @@ protected function _getSelectedOptions()
$selectionId = $this->getProduct()->getPreconfiguredValues()->getData(
'bundle_option/' . $option->getId()
);
if ($selectionId && $option->getSelectionById($selectionId)) {
$this->_selectedOptions = $selectionId;
} elseif (!$option->getRequired()) {
$this->_selectedOptions = 'None';
}
$this->assignSelection($option, $selectionId);
}
}

return $this->_selectedOptions;
}

/**
* Set selected options.
*
* @param \Magento\Bundle\Model\Option $option
* @param mixed $selectionId
* @return void
*/
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
{
if ($selectionId && $option->getSelectionById($selectionId)) {
$this->_selectedOptions = $selectionId;
} elseif (!$option->getRequired()) {
$this->_selectedOptions = 'None';
}
}

/**
* Define if selection is selected
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,20 @@ class Multi extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Optio
* @var string
*/
protected $_template = 'catalog/product/view/type/bundle/option/multi.phtml';

/**
* @inheritdoc
*/
protected function assignSelection(\Magento\Bundle\Model\Option $option, $selectionId)
{
if (is_array($selectionId)) {
foreach ($selectionId as $id) {
if ($id && $option->getSelectionById($id)) {
$this->_selectedOptions[] = $id;
}
}
} else {
parent::assignSelection($option, $selectionId);
}
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
$options
);

$optionsCollection->appendSelections($selections, false, $_appendAllSelections);
$optionsCollection->appendSelections($selections, true, $_appendAllSelections);

$selections = $selections->getItems();
} else {
Expand All @@ -704,7 +704,7 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
->getOptionsIds($product);
$selectionCollection = $product->getTypeInstance()
->getSelectionsCollection($optionIds, $product);
$options = $optionCollection->appendSelections($selectionCollection, false, $_appendAllSelections);
$options = $optionCollection->appendSelections($selectionCollection, true, $_appendAllSelections);

$selections = $this->mergeSelectionsWithOptions($options, $selections);
}
Expand Down
13 changes: 9 additions & 4 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public function testPrepareForCartAdvancedWithoutOptions()
->willReturn($productType);
$optionCollection->expects($this->any())
->method('appendSelections')
->with($selectionCollection, true, true)
->willReturn([$option]);
$productType->expects($this->once())
->method('setStoreFilter');
Expand Down Expand Up @@ -433,7 +434,8 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('getItemById')
->willReturn($option);
$optionCollection->expects($this->once())
->method('appendSelections');
->method('appendSelections')
->with($selectionCollection, true, true);
$productType->expects($this->once())
->method('setStoreFilter');
$buyRequest->expects($this->once())
Expand Down Expand Up @@ -668,7 +670,8 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('getItemById')
->willReturn($option);
$optionCollection->expects($this->once())
->method('appendSelections');
->method('appendSelections')
->with($selectionCollection, true, true);
$productType->expects($this->once())
->method('setStoreFilter');
$buyRequest->expects($this->once())
Expand Down Expand Up @@ -891,7 +894,8 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('getItemById')
->willReturn($option);
$optionCollection->expects($this->once())
->method('appendSelections');
->method('appendSelections')
->with($selectionCollection, true, true);
$productType->expects($this->once())
->method('setStoreFilter');
$buyRequest->expects($this->once())
Expand Down Expand Up @@ -1169,7 +1173,8 @@ function ($key) use ($optionCollection, $selectionCollection) {
}
);
$optionCollection->expects($this->once())
->method('appendSelections');
->method('appendSelections')
->with($selectionCollection, true, true);
$productType->expects($this->once())
->method('setStoreFilter');
$buyRequest->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<?php
$product = $block->getProduct();
$helper = $this->helper('Magento\Catalog\Helper\Output');
$stripSelection = $product->getConfigureMode() ? true : false;
$options = $block->decorateArray($block->getOptions($stripSelection));
?>
<?php $options = $block->decorateArray($block->getOptions()); ?>
<?php if ($product->isSaleable()):?>
<?php if (count($options)): ?>
<script type="text/x-magento-init">
Expand Down
15 changes: 13 additions & 2 deletions app/code/Magento/Catalog/Pricing/Price/TierPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\Framework\Pricing\Price\AbstractPrice;
use Magento\Framework\Pricing\Price\BasePriceProviderInterface;
use Magento\Framework\Pricing\PriceInfoInterface;
use Magento\Customer\Model\Group\RetrieverInterface as CustomerGroupRetrieverInterface;

/**
* @api
Expand All @@ -30,6 +31,7 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr

/**
* @var Session
* @deprecated
*/
protected $customerSession;

Expand Down Expand Up @@ -57,30 +59,39 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
*/
protected $groupManagement;

/**
* @var CustomerGroupRetrieverInterface
*/
private $customerGroupRetriever;

/**
* @param Product $saleableItem
* @param float $quantity
* @param CalculatorInterface $calculator
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
* @param Session $customerSession
* @param GroupManagementInterface $groupManagement
* @param CustomerGroupRetrieverInterface|null $customerGroupRetriever
*/
public function __construct(
Product $saleableItem,
$quantity,
CalculatorInterface $calculator,
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
Session $customerSession,
GroupManagementInterface $groupManagement
GroupManagementInterface $groupManagement,
CustomerGroupRetrieverInterface $customerGroupRetriever = null
) {
$quantity = floatval($quantity) ? $quantity : 1;
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
$this->customerSession = $customerSession;
$this->groupManagement = $groupManagement;
$this->customerGroupRetriever = $customerGroupRetriever
?? \Magento\Framework\App\ObjectManager::getInstance()->get(CustomerGroupRetrieverInterface::class);
if ($saleableItem->hasCustomerGroupId()) {
$this->customerGroup = (int) $saleableItem->getCustomerGroupId();
} else {
$this->customerGroup = (int) $this->customerSession->getCustomerGroupId();
$this->customerGroup = (int) $this->customerGroupRetriever->getCustomerGroupId();
}
}

Expand Down
34 changes: 21 additions & 13 deletions app/code/Magento/Catalog/Test/Unit/Pricing/Price/TierPriceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,52 @@ class TierPriceTest extends \PHPUnit\Framework\TestCase
*
* @var int
*/
protected $customerGroup = Group::NOT_LOGGED_IN_ID;
private $customerGroup = Group::NOT_LOGGED_IN_ID;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $priceInfo;
private $priceInfo;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $product;
private $product;

/**
* @var float
*/
protected $quantity = 3.;
private $quantity = 3.;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $calculator;
private $calculator;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $session;
private $session;

/**
* @var TierPrice
*/
protected $model;
private $model;

/**
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $priceCurrencyMock;
private $priceCurrencyMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $groupManagement;
private $groupManagement;

/**
* @var \Magento\Customer\Model\Group\RetrieverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $customerGroupRetriever;

/**
* Initialize base dependencies
Expand All @@ -76,11 +81,12 @@ protected function setUp()

$this->product = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['getPriceInfo', 'hasCustomerGroupId', 'getCustomerGroupId', 'getResource', '__wakeup']);
$this->product->expects($this->any())->method('getPriceInfo')->will($this->returnValue($this->priceInfo));

$this->customerGroupRetriever = $this->getMockBuilder(\Magento\Customer\Model\Group\RetrieverInterface::class)
->disableOriginalConstructor()->getMock();
$this->session = $this->createMock(\Magento\Customer\Model\Session::class);
$this->session->expects($this->any())->method('getCustomerGroupId')
->will($this->returnValue($this->customerGroup));

$this->customerGroupRetriever = $this->createMock(\Magento\Customer\Model\Group\RetrieverInterface::class);
$this->calculator = $this->createMock(\Magento\Framework\Pricing\Adjustment\Calculator::class);
$this->groupManagement = $this->createMock(\Magento\Customer\Api\GroupManagementInterface::class);

Expand All @@ -92,7 +98,8 @@ protected function setUp()
$this->calculator,
$this->priceCurrencyMock,
$this->session,
$this->groupManagement
$this->groupManagement,
$this->customerGroupRetriever
);
}

Expand Down Expand Up @@ -218,7 +225,8 @@ public function testGetterStoredTierPrices()
$this->calculator,
$this->priceCurrencyMock,
$this->session,
$this->groupManagement
$this->groupManagement,
$this->customerGroupRetriever
);
$group = $this->createMock(\Magento\Customer\Model\Data\Group::class);
$group->expects($this->once())->method('getId')->willReturn(GroupManagement::CUST_GROUP_ALL);
Expand Down
Loading

0 comments on commit 58694a6

Please sign in to comment.