Skip to content

Commit

Permalink
Merge pull request #683 from magento-firedrakes/MAGETWO-41948
Browse files Browse the repository at this point in the history
[Firedrakes][South][Tango][FearlessKiwis] MAGETWO-41984 MAGETWO-41944 Convert Quoteitem to order item with product options
  • Loading branch information
dkvashninbay committed Oct 7, 2015
2 parents 86d5abe + c7f915c commit 2e2785c
Show file tree
Hide file tree
Showing 141 changed files with 4,919 additions and 299 deletions.
2 changes: 0 additions & 2 deletions app/code/Magento/Backend/App/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ protected function _processLocaleSettings()
/**
* Set redirect into response
*
* @deprecated
* @TODO MAGETWO-28356: Refactor controller actions to new ResultInterface
* @param string $path
* @param array $arguments
Expand All @@ -316,7 +315,6 @@ protected function _redirect($path, $arguments = [])
/**
* Forward to action
*
* @deprecated
* @TODO MAGETWO-28356: Refactor controller actions to new ResultInterface
* @param string $action
* @param string|null $controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* @method \Magento\Quote\Model\Quote setHideFormElement(boolean $value) Hide Form element to prevent IE errors
* @method boolean getHideFormElement()
* @author Magento Core Team <core@magentocommerce.com>
* @deprecated support Magento 1.x grid massaction implementation
* @TODO MAGETWO-31510: Remove deprecated class
*/
class Extended extends \Magento\Backend\Block\Widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

// @codingStandardsIgnoreFile

