Skip to content

Commit f7a492c

Browse files
author
Natalia Momotenko
committed
Merge remote-tracking branch 'origin/develop' into PR
2 parents 027a7ea + 3e84547 commit f7a492c

File tree

44 files changed

+3039
-113
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3039
-113
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Api\Data;
8+
9+
/**
10+
* Interface BundleOptionInterface
11+
* @api
12+
*/
13+
interface BundleOptionInterface extends \Magento\Framework\Api\ExtensibleDataInterface
14+
{
15+
/**
16+
* Get bundle option id.
17+
*
18+
* @return int
19+
*/
20+
public function getOptionId();
21+
22+
/**
23+
* Set bundle option id.
24+
*
25+
* @param int $optionId
26+
* @return int
27+
*/
28+
public function setOptionId($optionId);
29+
30+
/**
31+
* Get bundle option quantity.
32+
*
33+
* @return int
34+
*/
35+
public function getOptionQty();
36+
37+
/**
38+
* Set bundle option quantity.
39+
*
40+
* @param int $optionQty
41+
* @return int
42+
*/
43+
public function setOptionQty($optionQty);
44+
45+
/**
46+
* Get bundle option selection ids.
47+
*
48+
* @return int[]
49+
*/
50+
public function getOptionSelections();
51+
52+
/**
53+
* Set bundle option selection ids.
54+
*
55+
* @param int[] $optionSelections
56+
* @return int[]
57+
*/
58+
public function setOptionSelections(array $optionSelections);
59+
60+
/**
61+
* Retrieve existing extension attributes object or create a new one.
62+
*
63+
* @return \Magento\Bundle\Api\Data\BundleOptionExtensionInterface|null
64+
*/
65+
public function getExtensionAttributes();
66+
67+
/**
68+
* Set an extension attributes object.
69+
*
70+
* @param \Magento\Bundle\Api\Data\BundleOptionExtensionInterface $extensionAttributes
71+
* @return $this
72+
*/
73+
public function setExtensionAttributes(
74+
\Magento\Bundle\Api\Data\BundleOptionExtensionInterface $extensionAttributes
75+
);
76+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Model;
7+
8+
use Magento\Framework\Model\AbstractExtensibleModel;
9+
use Magento\Bundle\Api\Data\BundleOptionInterface;
10+
11+
class BundleOption extends AbstractExtensibleModel implements BundleOptionInterface
12+
{
13+
/**#@+
14+
* Constants
15+
*/
16+
const OPTION_ID = 'option_id';
17+
const OPTION_QTY = 'option_qty';
18+
const OPTION_SELECTIONS = 'option_selections';
19+
/**#@-*/
20+
21+
/**
22+
* {@inheritdoc}
23+
* @codeCoverageIgnore
24+
*/
25+
public function getOptionId()
26+
{
27+
return $this->getData(self::OPTION_ID);
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
* @codeCoverageIgnore
33+
*/
34+
public function getOptionQty()
35+
{
36+
return $this->getData(self::OPTION_QTY);
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
* @codeCoverageIgnore
42+
*/
43+
public function getOptionSelections()
44+
{
45+
return $this->getData(self::OPTION_SELECTIONS);
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
* @codeCoverageIgnore
51+
*/
52+
public function setOptionId($optionId)
53+
{
54+
return $this->setData(self::OPTION_ID, $optionId);
55+
}
56+
57+
/**
58+
* {@inheritdoc}
59+
* @codeCoverageIgnore
60+
*/
61+
public function setOptionQty($optionQty)
62+
{
63+
return $this->setData(self::OPTION_QTY, $optionQty);
64+
}
65+
66+
/**
67+
* {@inheritdoc}
68+
* @codeCoverageIgnore
69+
*/
70+
public function setOptionSelections(array $optionSelections)
71+
{
72+
return $this->setData(self::OPTION_SELECTIONS, $optionSelections);
73+
}
74+
75+
/**
76+
* {@inheritdoc}
77+
* @codeCoverageIgnore
78+
*/
79+
public function getExtensionAttributes()
80+
{
81+
return $this->_getExtensionAttributes();
82+
}
83+
84+
/**
85+
* {@inheritdoc}
86+
* @codeCoverageIgnore
87+
*/
88+
public function setExtensionAttributes(\Magento\Bundle\Api\Data\BundleOptionExtensionInterface $extensionAttributes)
89+
{
90+
return $this->_setExtensionAttributes($extensionAttributes);
91+
}
92+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Model;
7+
8+
use Magento\Quote\Model\Quote\Item\CartItemProcessorInterface;
9+
use Magento\Quote\Api\Data\CartItemInterface;
10+
use Magento\Bundle\Api\Data\BundleOptionInterfaceFactory;
11+
use Magento\Quote\Api\Data as QuoteApi;
12+
13+
class CartItemProcessor implements CartItemProcessorInterface
14+
{
15+
/**
16+
* @var \Magento\Framework\DataObject\Factory
17+
*/
18+
protected $objectFactory;
19+
20+
/**
21+
* @var QuoteApi\ProductOptionExtensionFactory
22+
*/
23+
protected $productOptionExtensionFactory;
24+
25+
/**
26+
* @var BundleOptionInterfaceFactory
27+
*/
28+
protected $bundleOptionFactory;
29+
30+
/**
31+
* @var QuoteApi\ProductOptionInterfaceFactory
32+
*/
33+
protected $productOptionFactory;
34+
35+
/**
36+
* @param \Magento\Framework\DataObject\Factory $objectFactory
37+
* @param QuoteApi\ProductOptionExtensionFactory $productOptionExtensionFactory
38+
* @param BundleOptionInterfaceFactory $bundleOptionFactory
39+
* @param QuoteApi\ProductOptionInterfaceFactory $productOptionFactory
40+
*/
41+
public function __construct(
42+
\Magento\Framework\DataObject\Factory $objectFactory,
43+
QuoteApi\ProductOptionExtensionFactory $productOptionExtensionFactory,
44+
BundleOptionInterfaceFactory $bundleOptionFactory,
45+
QuoteApi\ProductOptionInterfaceFactory $productOptionFactory
46+
) {
47+
$this->objectFactory = $objectFactory;
48+
$this->productOptionExtensionFactory = $productOptionExtensionFactory;
49+
$this->bundleOptionFactory = $bundleOptionFactory;
50+
$this->productOptionFactory = $productOptionFactory;
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public function convertToBuyRequest(CartItemInterface $cartItem)
57+
{
58+
if ($cartItem->getProductOption() && $cartItem->getProductOption()->getExtensionAttributes()) {
59+
$options = $cartItem->getProductOption()->getExtensionAttributes()->getBundleOptions();
60+
if (is_array($options)) {
61+
$requestData = [];
62+
foreach ($options as $option) {
63+
/** @var \Magento\Bundle\Api\Data\BundleOptionInterface $option */
64+
foreach ($option->getOptionSelections() as $selection) {
65+
$requestData['bundle_option'][$option->getOptionId()][] = $selection;
66+
$requestData['bundle_option_qty'][$option->getOptionId()] = $option->getOptionQty();
67+
}
68+
}
69+
return $this->objectFactory->create($requestData);
70+
}
71+
}
72+
return null;
73+
}
74+
75+
/**
76+
* {@inheritdoc}
77+
* @SuppressWarnings(PHPMD.NPathComplexity)
78+
*/
79+
public function processProductOptions(CartItemInterface $cartItem)
80+
{
81+
if ($cartItem->getProductType() !== \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) {
82+
return $cartItem;
83+
}
84+
$productOptions = [];
85+
$bundleOptions = $cartItem->getBuyRequest()->getBundleOption();
86+
$bundleOptionsQty = $cartItem->getBuyRequest()->getBundleOptionQty();
87+
foreach ($bundleOptions as $optionId => $optionSelections) {
88+
if (empty($optionSelections)) {
89+
continue;
90+
}
91+
$optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections];
92+
$optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1;
93+
94+
/** @var \Magento\Bundle\Api\Data\BundleOptionInterface $productOption */
95+
$productOption = $this->bundleOptionFactory->create();
96+
$productOption->setOptionId($optionId);
97+
$productOption->setOptionSelections($optionSelections);
98+
$productOption->setOptionQty($optionQty);
99+
$productOptions[] = $productOption;
100+
}
101+
102+
$extension = $this->productOptionExtensionFactory->create()->setBundleOptions($productOptions);
103+
if (!$cartItem->getProductOption()) {
104+
$cartItem->setProductOption($this->productOptionFactory->create());
105+
}
106+
$cartItem->getProductOption()->setExtensionAttributes($extension);
107+
return $cartItem;
108+
}
109+
}

0 commit comments

Comments
 (0)