Skip to content

Commit bd45f47

Browse files
author
He, Joan(johe)
committed
Merge pull request magento#25 from magento-nord/develop
[Nord] BugFix
2 parents 63756ee + c78a8fd commit bd45f47

File tree

4 files changed

+211
-23
lines changed

4 files changed

+211
-23
lines changed

app/code/Magento/BundleSampleData/Model/Product.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
namespace Magento\BundleSampleData\Model;
77

88
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
9+
use Magento\Bundle\Api\Data\OptionInterfaceFactory as OptionFactory;
10+
use Magento\Bundle\Api\Data\LinkInterfaceFactory as LinkFactory;
11+
use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepository;
12+
use \Magento\Framework\App\ObjectManager;
913

1014
/**
1115
* Setup bundle product
@@ -17,6 +21,11 @@ class Product extends \Magento\CatalogSampleData\Model\Product
1721
*/
1822
protected $productType = \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE;
1923

24+
/**
25+
* @var OptionFactory
26+
*/
27+
private $optionFactory;
28+
2029
/**
2130
* Product constructor.
2231
* @param SampleDataContext $sampleDataContext
@@ -48,6 +57,16 @@ public function __construct(
4857
);
4958
}
5059

60+
/**
61+
* @var LinkFactory
62+
*/
63+
private $linkFactory;
64+
65+
/**
66+
* @var ProductRepository
67+
*/
68+
private $productRepository;
69+
5170
/**
5271
* @inheritdoc
5372
*/
@@ -57,7 +76,82 @@ protected function prepareProduct($product, $data)
5776
->setCanSaveConfigurableAttributes(true)
5877
->setCanSaveBundleSelections(true)
5978
->setPriceType(0);
79+
$bundleOptionsData = $product->getBundleOptionsData();
80+
$options = [];
81+
foreach ($bundleOptionsData as $key => $optionData) {
82+
$option = $this->getOptionFactory()->create(['data' => $optionData]);
83+
$option->setSku($product->getSku());
84+
$option->setOptionId(null);
85+
86+
$links = [];
87+
$bundleLinks = $product->getBundleSelectionsData();
88+
foreach ($bundleLinks[$key] as $linkData) {
89+
$linkProduct = $this->getProductRepository()->getById($linkData['product_id']);
90+
$link = $this->getLinkFactory()->create(['data' => $linkData]);
91+
$link->setSku($linkProduct->getSku());
92+
$link->setQty($linkData['selection_qty']);
93+
94+
if (array_key_exists('selection_can_change_qty', $linkData)) {
95+
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
96+
}
97+
$links[] = $link;
98+
}
99+
$option->setProductLinks($links);
100+
$options[] = $option;
101+
}
102+
103+
$extension = $product->getExtensionAttributes();
104+
$extension->setBundleProductOptions($options);
105+
$product->setExtensionAttributes($extension);
60106

61107
return $this;
62108
}
109+
110+
/**
111+
* Get option interface factory
112+
*
113+
* @deprecated
114+
* @return \Magento\Bundle\Api\Data\OptionInterfaceFactory
115+
*/
116+
private function getOptionFactory()
117+
{
118+
if (!$this->optionFactory) {
119+
$this->optionFactory = ObjectManager::getInstance()->get(
120+
'\Magento\Bundle\Api\Data\OptionInterfaceFactory'
121+
);
122+
}
123+
return $this->optionFactory;
124+
}
125+
126+
/**
127+
* Get bundle link interface factory
128+
*
129+
* @deprecated
130+
* @return \Magento\Bundle\Api\Data\LinkInterfaceFactory
131+
*/
132+
private function getLinkFactory()
133+
{
134+
if (!$this->linkFactory) {
135+
$this->linkFactory = ObjectManager::getInstance()->get(
136+
'\Magento\Bundle\Api\Data\LinkInterfaceFactory'
137+
);
138+
}
139+
return $this->linkFactory;
140+
}
141+
142+
/**
143+
* Get product repository
144+
*
145+
* @deprecated
146+
* @return \Magento\Catalog\Api\ProductRepositoryInterface
147+
*/
148+
private function getProductRepository()
149+
{
150+
if (!$this->productRepository) {
151+
$this->productRepository = ObjectManager::getInstance()->get(
152+
'\Magento\Catalog\Api\ProductRepositoryInterface'
153+
);
154+
}
155+
return $this->productRepository;
156+
}
63157
}