/**
* @deprecated support Magento 1.x grid massaction implementation
*/
?>
<div id="<?php echo $block->getHtmlId() ?>" class="admin__grid-massaction">

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Bundle/Model/CartItemProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
* {@inheritdoc}
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function processProductOptions(CartItemInterface $cartItem)
public function processOptions(CartItemInterface $cartItem)
{
if ($cartItem->getProductType() !== \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
return $cartItem;
Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public function getIsPricesCalculatedByIndex()
*
* @param \Magento\Catalog\Model\Product $product
* @return float
*
* @deprecated (MAGETWO-31476)
*/
public function getPrice($product)
{
Expand Down Expand Up @@ -375,7 +373,6 @@ public function getOptions($product)
* @param null|bool $multiplyQty Whether to multiply selection's price by its quantity
* @return float
*
* @deprecated after 1.6.2.0 (MAGETWO-31475)
* @see \Magento\Bundle\Model\Product\Price::getSelectionFinalTotalPrice()
*/
public function getSelectionPrice($bundleProduct, $selectionProduct, $selectionQty = null, $multiplyQty = true)
Expand Down
112 changes: 112 additions & 0 deletions app/code/Magento/Bundle/Model/ProductOptionProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Model;

use Magento\Bundle\Api\Data\BundleOptionInterface;
use Magento\Bundle\Api\Data\BundleOptionInterfaceFactory;
use Magento\Catalog\Api\Data\ProductOptionInterface;
use Magento\Catalog\Model\Product\Type as ProductType;
use Magento\Catalog\Model\ProductOptionProcessorInterface;
use Magento\Framework\DataObject;
use Magento\Framework\DataObject\Factory as DataObjectFactory;

class ProductOptionProcessor implements ProductOptionProcessorInterface
{
/**
* @var DataObjectFactory
*/
protected $objectFactory;

/**
* @var BundleOptionInterfaceFactory
*/
protected $bundleOptionFactory;

/**
* @param DataObjectFactory $objectFactory
* @param BundleOptionInterfaceFactory $bundleOptionFactory
*/
public function __construct(
DataObjectFactory $objectFactory,
BundleOptionInterfaceFactory $bundleOptionFactory
) {
$this->objectFactory = $objectFactory;
$this->bundleOptionFactory = $bundleOptionFactory;
}

/**
* {@inheritdoc}
*/
public function convertToBuyRequest(ProductOptionInterface $productOption)
{
/** @var DataObject $request */
$request = $this->objectFactory->create();

$bundleOptions = $this->getBundleOptions($productOption);
if (!empty($bundleOptions) && is_array($bundleOptions)) {
$requestData = [];
foreach ($bundleOptions as $option) {
/** @var BundleOptionInterface $option */
foreach ($option->getOptionSelections() as $selection) {
$requestData['bundle_option'][$option->getOptionId()][] = $selection;
$requestData['bundle_option_qty'][$option->getOptionId()] = $option->getOptionQty();
}
}
$request->addData($requestData);
}

return $request;
}

/**
* Retrieve bundle options
*
* @param ProductOptionInterface $productOption
* @return array
*/
protected function getBundleOptions(ProductOptionInterface $productOption)
{
if ($productOption
&& $productOption->getExtensionAttributes()
&& $productOption->getExtensionAttributes()->getBundleOptions()
) {
return $productOption->getExtensionAttributes()
->getBundleOptions();
}
return [];
}

/**
* {@inheritdoc}
*/
public function convertToProductOption(DataObject $request)
{
$bundleOptions = $request->getBundleOption();
$bundleOptionsQty = $request->getBundleOptionQty();

if (!empty($bundleOptions) && is_array($bundleOptions)) {
$data = [];
foreach ($bundleOptions as $optionId => $optionSelections) {
if (empty($optionSelections)) {
continue;
}
$optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections];
$optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1;

/** @var BundleOptionInterface $productOption */
$productOption = $this->bundleOptionFactory->create();
$productOption->setOptionId($optionId);
$productOption->setOptionSelections($optionSelections);
$productOption->setOptionQty($optionQty);
$data[] = $productOption;
}

return ['bundle_options' => $data];
}

return [];
}
}
20 changes: 16 additions & 4 deletions app/code/Magento/Bundle/Pricing/Render/FinalPriceBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,33 @@

use Magento\Bundle\Pricing\Price;
use Magento\Catalog\Pricing\Render as CatalogRender;
use Magento\Catalog\Pricing\Price\CustomOptionPrice;

/**
* Class for final_price rendering
*/
class FinalPriceBox extends CatalogRender\FinalPriceBox
{
/**
* Check if bundle product has one more custom option with different prices
* Check if bundle product has one or more options, or custom options, with different prices
*
* @return bool
*/
public function showRangePrice()
{
/** @var Price\BundleOptionPrice $optionPrice */
$optionPrice = $this->getPriceType(Price\BundleOptionPrice::PRICE_CODE);
return $optionPrice->getValue() !== $optionPrice->getMaxValue();
//Check the bundle options
/** @var Price\BundleOptionPrice $bundleOptionPrice */
$bundleOptionPrice = $this->getPriceType(Price\BundleOptionPrice::PRICE_CODE);
$showRange = $bundleOptionPrice->getValue() != $bundleOptionPrice->getMaxValue();

if (!$showRange) {
//Check the custom options, if any
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->getPriceType(CustomOptionPrice::PRICE_CODE);
$showRange =
$customOptionPrice->getCustomOptionRange(true) != $customOptionPrice->getCustomOptionRange(false);
}

return $showRange;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ public function testProcessProductOptions()
$cartItemMock->expects($this->atLeastOnce())->method('getProductOption')->willReturn($productOptionMock);
$productOptionMock->expects($this->once())->method('setExtensionAttributes')->with($optionExtensionMock);

$this->assertSame($cartItemMock, $this->model->processProductOptions($cartItemMock));
$this->assertSame($cartItemMock, $this->model->processOptions($cartItemMock));
}

public function testProcessProductOptionsInvalidType()
{
$cartItemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', ['getProductType'], [], '', false);
$cartItemMock->expects($this->once())->method('getProductType')->willReturn(Type::TYPE_SIMPLE);
$this->assertSame($cartItemMock, $this->model->processProductOptions($cartItemMock));
$this->assertSame($cartItemMock, $this->model->processOptions($cartItemMock));
}
}
Loading

0 comments on commit 2e2785c

Please sign in to comment.