Skip to content

Commit 3b536b7

Browse files
author
Yaroslav Onischenko
committed
MAGETWO-52973: Sample data throws exception on installation
1 parent 1b714e4 commit 3b536b7

File tree

7 files changed

+77
-19
lines changed

7 files changed

+77
-19
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ public function install(array $fixtures)
149149
$attributeSet = $this->processAttributeSet($setName);
150150
$attributeGroupId = $attributeSet->getDefaultGroupId();
151151

152-
$attribute = $this->attributeFactory->create();
152+
$attribute = $this->attributeFactory->create()->load($attributeId);
153153
$attribute
154-
->setId($attributeId)
155154
->setAttributeGroupId($attributeGroupId)
156155
->setAttributeSetId($attributeSet->getId())
157156
->setEntityTypeId($this->getEntityTypeId())

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public function setFixtures(array $fixtures)
118118
*/
119119
protected function storeImage($product, $images)
120120
{
121+
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
122+
$productId = $product->getData($linkField);
121123
$baseImage = '';
122124
$i = 1;
123125
$mediaAttribute = $this->eavConfig->getAttribute('catalog_product', 'media_gallery');
@@ -129,21 +131,20 @@ protected function storeImage($product, $images)
129131
if (strpos($image, '_main') !== false) {
130132
$baseImage = $image;
131133
}
132-
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
134+
133135
$id = $this->galleryResource->insertGallery([
134136
'attribute_id' => $mediaAttribute->getAttributeId(),
135-
$linkField => $product->getId(),
136137
'value' => $image,
137138
]);
138139
$this->galleryResource->insertGalleryValueInStore([
139140
'value_id' => $id,
140141
'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
141-
$linkField => $product->getId(),
142+
$linkField => $productId,
142143
'label' => 'Image',
143144
'position' => $i,
144145
'disables' => 0,
145146
]);
146-
$this->galleryResource->bindValueToEntity($id, $product->getId());
147+
$this->galleryResource->bindValueToEntity($id, $productId);
147148
$i++;
148149
}
149150

@@ -160,7 +161,7 @@ protected function storeImage($product, $images)
160161
$table = $imageAttribute->getBackend()->getTable();
161162
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter*/
162163
$data = [
163-
$attribute->getEntity()->getLinkField() => $product->getId(),
164+
$attribute->getEntity()->getLinkField() => $productId,
164165
'attribute_id' => $attribute->getId(),
165166
'value' => $baseImage,
166167
];

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,25 @@
55
*/
66
namespace Magento\DownloadableSampleData\Model\Product;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Filesystem;
11+
812
/**
913
* Class Converter
1014
*/
1115
class Converter extends \Magento\CatalogSampleData\Model\Product\Converter
1216
{
17+
/**
18+
* @var \Magento\Downloadable\Api\Data\File\ContentInterfaceFactory
19+
*/
20+
private $fileContentFactory;
21+
22+
/**
23+
* @var \Magento\Framework\Filesystem
24+
*/
25+
private $filesystem;
26+
1327
/**
1428
* Get downloadable data from array
1529
*
@@ -84,7 +98,11 @@ public function formatDownloadableLinkData($linkData)
8498
foreach ($linkItems as $csvRow) {
8599
$linkData[$csvRow] = isset($linkData[$csvRow]) ? $linkData[$csvRow] : '';
86100
}
87-
101+
$directory = $this->getFilesystem()->getDirectoryRead(DirectoryList::MEDIA);
102+
$linkPath = $directory->getAbsolutePath('downloadable/files/links' . $linkData['link_item_file']);
103+
$data = base64_encode(file_get_contents($linkPath));
104+
$content = $this->getFileContent()->setFileData($data)
105+
->setName('luma_background_-_model_against_fence_4_sec_.mp4');
88106
$link = [
89107
'is_delete' => '',
90108
'link_id' => '0',
@@ -95,6 +113,7 @@ public function formatDownloadableLinkData($linkData)
95113
'type' => 'file',
96114
'file' => json_encode([['file' => $linkData['link_item_file'], 'status' => 'old']]),
97115
'sort_order' => '',
116+
'link_file_content' => $content
98117
];
99118

100119
return $link;
@@ -106,6 +125,13 @@ public function formatDownloadableLinkData($linkData)
106125
*/
107126
public function getSamplesInfo()
108127
{
128+
$directory = $this->getFilesystem()->getDirectoryRead(DirectoryList::MEDIA);
129+
$linkPath = $directory->getAbsolutePath(
130+
'downloadable/files/samples/l/u/luma_background_-_model_against_fence_4_sec_.mp4'
131+
);
132+
$data = base64_encode(file_get_contents($linkPath));
133+
$content = $this->getFileContent()->setFileData($data)
134+
->setName('luma_background_-_model_against_fence_4_sec_.mp4');
109135
$sample = [
110136
'is_delete' => '',
111137
'sample_id' => '0',
@@ -115,6 +141,7 @@ public function getSamplesInfo()
115141
]]),
116142
'type' => 'file',
117143
'sort_order' => '',
144+
'sample_file_content' => $content
118145
];
119146

