Skip to content

Commit

Permalink
2.3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbritts committed Aug 10, 2018
1 parent 5ff3531 commit 18853de
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Model/Attribute.php → Setup/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSampleDataVenia\Model;
namespace Magento\CatalogSampleDataVenia\Setup;

use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
use Magento\Store\Model\StoreManagerInterface;
Expand Down
2 changes: 1 addition & 1 deletion Model/Category.php → Setup/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSampleDataVenia\Model;
namespace Magento\CatalogSampleDataVenia\Setup;

use Magento\Framework\Setup\SampleData\Context as SampleDataContext;

Expand Down
35 changes: 0 additions & 35 deletions Setup/InstallData.php

This file was deleted.

64 changes: 0 additions & 64 deletions Setup/Installer.php

This file was deleted.

104 changes: 104 additions & 0 deletions Setup/Patch/Data/InstallSimpleProducts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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\Framework\Setup\ModuleDataSetupInterface;
use Magento\CatalogSampleDataVenia\Setup\Category;
use Magento\CatalogSampleDataVenia\Setup\Attribute;
use Magento\CatalogSampleDataVenia\Setup\Product;
use Magento\Framework\Setup\Patch\PatchVersionInterface;

/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class InstallSimpleProducts implements
DataPatchInterface, PatchVersionInterface
{
/**
* Setup class for category
*
* @var \Magento\CatalogSampleDataVenia\Setup\Category
*/
protected $categorySetup;

/**
* Setup class for product attributes
*
* @var \Magento\CatalogSampleDataVenia\Setup\Attribute
*/
protected $attributeSetup;

/**
* Setup class for products
*
* @var \Magento\CatalogSampleDataVenia\Setup\Product
*/
protected $productSetup;


/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;

/**
* InstallSimpleProducts constructor.
* @param ModuleDataSetupInterface $moduleDataSetup
* @param Category $categorySetup
* @param Attribute $attributeSetup
* @param Product $productSetup
*/
public function __construct(ModuleDataSetupInterface $moduleDataSetup, Category $categorySetup,
Attribute $attributeSetup, Product $productSetup)
{
$this->moduleDataSetup = $moduleDataSetup;
$this->categorySetup = $categorySetup;
$this->attributeSetup = $attributeSetup;
$this->productSetup = $productSetup;
}

/**
* Do Upgrade
*
* @return void
*/
public function apply()
{
$this->attributeSetup->install(['Magento_CatalogSampleDataVenia::fixtures/attributes.csv']);
$this->categorySetup->install(['Magento_CatalogSampleDataVenia::fixtures/categories.csv']);
$this->productSetup->install(
[
'Magento_CatalogSampleDataVenia::fixtures/SimpleProduct/products_accessories.csv'
],
[
'Magento_CatalogSampleDataVenia::fixtures/SimpleProduct/images_accessories.csv'
]
);
}

/**
* {@inheritdoc}
*/
public function getAliases()
{
return [];
}

/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [

];
}
public static function getVersion(){
return '0.0.0';
}
}
17 changes: 13 additions & 4 deletions Model/Product.php → Setup/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSampleDataVenia\Model;
namespace Magento\CatalogSampleDataVenia\Setup;

use Magento\Framework\Setup\SampleData\Context as SampleDataContext;

Expand Down Expand Up @@ -64,6 +64,9 @@ class Product
*/
protected $eavConfig;

/** @var \Magento\Framework\App\State */
protected $appState;

/**
* Product constructor.
* @param SampleDataContext $sampleDataContext
Expand All @@ -73,6 +76,7 @@ class Product
* @param 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 All @@ -81,7 +85,8 @@ public function __construct(
Product\Converter $converter,
Product\Gallery $gallery,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Eav\Model\Config $eavConfig
\Magento\Eav\Model\Config $eavConfig,
\Magento\Framework\App\State $appState
) {
$this->fixtureManager = $sampleDataContext->getFixtureManager();
$this->productFactory = $productFactory;
Expand All @@ -91,6 +96,7 @@ public function __construct(
$this->gallery = $gallery;
$this->storeManager = $storeManager;
$this->eavConfig = $eavConfig;
$this->appState = $appState;
}

/**
Expand Down Expand Up @@ -138,8 +144,11 @@ public function install(array $productFixtures, array $galleryFixtures)
}

$this->prepareProduct($product, $data);

$product->save();
$this->appState->emulateAreaCode(
'adminhtml',
[$product, 'save']
);
//$product->save();
$this->installGallery($product);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSampleDataVenia\Model\Product;
namespace Magento\CatalogSampleDataVenia\Setup\Product;

class Converter
{
Expand Down
2 changes: 1 addition & 1 deletion Model/Product/Gallery.php → Setup/Product/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSampleDataVenia\Model\Product;
namespace Magento\CatalogSampleDataVenia\Setup\Product;

use Magento\Catalog\Model\ProductFactory;
use Magento\Catalog\Model\ResourceModel\Product\Gallery as GalleryResource;
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_CatalogSampleDataVenia" setup_version="0.0.1">
<module name="Magento_CatalogSampleDataVenia">
<sequence>
<module name="Magento_Store"/>
<module name="Magento_Eav"/>
Expand Down

0 comments on commit 18853de

Please sign in to comment.