app/code/Magento/CatalogSampleData/Model/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ protected function installGallery($product)
166166
}
167167

168168
/**
169-
* @param \Magento\Framework\Model\AbstractModel $product
169+
* @param \Magento\Catalog\Model\Product $product
170170
* @param array $data
171171
* @return $this
172172
* @SuppressWarnings(PHPMD.UnusedFormalParameter)

app/code/Magento/DownloadableSampleData/Model/Product.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
namespace Magento\DownloadableSampleData\Model;
77

88
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
9+
use Magento\Downloadable\Api\Data\SampleInterfaceFactory as SampleFactory;
10+
use Magento\Downloadable\Api\Data\LinkInterfaceFactory as LinkFactory;
11+
use \Magento\Framework\App\ObjectManager;
912

1013
/**
1114
* Setup downloadable product
@@ -27,6 +30,16 @@ class Product extends \Magento\CatalogSampleData\Model\Product
2730
*/
2831
protected $downloadableData = [];
2932

33+
/**
34+
* @var SampleFactory
35+
*/
36+
protected $sampleFactory;
37+
38+
/**
39+
* @var LinkFactory
40+
*/
41+
protected $linkFactory;
42+
3043
/**
3144
* Product constructor.
3245
* @param SampleDataContext $sampleDataContext
@@ -96,9 +109,105 @@ public function install(array $productFixtures, array $galleryFixtures, array $d
96109
protected function prepareProduct($product, $data)
97110
{
98111
if (isset($this->downloadableData[$data['sku']])) {
112+
$extension = $product->getExtensionAttributes();
113+
$links = [];
114+
foreach ($this->downloadableData[$data['sku']]['link'] as $linkData) {
115+
$link = $this->getLinkFactory()->create(['data' => $linkData]);
116+
if (isset($linkData['type'])) {
117+
$link->setLinkType($linkData['type']);
118+
}
119+
if (isset($linkData['file'])) {
120+
$link->setFile($linkData['file']);
121+
}
122+
if (isset($linkData['file_content'])) {
123+
$link->setLinkFileContent($linkData['file_content']);
124+
}
125+
$link->setId(null);
126+
if (isset($linkData['sample']['type'])) {
127+
$link->setSampleType($linkData['sample']['type']);
128+
}
129+
if (isset($linkData['sample']['file'])) {
130+
$link->setSampleFileData($linkData['sample']['file']);
131+
}
132+
if (isset($linkData['sample']['url'])) {
133+
$link->setSampleUrl($linkData['sample']['url']);
134+
}
135+
if (isset($linkData['sample']['file_content'])) {
136+
$link->setSampleFileContent($linkData['file_content']);
137+
}
138+
$link->setStoreId($product->getStoreId());
139+
$link->setWebsiteId($product->getStore()->getWebsiteId());
140+
$link->setProductWebsiteIds($product->getWebsiteIds());
141+
if (!$link->getSortOrder()) {
142+
$link->setSortOrder(1);
143+
}
144+
if (null === $link->getPrice()) {
145+
$link->setPrice(0);
146+
}
147+
if ($link->getIsUnlimited()) {
148+
$link->setNumberOfDownloads(0);
149+
}
150+
$links[] = $link;
151+
}
152+
$extension->setDownloadableProductLinks($links);
153+
154+
$samples = [];
155+
foreach ($this->downloadableData[$data['sku']]['sample'] as $sampleData) {
156+
$sample = $this->getSampleFactory()->create(['data' => $sampleData]);
157+
$sample->setId(null);
158+
$sample->setStoreId($product->getStoreId());
159+
if (isset($sampleData['type'])) {
160+
$sample->setSampleType($sampleData['type']);
161+
}
162+
if (isset($sampleData['file'])) {
163+
$sample->setFile($sampleData['file']);
164+
}
165+
if (isset($sampleData['sample_url'])) {
166+
$sample->setSampleUrl($sampleData['sample_url']);
167+
}
168+
if (!$sample->getSortOrder()) {
169+
$sample->setSortOrder(1);
170+
}
171+
$samples[] = $sample;
172+
}
173+
$extension->setDownloadableProductSamples($samples);
174+
99175
$product->setDownloadableData($this->downloadableData[$data['sku']]);
176+
$product->setExtensionAttributes($extension);
100177
}
101178
$this->setVirtualStockData($product);
102179
return $this;
103180
}
181+
182+
/**
183+
* Get link interface factory
184+
*
185+
* @deprecated
186+
* @return \Magento\Downloadable\Api\Data\LinkInterfaceFactory
187+
*/
188+
private function getLinkFactory()
189+
{
190+
if (!$this->linkFactory) {
191+
$this->linkFactory = ObjectManager::getInstance()->get(
192+
'\Magento\Downloadable\Api\Data\LinkInterfaceFactory'
193+
);
194+
}
195+
return $this->linkFactory;
196+
}
197+
198+
/**
199+
* Get sample interface factory
200+
*
201+
* @deprecated
202+
* @return \Magento\Downloadable\Api\Data\SampleInterfaceFactory
203+
*/
204+
private function getSampleFactory()
205+
{
206+
if (!$this->sampleFactory) {
207+
$this->sampleFactory = ObjectManager::getInstance()->get(
208+
'\Magento\Downloadable\Api\Data\SampleInterfaceFactory'
209+
);
210+
}
211+
return $this->sampleFactory;
212+
}
104213
}

