Skip to content

Commit

Permalink
Revert "Revert "added grouped with test data""
Browse files Browse the repository at this point in the history
This reverts commit 6793df7.
  • Loading branch information
jeffbritts committed Jan 23, 2020
1 parent 883c006 commit ea0335f
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Model/Bundle/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ class Product extends \Magento\CatalogSampleDataVenia\Setup\Product
* @param SampleDataContext $sampleDataContext
* @param \Magento\Catalog\Model\ProductFactory $productFactory
* @param \Magento\Catalog\Model\ConfigFactory $catalogConfig
* @param Product\Converter $converter
* @param Converter $converter
* @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,
Expand Down
48 changes: 48 additions & 0 deletions Model/Grouped/Converter.php
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;
}
}
90 changes: 90 additions & 0 deletions Model/Grouped/Product.php
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;
}
}
}
63 changes: 63 additions & 0 deletions Setup/Patch/Data/InstallGroupedProducts.php
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 [];
}
}
2 changes: 2 additions & 0 deletions fixtures/Grouped/images_jewelry_grouped.csv
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
7 changes: 7 additions & 0 deletions fixtures/Grouped/jewelry_grouped.csv
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

0 comments on commit ea0335f

Please sign in to comment.