Skip to content

Commit 10d3263

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #45 from magento-dragons/merchant_beta_sample_data
[Merchant Beta] MAGETWO-42907: Porting Sample Data fixes for merchant beta
2 parents 9cdcdfc + a0e443a commit 10d3263

File tree

748 files changed

+7605
-3511
lines changed

Some content is hidden

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

748 files changed

+7605
-3511
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#Introduction
2+
3+
Magento sample data uses the responsive Luma theme to display a sample store, complete with products, categories, promotional price rules, CMS pages, banners, and so on. You can use the sample data to come up to speed quickly and see the power and flexibility of the Magento storefront.
4+
5+
Installing sample data is optional; you can install it before or after you install the Magento software.
6+
7+
#Deployment
8+
9+
##From Composer
10+
To deploy sample data from Composer, use:
11+
12+
1. In your composer.json, specify the following:
13+
- repository:
14+
```
15+
{
16+
"repositories": [
17+
{
18+
"type": "composer",
19+
"url": "http://packages.magento.com/"
20+
}
21+
],
22+
}
23+
```
24+
25+
- packages:
26+
```
27+
{
28+
"require": {
29+
"magento/sample-data": "{version}"
30+
}
31+
}
32+
```
33+
34+
where version is either an exact version or semantic version syntax.
35+
2. From your Magento root directory, run composer update.
36+
37+
##From repository
38+
To deploy sample data from repository, use:
39+
40+
1. Clone the sample data repository. For example, git clone [https://github.com/magento/magento2-sample-data.git](https://github.com/magento/magento2-sample-data.git)
41+
2. Link the sample data repository with your Magento CE repository as follows:
42+
```
43+
php -f <sample-data-root>/dev/tools/build-sample-data.php -- --ce-source="path/to/magento/ce/edition"
44+
```
45+
46+
#Installation
47+
48+
Once deployed, the sample data can be installed using the Magento Setup Wizard (web installation) or using CLI (console installation).
49+
50+
###Web Installation
51+
52+
When installing the Magento application using the Magento Setup Wizard, you can choose to install the sample data at Step 4. Customize Your Store by selecting the *Use Sample Data* check box.
53+
54+
###Console Installation
55+
56+
The steps required to install sample data are different depending on whether the Magento application itself is installed:
57+
58+
- If the Magento application is not installed, you can install it with sample data at once. Use the following code sample as an example:
59+
```
60+
php -f index.php install --base-url=http://localhost/magento2/ \
61+
--backend-frontname=admin \
62+
--db-host=localhost --db-name=magento --db-user=magento --db-password=magento \
63+
--admin-firstname=Magento --admin-lastname=User --admin-email=[email protected] \
64+
--admin-user=admin --admin-password=iamtheadmin --language=en_US \
65+
--currency=USD --timezone=America/Chicago
66+
--use-sample-data
67+
```
68+
- If the Magento application is already installed, to install the sample data, enter the following commands in the order shown:
69+
```
70+
<path to Magento 2 bin dir>/magento setup:upgrade
71+
<path to Magento 2 bin dir>/magento sampledata:install <your Magento administrator user name>
72+
```
73+
74+
For example,
75+
```
76+
/var/www/magento2/bin magento setup:upgrade
77+
/var/www/magento2/bin magento sampledata:install admin
78+
```
79+
80+
#Removing Sample Data
81+
82+
There are no special scripts that assist in uninstalling of sample data.
83+
To remove sample data, you must delete the database and re-install Magento with a new empty database
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\SampleData\Model;
7+
8+
/**
9+
* Mail Transport that do not send mail
10+
*/
11+
class BlackHole implements \Magento\Framework\Mail\TransportInterface
12+
{
13+
/**
14+
* Send a mail using this transport
15+
*
16+
* @return void
17+
*/
18+
public function sendMessage()
19+
{
20+
return true;
21+
}
22+
}

app/code/Magento/SampleData/Module/ConfigurableProduct/Setup/Product.php

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,64 @@
55
*/
66
namespace Magento\SampleData\Module\ConfigurableProduct\Setup;
77

8-
use Magento\SampleData\Helper\Csv\ReaderFactory as CsvReaderFactory;
9-
use Magento\SampleData\Helper\Fixture as FixtureHelper;
108
use Magento\SampleData\Model\SetupInterface;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
1110

1211
/**
1312
* Setup configurable product
1413
*/
15-
class Product extends \Magento\SampleData\Module\Catalog\Setup\Product implements SetupInterface
14+
class Product implements SetupInterface
1615
{
1716
/**
18-
* @var string
17+
* @var \Magento\SampleData\Model\Logger
1918
*/
20-
protected $productType = \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE;
19+
private $logger;
2120

2221
/**
23-
* @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable
22+
* @var \Magento\ImportExport\Model\Import
2423
*/
25-
protected $configurableProductType;
24+
private $importModel;
2625

2726
/**
28-
* @var \Magento\Eav\Model\Config
27+
* @var \Magento\ImportExport\Model\Import\Source\CsvFactory
2928
*/
30-
protected $eavConfig;
29+
private $csvSourceFactory;
3130

3231
/**
33-
* @var string
32+
* @var \Magento\Framework\Filesystem
3433
*/
35-
protected $attributeSet;
34+
private $filesystem;
35+
36+
/**
37+
* @var \Magento\Indexer\Model\Indexer\CollectionFactory
38+
*/
39+
private $indexerCollectionFactory;
3640

3741
/**
38-
* @param \Magento\Catalog\Model\ProductFactory $productFactory
39-
* @param \Magento\Catalog\Model\Config $catalogConfig
40-
* @param Product\Converter $converter
41-
* @param FixtureHelper $fixtureHelper
42-
* @param CsvReaderFactory $csvReaderFactory
43-
* @param Product\Gallery $gallery
4442
* @param \Magento\SampleData\Model\Logger $logger
45-
* @param \Magento\SampleData\Helper\StoreManager $storeManager
46-
* @param \Magento\ConfigurableProduct\Model\Product\Type\Configurable $configurableProductType
4743
* @param \Magento\Eav\Model\Config $eavConfig
48-
* @param array $fixtures
44+
* @param \Magento\ImportExport\Model\Import $importModel
45+
* @param \Magento\ImportExport\Model\Import\Source\CsvFactory $csvSourceFactory
46+
* @param \Magento\Indexer\Model\Indexer\CollectionFactory $indexerCollectionFactory
47+
* @param \Magento\Framework\Filesystem $filesystem
4948
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5049
* @codingStandardsIgnoreStart
5150
*/
5251
public function __construct(
53-
\Magento\Catalog\Model\ProductFactory $productFactory,
54-
\Magento\Catalog\Model\Config $catalogConfig,
55-
Product\Converter $converter,
56-
FixtureHelper $fixtureHelper,
57-
CsvReaderFactory $csvReaderFactory,
58-
Product\Gallery $gallery,
5952
\Magento\SampleData\Model\Logger $logger,
60-
\Magento\SampleData\Helper\StoreManager $storeManager,
61-
\Magento\ConfigurableProduct\Model\Product\Type\Configurable $configurableProductType,
6253
\Magento\Eav\Model\Config $eavConfig,
63-
$fixtures = [
64-
'ConfigurableProduct/products_men_tops.csv',
65-
'ConfigurableProduct/products_men_bottoms.csv',
66-
'ConfigurableProduct/products_women_tops.csv',
67-
'ConfigurableProduct/products_women_bottoms.csv',
68-
'ConfigurableProduct/products_gear_fitness_equipment_ball.csv',
69-
'ConfigurableProduct/products_gear_fitness_equipment_strap.csv',
70-
]
54+
\Magento\ImportExport\Model\Import $importModel,
55+
\Magento\ImportExport\Model\Import\Source\CsvFactory $csvSourceFactory,
56+
\Magento\Indexer\Model\Indexer\CollectionFactory $indexerCollectionFactory,
57+
\Magento\Framework\Filesystem $filesystem
7158
) {
59+
$this->logger = $logger;
7260
$this->eavConfig = $eavConfig;
73-
$this->configurableProductType = $configurableProductType;
74-
parent::__construct(
75-
$productFactory,
76-
$catalogConfig,
77-
$converter,
78-
$fixtureHelper,
79-
$csvReaderFactory,
80-
$gallery,
81-
$logger,
82-
$storeManager,
83-
$fixtures
84-
);
61+
$this->importModel = $importModel;
62+
$this->csvSourceFactory = $csvSourceFactory;
63+
$this->indexerCollectionFactory = $indexerCollectionFactory;
64+
$this->filesystem = $filesystem;
65+
8566
}
8667
// @codingStandardsIgnoreEnd
8768

@@ -90,27 +71,47 @@ public function __construct(
9071
*/
9172
public function run()
9273
{
93-
parent::run();
74+
$this->logger->log('Installing configurable products:');
75+
76+
$importModel = $this->importModel;
77+
$importModel->setData(
78+
[
79+
'entity' => 'catalog_product',
80+
'behavior' => 'append',
81+
'import_images_file_dir' => 'pub/media/catalog/product'
82+
]
83+
);
84+
85+
$source = $this->csvSourceFactory->create(
86+
[
87+
'file' => 'Magento/SampleData/fixtures/ConfigurableProduct/import-export_products-img.csv',
88+
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::MODULES)
89+
]
90+
);
91+
92+
$currentPath = getcwd();
93+
chdir($this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath());
94+
95+
$importModel->validateSource($source);
96+
$importModel->importSource();
97+
98+
chdir($currentPath);
99+
100+
$this->logger->logInline('.');
101+
94102
$this->eavConfig->clear();
103+
$this->reindex();
104+
105+
$this->logger->logInline('.');
95106
}
96107

97108
/**
98-
* @inheritdoc
109+
* Perform full reindex
99110
*/
100-
protected function prepareProduct($product, $data)
111+
private function reindex()
101112
{
102-
if ($this->attributeSet !== $data['attribute_set']) {
103-
$this->attributeSet = $data['attribute_set'];
104-
$this->eavConfig->clear();
105-
}
106-
if (empty($data['associated_product_ids'])) {
107-
$simpleIds = $this->configurableProductType
108-
->generateSimpleProducts($product, $data['variations_matrix']);
109-
} else {
110-
$simpleIds = $data['associated_product_ids'];
113+
foreach ($this->indexerCollectionFactory->create()->getItems() as $indexer) {
114+
$indexer->reindexAll();
111115
}
112-
$product->setAssociatedProductIds($simpleIds);
113-
$product->setCanSaveConfigurableAttributes(true);
114-
return $this;
115116
}
116117
}

app/code/Magento/SampleData/Module/Customer/Setup/Customer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public function run()
161161
'\Magento\Customer\Api\Data\CustomerInterface'
162162
);
163163
$customer->setAddresses([$addresses]);
164-
165164
$this->accountManagement->createAccount($customer, $row['password']);
166165
$this->logger->logInline('.');
167166
}