app/code/Magento/SalesSampleData/Model/Order/Processor.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,13 @@ public function createOrder($orderData)
131131
$this->setPhraseRenderer();
132132
if (!empty($orderData)) {
133133
$orderCreateModel = $this->processQuote($orderData);
134-
if (!empty($orderData['payment'])) {
135-
$orderCreateModel->setPaymentData($orderData['payment']);
136-
$orderCreateModel->getQuote()->getPayment()->addData($orderData['payment']);
137-
}
138134
$customer = $this->customerRepository->get(
139135
$orderData['order']['account']['email'],
140136
$this->storeManager->getWebsite()->getId()
141137
);
142138
$orderCreateModel->getQuote()->setCustomer($customer);
143139
$orderCreateModel->getSession()->setCustomerId($customer->getId());
144-
$order = $orderCreateModel
145-
->importPostData($orderData['order'])
146-
->createOrder();
140+
$order = $orderCreateModel->createOrder();
147141
$orderItem = $this->getOrderItemForTransaction($order);
148142
$this->invoiceOrder($orderItem);
149143
$this->shipOrder($orderItem);
@@ -174,23 +168,14 @@ protected function processQuote($data = [])
174168
$orderCreateModel = $this->createOrderFactory->create(
175169
['quoteSession' => $this->currentSession]
176170
);
177-
if (!empty($data['order'])) {
178-
$orderCreateModel->importPostData($data['order']);
179-
}
180-
$orderCreateModel->getQuote()->setReservedOrderId(null);
171+
$orderCreateModel->importPostData($data['order'])->initRuleData();
181172
$orderCreateModel->getBillingAddress();
182-
$orderCreateModel->setShippingAsBilling(true);
183-
if (!empty($data['add_products'])) {
184-
$orderCreateModel->addProducts($data['add_products']);
185-
}
173+
$orderCreateModel->setShippingAsBilling(1);
174+
$orderCreateModel->addProducts($data['add_products']);
175+
$orderCreateModel->getQuote()->getShippingAddress()->unsetData('cached_items_all');
176+
$orderCreateModel->getQuote()->setTotalsCollectedFlag(false);
186177
$orderCreateModel->collectShippingRates();
187-
if (!empty($data['payment'])) {
188-
/** @var \Magento\Quote\Model\Quote\Payment $payment */
189-
$payment = $orderCreateModel->getQuote()->getPayment();
190-
$payment->addData($data['payment']);
191-
$payment->setQuote($orderCreateModel->getQuote());
192-
}
193-
$orderCreateModel->initRuleData();
178+
$orderCreateModel->getQuote()->getPayment()->addData($data['payment'])->setQuote($orderCreateModel->getQuote());
194179
return $orderCreateModel;
195180
}
196181

0 commit comments

Comments
 (0)