120147
$samples = [];
@@ -125,4 +152,32 @@ public function getSamplesInfo()
125152

126153
return $samples;
127154
}
155+
156+
/**
157+
* @return \Magento\Downloadable\Api\Data\File\ContentInterface
158+
* @deprecated
159+
*/
160+
private function getFileContent()
161+
{
162+
if (!$this->fileContentFactory) {
163+
$this->fileContentFactory = ObjectManager::getInstance()->create(
164+
\Magento\Downloadable\Api\Data\File\ContentInterfaceFactory::class
165+
);
166+
}
167+
return $this->fileContentFactory->create();
168+
}
169+
170+
/**
171+
* @return Filesystem
172+
* @deprecated
173+
*/
174+
private function getFilesystem()
175+
{
176+
if (!$this->filesystem) {
177+
$this->filesystem = ObjectManager::getInstance()->create(
178+
Filesystem::class
179+
);
180+
}
181+
return $this->filesystem;
182+
}
128183
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ public function createOrder($orderData)
130130
{
131131
$this->setPhraseRenderer();
132132
if (!empty($orderData)) {
133-
$orderCreateModel = $this->processQuote($orderData);
133+
$this->currentSession = $this->sessionQuoteFactory->create();
134134
$customer = $this->customerRepository->get(
135135
$orderData['order']['account']['email'],
136136
$this->storeManager->getWebsite()->getId()
137137
);
138+
$this->currentSession->setCustomerId($customer->getId());
139+
$orderCreateModel = $this->processQuote($orderData);
138140
$orderCreateModel->getQuote()->setCustomer($customer);
139-
$orderCreateModel->getSession()->setCustomerId($customer->getId());
141+
140142
$order = $orderCreateModel->createOrder();
141143
$orderItem = $this->getOrderItemForTransaction($order);
142144
$this->invoiceOrder($orderItem);
@@ -163,7 +165,6 @@ public function createOrder($orderData)
163165
*/
164166
protected function processQuote($data = [])
165167
{
166-
$this->currentSession = $this->sessionQuoteFactory->create();
167168
/** @var \Magento\Sales\Model\AdminOrder\Create $orderCreateModel */
168169
$orderCreateModel = $this->createOrderFactory->create(
169170
['quoteSession' => $this->currentSession]
@@ -173,6 +174,7 @@ protected function processQuote($data = [])
173174
$orderCreateModel->setShippingAsBilling(1);
174175
$orderCreateModel->addProducts($data['add_products']);
175176
$orderCreateModel->getQuote()->getShippingAddress()->unsetData('cached_items_all');
177+
$orderCreateModel->getQuote()->getShippingAddress()->setShippingMethod($data['order']['shipping_method']);
176178
$orderCreateModel->getQuote()->setTotalsCollectedFlag(false);
177179
$orderCreateModel->collectShippingRates();
178180
$orderCreateModel->getQuote()->getPayment()->addData($data['payment'])->setQuote($orderCreateModel->getQuote());

dev/tests/functional/tests/app/Magento/CustomerSampleData/Test/TestCase/LoginCustomerTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<data name="customer/data/firstname" xsi:type="string">Veronica</data>
1313
<data name="customer/data/lastname" xsi:type="string">Costello</data>
1414
<data name="customer/data/email" xsi:type="string">[email protected]</data>
15-
<data name="customer/data/password" xsi:type="string">roni_cost@example.com</data>
15+
<data name="customer/data/password" xsi:type="string">roni_cost3@example.com</data>
1616
</variation>
1717
</testCase>
1818
</config>

dev/tests/functional/tests/app/Magento/SalesSampleData/Test/TestCase/CheckoutSalesSampleDataProductEntityTest.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@
1212
<data name="id" xsi:type="string">1</data>
1313
<data name="salesRule" xsi:type="string">active_sales_rule_for_all_groups</data>
1414
<data name="prices" xsi:type="array">
15-
<item name="grandTotal" xsi:type="string">50.00</item>
15+
<item name="grandTotal" xsi:type="string">53.71</item>
1616
</data>
1717
<data name="status" xsi:type="string">Pending</data>
1818
<data name="orderButtonsAvailable" xsi:type="string">Back, Cancel, Hold, Ship, Invoice, Edit</data>
1919
<data name="payment/method" xsi:type="string">checkmo</data>
2020
<data name="checkoutMethod" xsi:type="string">login</data>
21-
<data name="shippingAddress/dataset" xsi:type="string">US_address_1_without_email</data>
2221
<data name="shipping/shipping_service" xsi:type="string">Flat Rate</data>
2322
<data name="shipping/shipping_method" xsi:type="string">Fixed</data>
2423
<data name="configData" xsi:type="string">checkmo</data>
24+
<data name="customer/data/firstname" xsi:type="string">Veronica</data>
25+
<data name="customer/data/lastname" xsi:type="string">Costello</data>
26+
<data name="customer/data/email" xsi:type="string">[email protected]</data>
27+
<data name="customer/data/password" xsi:type="string">[email protected]</data>
2528
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage"/>
2629
<constraint name="Magento\Sales\Test\Constraint\AssertOrderInOrdersGridOnFrontend"/>
2730
</variation>

dev/tests/functional/tests/app/Magento/SalesSampleData/Test/etc/testcase.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/TestCase/etc/testcase.xsd">
99
<scenario name="CheckoutSalesSampleDataProductEntityTest" firstStep="setupConfiguration">
10-
<step name="setupConfiguration" module="Magento_Config" next="createCustomer"/>
11-
<step name="createCustomer" module="Magento_Customer" next="createProducts"/>
10+
<step name="setupConfiguration" module="Magento_Config" next="loginCustomerOnFrontend"/>
11+
<step name="loginCustomerOnFrontend" module="Magento_Customer" next="createProducts"/>
1212
<step name="createProducts" module="Magento_Catalog" next="addProductsToTheCart"/>
1313
<step name="addProductsToTheCart" module="Magento_Checkout" next="estimateShippingAndTax"/>
1414
<step name="estimateShippingAndTax" module="Magento_Checkout" next="clickProceedToCheckout"/>
15-
<step name="clickProceedToCheckout" module="Magento_Checkout" next="selectCheckoutMethod"/>
16-
<step name="selectCheckoutMethod" module="Magento_Checkout" next="fillShippingAddress"/>
17-
<step name="fillShippingAddress" module="Magento_Checkout" next="fillShippingMethod"/>
15+
<step name="clickProceedToCheckout" module="Magento_Checkout" next="fillShippingMethod"/>
1816
<step name="fillShippingMethod" module="Magento_Checkout" next="selectPaymentMethod"/>
1917
<step name="selectPaymentMethod" module="Magento_Checkout" next="placeOrder"/>
2018
<step name="placeOrder" module="Magento_Checkout"/>

0 commit comments

Comments
 (0)