Skip to content

Commit

Permalink
PIM-6674: Mass actions only process ProductInterface. (#6770)
Browse files Browse the repository at this point in the history
* PIM-6674: Introduces a reader that returns only products of selection no models

* PIM-6674: Fix after rebase

* PIM-6674: Add integration test filter on identifier for product and product models

* PIM-6674: fix comments

* PIM-6674: Fix behats
  • Loading branch information
SamirBoulil authored Sep 24, 2017
1 parent 6e2bb9e commit 365bf39
Show file tree
Hide file tree
Showing 11 changed files with 701 additions and 32 deletions.
27 changes: 27 additions & 0 deletions features/Context/FixturesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Pim\Component\Catalog\Model\AttributeOptionInterface;
use Pim\Component\Catalog\Model\LocaleInterface;
use Pim\Component\Catalog\Model\ProductInterface;
use Pim\Component\Catalog\Model\ProductModelInterface;
use Pim\Component\Catalog\Model\ValueInterface;
use Pim\Component\Catalog\Repository\AttributeRepositoryInterface;
use Pim\Component\Catalog\Repository\FamilyVariantRepositoryInterface;
Expand Down Expand Up @@ -1501,6 +1502,24 @@ public function getProduct($sku)
return $product;
}

/**
* @param string $code
*
* @throws \InvalidArgumentException
*
* @return ProductModelInterface
*/
public function getProductModel($code)
{
$productModel = $this->spin(function () use ($code) {
return $this->getProductModelRepository()->findOneByIdentifier($code);
}, sprintf('Could not find a product model with code "%s"', $code));

$this->refresh($productModel);

return $productModel;
}

/**
* @param string $username
*
Expand Down Expand Up @@ -2140,6 +2159,14 @@ protected function getProductRepository()
return $this->getContainer()->get('pim_catalog.repository.product');
}

/**
* @return \Pim\Component\Catalog\Repository\ProductModelRepositoryInterface
*/
protected function getProductModelRepository()
{
return $this->getContainer()->get('pim_catalog.repository.product_model');
}

/**
* @return AttributeRepositoryInterface
*/
Expand Down
28 changes: 28 additions & 0 deletions features/Context/WebUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,23 @@ public function theFamilyOfProductShouldBe($sku, $expectedFamily = '')
}, sprintf('Expecting the family of "%s" to be "%s".', $sku, $expectedFamily));
}

/**
* @param string $code
* @param string|null $expectedFamily
*
* @Then /^the product model "([^"]*)" should have no family$/
* @Then /^the family of (?:the )?product model "([^"]*)" should be "([^"]*)"$/
*/
public function theFamilyOfProductModelShouldBe($code, $expectedFamily = '')
{
$this->spin(function () use ($code, $expectedFamily) {
$productModel = $this->getFixturesContext()->getProductModel($code);
$actualFamily = $productModel->getFamily() ? $productModel->getFamily()->getCode() : '';

return $expectedFamily === $actualFamily;
}, sprintf('Expecting the family of "%s" to be "%s".', $code, $expectedFamily));
}

/**
* @param string $sku
* @param string $categoryCode
Expand All @@ -1865,6 +1882,17 @@ public function theCategoryOfProductShouldBe($sku, $categoryCode)
);
}

/**
* @param string $sku
*
* @Then /^the product "([^"]*)" should not have any category$/
*/
public function theProductShouldNotHaveAnyCategory($sku)
{
$product = $this->getFixturesContext()->getProduct($sku);
assertEmpty($product->getCategoryCodes());
}