app/code/Magento/SampleData/Module/Sales/Setup/Order/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected function processQuote($data = [])
163163
if (!empty($data['order'])) {
164164
$orderCreateModel->importPostData($data['order']);
165165
}
166-
$orderCreateModel->getQuote()->setReservedOrderId($data['order']['increment_id']);
166+
$orderCreateModel->getQuote()->setReservedOrderId(null);
167167
$orderCreateModel->getBillingAddress();
168168
$orderCreateModel->setShippingAsBilling(true);
169169
if (!empty($data['add_products'])) {

app/code/Magento/SampleData/README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#Introduction
22

3-
Sample data consists of installation scripts, fixtures and media files.
4-
Installing sample data fills your database with a number of products of each type, price rules, CMS pages, banners and more.
3+
Magento sample data uses the responsive Luma theme to display a sample store, complete with products, categories, promotional price rules, CMS pages, banners, and so on. You can use the sample data to come up to speed quickly and see the power and flexibility of the Magento storefront.
4+
5+
Installing sample data is optional; you can install it before or after you install the Magento software.
56

67
#Deployment
78

8-
To deploy sample data, use Composer:
9+
##From Composer
10+
To deploy sample data from Composer, use:
911

1012
1. In your composer.json, specify the following:
1113
- repository:
@@ -28,15 +30,26 @@ To deploy sample data, use Composer:
2830
}
2931
}
3032
```
33+
34+
where version is either an exact version or semantic version syntax.
3135
2. From your Magento root directory, run composer update.
3236
37+
##From repository
38+
To deploy sample data from repository, use:
39+
40+
1. Clone the sample data repository. For example, git clone [https://github.com/magento/magento2-sample-data.git](https://github.com/magento/magento2-sample-data.git)
41+
2. Link the sample data repository with your Magento CE repository as follows:
42+
```
43+
php -f <sample-data-root>/dev/tools/build-sample-data.php -- --ce-source="path/to/magento/ce/edition"
44+
```
45+
3346
#Installation
3447
35-
Once deployed, the sample data can be installed using the Magento Installation Wizard (web installation) or using CLI (console installation).
48+
Once deployed, the sample data can be installed using the Magento Setup Wizard (web installation) or using CLI (console installation).
3649
3750
###Web Installation
3851
39-
When installing the Magento application using the Magento Installation Wizard, you can choose to install the sample data at once. To do this, during installation, on the **Customize Your Store** step, select the **Use Sample Data** checkbox.
52+
When installing the Magento application using the Magento Setup Wizard, you can choose to install the sample data at Step 4. Customize Your Store by selecting the *Use Sample Data* check box.
4053
4154
###Console Installation
4255

app/code/Magento/SampleData/etc/di.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,24 @@
1313
</argument>
1414
</arguments>
1515
</type>
16+
<virtualType name="Magento\SampleData\Model\BlackHoleFactory" type="\Magento\Framework\Mail\TransportInterfaceFactory">
17+
<arguments>
18+
<argument name="instanceName" xsi:type="string">Magento\SampleData\Model\BlackHole</argument>
19+
</arguments>
20+
</virtualType>
21+
<virtualType name="blackHoleTransportBuilder" type="Magento\Framework\Mail\Template\TransportBuilder">
22+
<arguments>
23+
<argument name="mailTransportFactory" xsi:type="object" >Magento\SampleData\Model\BlackHoleFactory</argument>
24+
</arguments>
25+
</virtualType>
26+
<virtualType name="sampleDataAccountManagement" type="Magento\Customer\Model\AccountManagement">
27+
<arguments>
28+
<argument name="transportBuilder" xsi:type="object">blackHoleTransportBuilder</argument>
29+
</arguments>
30+
</virtualType>
31+
<type name="Magento\SampleData\Module\Customer\Setup\Customer">
32+
<arguments>
33+
<argument name="accountManagement" xsi:type="object">sampleDataAccountManagement</argument>
34+
</arguments>
35+
</type>
1636
</config>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sku,image
2-
24-WG080,/sample_data/l/u/luma-yoga-kit-2.jpg
2+
24-WG080,/l/u/luma-yoga-kit-2.jpg

0 commit comments

Comments
 (0)