forked from FriendsOfSylius/SyliusImportExportPlugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/import export product in csv (FriendsOfSylius#196)
* add import/export of products * use context in behat * fix returns type * enable products import/export behat tests use (new) comma separator add cli behat tests update README.md fix return type and typo fix exportKeysAvailable clean not need store data importer add transformer improve product import/export update for new controller style allow to remove product attribute value update for sylius 1.4 * add images channels locals add images channels locals * upgrade feature for tests imports fix phpstan version * set length to product datas * add variant price * upgrade to clean code * update channel price * fix export images * fix export images * fix export images * fix export price * use ImportResultLoggerInterface * fix ImporterResultInterface
- Loading branch information
1 parent
75e7ad3
commit 0557db8
Showing
51 changed files
with
1,684 additions
and
19 deletions.
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
13 changes: 13 additions & 0 deletions
13
features/export/cli/exporting_products_to_csv_via_cli.feature
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,13 @@ | ||
@managing_products | ||
Feature: exporting products to csv-file | ||
In order to have my products exported to an external target | ||
As a developer | ||
I want to be able to export product data to csv file from the commandline | ||
|
||
Background: | ||
Given I have a working command-line interface | ||
|
||
@cli_importer_exporter | ||
Scenario: Exporting products to csv-file | ||
When I export "product" data as "csv" to the file "products_export.csv" with the cli-command | ||
Then I should see "Exported" in the output |
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,17 @@ | ||
@managing_products | ||
Feature: Export Products from grid | ||
In order to have my products exported to an external target | ||
As an Administrator | ||
I want to be able to export product data to csv file from backOffice | ||
|
||
Background: | ||
Given I am logged in as an administrator | ||
And the store has a product "T-shirt cool" | ||
|
||
@ui | ||
Scenario: Exporting products should export all of them | ||
When I open the product admin index page | ||
And I should see 1 products in the list | ||
Then I go to "/admin/export/sylius.product/csv" homepage | ||
And response should contain "Code,Locale,Name,Description,Short_description,Meta_description,Meta_keywords,Main_taxon,Taxons,Channels,Enabled" | ||
And response should contain 'T_SHIRT_COOL,en_US,"T-shirt cool",,,,,,,,1' |
21 changes: 21 additions & 0 deletions
21
features/export/ui/exporting_products_with_attributs.feature
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,21 @@ | ||
@managing_products | ||
Feature: Export Products with attributes from grid | ||
In order to have my products exported to an external target | ||
As an Administrator | ||
I want to be able to export product data and her attributes to csv file from backOffice | ||
|
||
Background: | ||
Given I am logged in as an administrator | ||
And the store has a select product attribute "Attribute select" with values "select1" and "select2" | ||
And the store has a product "T-shirt cool" | ||
And this product has text attribute "Attribute text" with value "Banana" | ||
And this product has textarea attribute "Attribute textarea" with value "Banana <br /> Bananaaaa !!!" | ||
And this product has percent attribute "Attribute percent" with value 22% | ||
|
||
@ui | ||
Scenario: Exporting products should export all of them | ||
When I open the product admin index page | ||
And I should see 1 products in the list | ||
Then I go to "/admin/export/sylius.product/csv" homepage | ||
And response should contain "Attribute_text,Attribute_textarea,Attribute_percent" | ||
And response should contain 'Banana,"Banana <br /> Bananaaaa !!!",0.22' |
16 changes: 16 additions & 0 deletions
16
features/import/cli/importing_products_from_csv_via_cli.feature
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,16 @@ | ||
@managing_products | ||
Feature: Importing products from csv with the command-line interface | ||
In order to have my products from external source | ||
As a developer | ||
I want to be able to import data from csv file from the commandline | ||
|
||
Background: | ||
Given I have a working command-line interface | ||
|
||
@cli_importer_exporter | ||
Scenario: Importing defined products with the cli-command | ||
When I import "product" data from csv file "products.csv" file with the cli-command | ||
Then I should see "Imported" in the output | ||
And I should have at least the following product ids in the database: | ||
| 123456 | | ||
| 222333 | |
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,17 @@ | ||
@managing_products | ||
Feature: Import Products from grid | ||
In order to have my products exported to an external target | ||
As an Administrator | ||
I want to be able to import product data to csv file from backOffice | ||
|
||
Background: | ||
Given I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Import products should create all of them | ||
When I open the product admin index page | ||
And I import product data from "products.csv" csv file | ||
Then I should see a notification that the import was successful | ||
And I should see 2 products in the list | ||
And the first product on the list should have name "Product 1" | ||
And the last product on the list should have name "Product 2" |
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,19 @@ | ||
@managing_products | ||
Feature: Import Products from grid | ||
In order to have my products exported to an external target | ||
As an Administrator | ||
I want to be able to import product data to csv file from backOffice | ||
|
||
Background: | ||
Given I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Import products should update them | ||
When I open the product admin index page | ||
And I import product data from "products.csv" csv file | ||
Then I should see a notification that the import was successful | ||
And I import product data from "products_update.csv" csv file | ||
Then I should see a notification that the import was successful | ||
And I should see 2 products in the list | ||
And the first product on the list should have name "Product 1" | ||
And the last product on the list should have name "Product 2 update" |
21 changes: 21 additions & 0 deletions
21
features/import/ui/importing_products_with_attributes.feature
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,21 @@ | ||
@managing_products | ||
Feature: Import Products with attributes from grid | ||
In order to have my products exported to an external target | ||
As an Administrator | ||
I want to be able to import product data and her attributes to csv file from backOffice | ||
|
||
Background: | ||
Given I am logged in as an administrator | ||
Given the store has locale "en_US" | ||
And the store has a text product attribute "Attribute text" | ||
And the store has a textarea product attribute "Attribute textarea" | ||
And the store has a percent product attribute "Attribute percent" | ||
|
||
@ui | ||
Scenario: Exporting products should export all of them | ||
When I open the product admin index page | ||
And I import product data from "products_attr.csv" csv file | ||
Then I should see a notification that the import was successful | ||
And I should see 2 products in the list | ||
Then the product "Product 1" should appear in the registry | ||
And attribute "Attribute text" of product "Product 1" should be "Banana" in "en_US" |
53 changes: 53 additions & 0 deletions
53
spec/Exporter/Transformer/Handler/ArrayToStringHandlerSpec.php
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\FriendsOfSylius\SyliusImportExportPlugin\Exporter\Transformer\Handler; | ||
|
||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Transformer\Handler; | ||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Transformer\Handler\ArrayToStringHandler; | ||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Transformer\HandlerInterface; | ||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Transformer\Pool; | ||
use PhpSpec\ObjectBehavior; | ||
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; | ||
use Webmozart\Assert\Assert; | ||
|
||
class ArrayToStringHandlerSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(ArrayToStringHandler::class); | ||
} | ||
|
||
function it_extends() | ||
{ | ||
$this->shouldHaveType(Handler::class); | ||
} | ||
|
||
function it_should_implement() | ||
{ | ||
$this->shouldImplement(HandlerInterface::class); | ||
} | ||
|
||
function it_should_process_directly() | ||
{ | ||
$array = ['a', 'b', 'c']; | ||
$this->handle('test', $array)->shouldBeString(); | ||
$this->handle('test', $array)->shouldBe('a|b|c'); | ||
} | ||
|
||
function it_should_process_via_pool() | ||
{ | ||
$array = ['a', 'b', 'c']; | ||
|
||
$generator = new RewindableGenerator(function () { | ||
return [$this->getWrappedObject()]; | ||
}, $count = 1); | ||
|
||
$pool = new Pool($generator); | ||
|
||
$result = $pool->handle('test', $array); | ||
|
||
Assert::same('a|b|c', $result); | ||
} | ||
} |
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
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
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace FriendsOfSylius\SyliusImportExportPlugin\Exporter\Plugin; | ||
|
||
use FriendsOfSylius\SyliusImportExportPlugin\Service\AttributeCodesProviderInterface; | ||
use FriendsOfSylius\SyliusImportExportPlugin\Service\ImageTypesProviderInterface; | ||
|
||
final class ProductPluginPool extends PluginPool | ||
{ | ||
/** @var ImageTypesProviderInterface */ | ||
private $imageTypesProvider; | ||
/** @var AttributeCodesProviderInterface */ | ||
private $attributeCodesProvider; | ||
|
||
public function __construct( | ||
array $plugins, | ||
array $exportKeys, | ||
AttributeCodesProviderInterface $attributeCodesProvider, | ||
ImageTypesProviderInterface $imageTypesProvider | ||
) { | ||
parent::__construct($plugins, $exportKeys); | ||
$this->attributeCodesProvider = $attributeCodesProvider; | ||
$this->imageTypesProvider = $imageTypesProvider; | ||
} | ||
|
||
public function initPlugins(array $ids): void | ||
{ | ||
$this->exportKeys = \array_merge($this->exportKeys, $this->attributeCodesProvider->getAttributeCodesList()); | ||
$this->exportKeys = \array_merge($this->exportKeys, $this->imageTypesProvider->getProductImagesCodesWithPrefixList()); | ||
$this->exportKeysAvailable = $this->exportKeys; | ||
parent::initPlugins($ids); | ||
} | ||
} |
Oops, something went wrong.