/**
* @param int $count
*
Expand Down
2 changes: 2 additions & 0 deletions features/Context/catalog/catalog_modeling/groups.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
code;type;label-en_US;label-fr_FR;label-de_DE
related;related;Related;Connexe;Verbunden
165 changes: 151 additions & 14 deletions features/mass-action/mass_edit_products_and_product_models.feature
Original file line number Diff line number Diff line change
@@ -1,28 +1,165 @@
# TODO: PIM-6357 - Scenario should be removed once mass edits work for product models.
@javascript
Feature: Apply a mass action on products and product models
Feature: Apply a mass action on products only (and not product models)
In order to modify my catalog
As a product manager
I need to be able to select products and product models at the same time in the grid and apply mass-edit on them

Background:
Given a "catalog_modeling" catalog configuration
And there is no "product" in the catalog
And there is no "product model" in the catalog
And the following root product models:
| code | parent | family_variant | categories | price | color | description-en_US-ecommerce |
| tshirt-unique-color | | clothing_color_size | master_men | 10 USD, 15 EUR | blue | A unique color t-shirt |
And the following products:
| sku | family | name-en_US | categories | size | description-en_US-ecommerce |
| tshirt-kurt-cobain-s | clothing | Tshirt Kurt Cobain S | Tshirts | S | A Kurt Cobain t-shirt |
And I am logged in as "Julia"
And I am on the products page

Scenario: Apply a mass action on products and product models
Given I am on the products page
And I select rows tshirt-unique-color and tshirt-kurt-cobain-s
Given I show the filter "color"
And I filter by "color" with operator "in list" and value "Crimson red"
And I select rows model-tshirt-divided-crimson-red, running-shoes-m-crimson-red and tshirt-unique-size-crimson-red
And I press the "Bulk actions" button
And I choose the "Edit common attributes" operation
And I display the Model description attribute
And I change the "Model description" to "a tee"
And I display the Composition attribute
And I change the "Composition" to "my composition"
When I move to the confirm page
Then I should see the text "You are about to update 2 products with the following information, please confirm."
Then I should see the text "You are about to update 3 products with the following information, please confirm."

Scenario: Mass edits common attributes of only products within a selection of products and product models
Given I show the filter "color"
And I filter by "color" with operator "in list" and value "Crimson red"
And I select rows model-tshirt-divided-crimson-red, running-shoes-m-crimson-red and tshirt-unique-size-crimson-red
And I press the "Bulk actions" button
And I choose the "Edit common attributes" operation
And I display the Composition attribute
And I change the "Composition" to "My composition"
When I confirm mass edit
And I wait for the "edit_common_attributes" job to finish
When I go on the last executed job resume of "edit_common_attributes"
Then I should see the text "COMPLETED"
And I should see the text "processed 2"
And I should see the text "skipped 1"
And I should see the text "Bulk actions do not support Product models entities yet."
And attribute composition of "tshirt-unique-size-crimson-red" should be "My composition"
And attribute composition of "running-shoes-m-crimson-red" should be "My composition"

Scenario: Mass edits family of only products within a selection of products and product models
Given I show the filter "color"
And I filter by "color" with operator "in list" and value "Navy blue"
And I select rows watch, tshirt-unique-size-navy-blue and model-tshirt-divided-navy-blue
And I press the "Bulk actions" button
And I choose the "Change family" operation
And I change the Family to "Shoes"
And I confirm mass edit
And I wait for the "update_product_value" job to finish
When I go on the last executed job resume of "update_product_value"
Then I should see the text "COMPLETED"
And I should see the text "processed 1"
And I should see the text "skipped 1"
And I should see the text "Skipped products 1"
And I should see the text "The variant product family must be the same than its parent: tshirt-unique-size-navy-blue"
And I should see the text "Bulk actions do not support Product models entities yet."
And the family of product "watch" should be "shoes"
And the family of product "tshirt-unique-size-crimson-red" should be "clothing"
And the family of product model "model-tshirt-divided-crimson-red" should be "clothing"

Scenario: Mass edits status of only products within a selection of products and product models
Given I show the filter "color"
And I filter by "color" with operator "in list" and value "Navy blue"
And I select rows watch, tshirt-unique-size-navy-blue and model-tshirt-divided-navy-blue
And I press the "Bulk actions" button
And I choose the "Change status" operation
And I disable the products
And I wait for the "update_product_value" job to finish
When I go on the last executed job resume of "update_product_value"
Then I should see the text "COMPLETED"
And I should see the text "processed 2"
And I should see the text "skipped 1"
And I should see the text "Bulk actions do not support Product models entities yet."
And product "watch" should be disabled
And product "tshirt-unique-size-navy-blue" should be disabled

Scenario: Mass edits groups of only products within a selection of products and product models
Given I show the filter "color"
And I filter by "color" with operator "in list" and value "Navy blue"
And I select rows watch, tshirt-unique-size-navy-blue and model-tshirt-divided-navy-blue
And I press the "Bulk actions" button
And I choose the "Add to groups" operation
And I check "Related"
When I confirm mass edit
And I wait for the "add_product_value" job to finish
When I go on the last executed job resume of "add_product_value"
Then I should see the text "COMPLETED"
And I should see the text "processed 2"
And I should see the text "skipped 1"
And I should see the text "Bulk actions do not support Product models entities yet."
Then "related" group should contain "watch, tshirt-unique-size-navy-blue"

Scenario: Mass edits add categories of only products within a selection of products and product models
Given I show the filter "color"
And I filter by "color" with operator "in list" and value "Navy blue"
And I select rows watch, tshirt-unique-size-navy-blue and model-tshirt-divided-navy-blue
And I press the "Bulk actions" button
And I choose the "Add to categories" operation
And I move on to the choose step
And I choose the "Add to categories" operation
And I select the "Master" tree
And I expand the "master" category
And I press the "Women" button
And I confirm mass edit
And I wait for the "add_product_value" job to finish
When I go on the last executed job resume of "add_product_value"
Then I should see the text "COMPLETED"
And I should see the text "processed 2"
And I should see the text "skipped 1"
And I should see the text "Bulk actions do not support Product models entities yet."
When I am on the products grid
And I open the category tree
Then I should be able to use the following filters:
| filter | operator | value | result |
| category | | master_women | watch, tshirt-unique-size-navy-blue |

Scenario: Mass edits move categories of only products within a selection of products and product models
Given I show the filter "color"
And I filter by "color" with operator "in list" and value "Navy blue"
And I select rows watch, tshirt-unique-size-navy-blue and model-tshirt-divided-navy-blue
And I press the "Bulk actions" button
And I choose the "Move between categories" operation
And I move on to the choose step
And I choose the "Move between categories" operation
And I select the "Master" tree
And I expand the "master" category
And I press the "Women" button
And I confirm mass edit
And I wait for the "update_product_value" job to finish
When I go on the last executed job resume of "update_product_value"
Then I should see the text "COMPLETED"
And I should see the text "processed 2"
And I should see the text "skipped 1"
And I should see the text "Bulk actions do not support Product models entities yet."
When I am on the products grid
And I open the category tree
Then I should be able to use the following filters:
| filter | operator | value | result |
| category | | master_women | watch, tshirt-unique-size-navy-blue |

Scenario: Mass edits remove categories of only products within a selection of products and product models
Given I show the filter "color"
And I filter by "color" with operator "in list" and value "Navy blue"
And I select rows watch, tshirt-unique-size-navy-blue and model-tshirt-divided-navy-blue
And I press the "Bulk actions" button
And I choose the "Remove from categories" operation
And I move on to the choose step
And I choose the "Remove from categories" operation
And I select the "Master" tree
And I expand the "master" category
And I expand the "master_men" category
And I press the "T-shirts" button
And I select the "Suppliers" tree
And I expand the "suppliers" category
And I press the "Zaro" button
And I confirm mass edit
And I wait for the "remove_product_value" job to finish
When I go on the last executed job resume of "remove_product_value"
Then I should see the text "COMPLETED"
And I should see the text "processed 2"
And I should see the text "skipped 1"
And I should see the text "Bulk actions do not support Product models entities yet."
And the product "watch" should not have any category
And the product "tshirt-unique-size-navy-blue" should not have any category
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@javascript
Feature: Export products and product models
In order to use the enriched product data
As a product manager
I need to be able to export the products and product models to several channels

Background:
Given a "catalog_modeling" catalog configuration
And I am logged in as "Julia"
And I am on the products page
And I show the filter "color"
And I filter by "color" with operator "in list" and value "Crimson red"

Scenario: Successfully export only products to multiple channels
And I select rows model-tshirt-divided-crimson-red, running-shoes-m-crimson-red and tshirt-unique-size-crimson-red
And I press "CSV (Grid context)" on the "Quick Export" dropdown button
And I wait for the "csv_product_grid_context_quick_export" quick export to finish
And I am on the dashboard page
When I go on the last executed job resume of "csv_product_grid_context_quick_export"
Then I should see the text "COMPLETED"
And I should see the text "skipped 1"
And the name of the exported file of "csv_product_grid_context_quick_export" should be "products_export_grid_context_en_US_ecommerce.csv"
And exported file of "csv_product_grid_context_quick_export" should contain:
"""
sku;enabled;family;groups;image
tshirt-unique-size-crimson-red;1;clothing;;
running-shoes-m-crimson-red;1;shoes;;
"""
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace Pim\Bundle\CatalogBundle\tests\integration\PQB;

use Akeneo\Component\StorageUtils\Cursor\CursorInterface;
use Akeneo\Test\Integration\Configuration;
use Akeneo\Test\Integration\TestCase;
use Pim\Component\Catalog\Model\ProductInterface;
use Pim\Bundle\DataGridBundle\Normalizer\IdEncoder;
use Pim\Component\Catalog\Query\Filter\Operators;
use Pim\Component\Catalog\Query\Sorter\Directions;

Expand Down Expand Up @@ -57,6 +54,71 @@ public function testNoFilterAndSortIdentifier()
);
}

public function testIdentifierFilter()
{
$pqb = $this->get('pim_enrich.query.product_and_product_model_query_builder_from_size_factory')->create(
[
'limit' => 19,
]
);

$pqb->addFilter(
'identifier',
Operators::IN_LIST,
['watch', 'model-tshirt-unique-size', 'tshirt-unique-size-crimson-red']
);

$result = $pqb->execute();

$this->assert(
$result,
[
'watch',
'model-tshirt-unique-size',
'tshirt-unique-size-crimson-red',
]
);
}

public function testIdFilter()
{
$productId = IdEncoder::encode(
IdEncoder::PRODUCT_TYPE,
$this->get('pim_catalog.repository.product')->findOneByIdentifier('watch')->getId()
);
$variantProductId = IdEncoder::encode(
IdEncoder::PRODUCT_TYPE,
$this->get('pim_catalog.repository.product')->findOneByIdentifier('tshirt-unique-size-crimson-red')->getId()
);
$productModelId = IdEncoder::encode(
IdEncoder::PRODUCT_MODEL_TYPE,
$this->get('pim_catalog.repository.product_model')->findOneByIdentifier('model-tshirt-unique-size')->getId()
);

$pqb = $this->get('pim_enrich.query.product_and_product_model_query_builder_from_size_factory')->create(
[
'limit' => 19,
]
);

$pqb->addFilter(
'id',
Operators::IN_LIST,
[$productId, $variantProductId, $productModelId]
);

$result = $pqb->execute();

$this->assert(
$result,
[
'watch',
'model-tshirt-unique-size',
'tshirt-unique-size-crimson-red',
]
);
}

public function testSearchTshirtInDescription()
{
$result = $this->executeFilter([['description', Operators::CONTAINS, 'Divided slim T-shirt with 2 buttons']]);
Expand Down
Loading

0 comments on commit 365bf39

Please sign in to comment.