-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "added grouped with test data""
This reverts commit 6793df7.
- Loading branch information
1 parent
883c006
commit ea0335f
Showing
6 changed files
with
212 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\CatalogSampleDataVenia\Model\Grouped; | ||
|
||
/** | ||
* Convert data for grouped product | ||
*/ | ||
class Converter extends \Magento\CatalogSampleDataVenia\Setup\Product\Converter | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function convertField(&$data, $field, $value) | ||
{ | ||
if ('associated_sku' == $field) { | ||
$data['grouped_link_data'] = $this->convertGroupedAssociated($value); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @param string $associated | ||
* @return array | ||
*/ | ||
public function convertGroupedAssociated($associated) | ||
{ | ||
$skuList = explode(',', $associated); | ||
$data = []; | ||
$position = 0; | ||
foreach ($skuList as $sku) { | ||
$productId = $this->getProductIdBySku($sku); | ||
if (!$productId) { | ||
continue; | ||
} | ||
$data[$productId] = [ | ||
'id' => $productId, | ||
'position' => $position++, | ||
'qty' => '1', | ||
]; | ||
} | ||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogSampleDataVenia\Model\Grouped; | ||
|
||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\Setup\SampleData\Context as SampleDataContext; | ||
|
||
/** | ||
* Setup grouped product | ||
*/ | ||
class Product extends \Magento\CatalogSampleDataVenia\Setup\Product | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $productType = \Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE; | ||
|
||
/** | ||
* @var \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks | ||
*/ | ||
private $productLinksHelper; | ||
|
||
/** | ||
* Product constructor. | ||
* @param SampleDataContext $sampleDataContext | ||
* @param \Magento\Catalog\Model\ProductFactory $productFactory | ||
* @param \Magento\Catalog\Model\ConfigFactory $catalogConfig | ||
* @param \Magento\CatalogSampleDataVenia\Model\Grouped\Converter $converter | ||
* @param \Magento\Framework\Setup\SampleData\FixtureManager $fixtureManager | ||
* @param \Magento\CatalogSampleDataVenia\Setup\Product\Gallery $gallery | ||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
* @param \Magento\Eav\Model\Config $eavConfig | ||
* @param \Magento\Framework\App\State $appState | ||
*/ | ||
public function __construct( | ||
SampleDataContext $sampleDataContext, | ||
\Magento\Catalog\Model\ProductFactory $productFactory, | ||
\Magento\Catalog\Model\ConfigFactory $catalogConfig, | ||
\Magento\CatalogSampleDataVenia\Model\Grouped\Converter $converter, | ||
\Magento\Framework\Setup\SampleData\FixtureManager $fixtureManager, | ||
\Magento\CatalogSampleDataVenia\Setup\Product\Gallery $gallery, | ||
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||
\Magento\Eav\Model\Config $eavConfig, | ||
\Magento\Framework\App\State $appState | ||
) { | ||
parent::__construct( | ||
$sampleDataContext, | ||
$productFactory, | ||
$catalogConfig, | ||
$converter, | ||
$gallery, | ||
$storeManager, | ||
$eavConfig, | ||
$appState | ||
); | ||
} | ||
|
||
/** | ||
* @param \Magento\Catalog\Model\Product $product | ||
* @param array $data | ||
* @return $this | ||
*/ | ||
protected function prepareProduct($product, $data) | ||
{ | ||
$this->getProductLinksHelper()->initializeLinks($product, $data['grouped_link_data']); | ||
$product->unsetData('grouped_link_data'); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get product links helper | ||
* | ||
* @deprecated | ||
* @return \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks | ||
*/ | ||
private function getProductLinksHelper() | ||
{ | ||
|
||
if (!($this->productLinksHelper)) { | ||
return ObjectManager::getInstance()->get( | ||
'\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks' | ||
); | ||
} else { | ||
return $this->productLinksHelper; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\CatalogSampleDataVenia\Setup\Patch\Data; | ||
|
||
|
||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Store\Model\Store; | ||
use Magento\CatalogSampleDataVenia\Model\Grouped\Product as GroupProduct; | ||
|
||
class InstallGroupedProducts implements DataPatchInterface | ||
{ | ||
|
||
|
||
/** | ||
* Setup class for group products | ||
* | ||
* @var GroupProduct | ||
*/ | ||
protected $groupedProduct; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* InstallGroupedProducts constructor. | ||
* @param GroupProduct $groupedProduct | ||
* @param StoreManagerInterface|null $storeManager | ||
*/ | ||
public function __construct( | ||
GroupProduct $groupedProduct, | ||
StoreManagerInterface $storeManager = null | ||
) { | ||
$this->groupedProduct = $groupedProduct; | ||
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance() | ||
->get(StoreManagerInterface::class); | ||
} | ||
|
||
public function apply() | ||
{ | ||
$this->storeManager->setCurrentStore(Store::DISTRO_STORE_ID); | ||
$this->groupedProduct->install( | ||
['Magento_CatalogSampleDataVenia::fixtures/Grouped/jewelry_grouped.csv'] , | ||
['Magento_CatalogSampleDataVenia::fixtures/Grouped/images_jewelry_grouped.csv'] | ||
); | ||
} | ||
|
||
public static function getDependencies() | ||
{ | ||
return [InstallSimpleProducts::class]; | ||
} | ||
|
||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sku,image | ||
24-WG085_Group,/l/u/luma-yoga-strap-set.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
category,name,sku,price,qty,description,associated_sku,attribute_set | ||
"Accessories | ||
Jewelry","Venia Group Product",VA23,,100,"<p>Description</p> | ||
<li> 100% soft and durable cotton. | ||
<li> Plastic cinch buckle is easy to use. | ||
<li> Choice of three natural colors made from phthalate and heavy metal free dyes. | ||
</ul>","VA12-SI-NA,VA14-SI-NA,VA21-GO-NA",Fashion Accessories |