Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add category to product CQRS command #14800

Merged

Conversation

@matthieu-rolland
Copy link
Contributor

commented Jul 22, 2019

Questions Answers
Branch? develop
Description? Add and use CQRS command to add a category to a product.
Type? refacto
Category? BO
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #13097
How to test? Try adding a category in BO > product > edit

This change is Reviewable

@matthieu-rolland matthieu-rolland requested a review from PrestaShop/prestashop-core-developers as a code owner Jul 22, 2019

@matthieu-rolland matthieu-rolland force-pushed the matthieu-rolland:improve-command-bus branch 2 times, most recently from 69f1f14 to 3998bf0 Jul 22, 2019

@matks
Copy link
Contributor

left a comment

A few minor changes 😉 but the main logic is here ! Great !

use PrestaShop\PrestaShop\Core\Domain\Product\Command\AddCategoryToProductCommand;
/**
* Interface AddCategoryHandlerInterface.

This comment has been minimized.

Copy link
@matks

matks Jul 22, 2019

Contributor

Either remove this comment or enhance it: here it does not bring value 😉

This comment has been minimized.

Copy link
@matthieu-rolland

matthieu-rolland Jul 23, 2019

Author Contributor

yep, done

namespace PrestaShop\PrestaShop\Core\Domain\Product\Exception;
/**
* Class ProductConstraintException.

This comment has been minimized.

Copy link
@matks

matks Jul 22, 2019

Contributor

Either remove this comment or enhance it: here it does not bring value 😉

This comment has been minimized.

Copy link
@matthieu-rolland

matthieu-rolland Jul 23, 2019

Author Contributor

yep, done !

$product = $productAdapter->getProduct($request->query->get('id_product'));
$product->addToCategories($categoryId->getValue());
$product->save();
$addCategoryToProductCommand = new AddCategoryToProductCommand(

This comment has been minimized.

Copy link
@matks

matks Jul 22, 2019

Contributor

AddCategoryToProductCommand throws CannotAddCategoryToProductException that extends ProductException so the catch below will not be able to catch it.

Can you also catch this Exception and provide a nice displayable error message for it ? See for example
https://github.com/PrestaShop/PrestaShop/blob/develop/src/PrestaShopBundle/Controller/Admin/Sell/Customer/CustomerController.php#L154

This comment has been minimized.

Copy link
@matthieu-rolland

matthieu-rolland Jul 23, 2019

Author Contributor

Done, I now return the correct error message, returned in the json.

@matthieu-rolland matthieu-rolland force-pushed the matthieu-rolland:improve-command-bus branch 3 times, most recently from 8be6785 to 1886e99 Jul 22, 2019

/**
* @param $command
*
* @throws CannotAddCategoryToProductException

This comment has been minimized.

Copy link
@PierreRambaud

PierreRambaud Jul 23, 2019

Contributor

No throws in this function

This comment has been minimized.

Copy link
@PierreRambaud

PierreRambaud Jul 23, 2019

Contributor

Or add a comment meaning what's has been done to receive this Exception 🤔

This comment has been minimized.

Copy link
@matthieu-rolland

matthieu-rolland Jul 23, 2019

Author Contributor

indeed, I removed the @throws annotation

@matthieu-rolland matthieu-rolland force-pushed the matthieu-rolland:improve-command-bus branch 3 times, most recently from 9bd783e to 34aa875 Jul 23, 2019

Add category to product CQRS command
- add category to product CQRS command
- use the command in categoryController

@matthieu-rolland matthieu-rolland force-pushed the matthieu-rolland:improve-command-bus branch from 34aa875 to 11e9f5b Jul 30, 2019

@matthieu-rolland matthieu-rolland force-pushed the matthieu-rolland:improve-command-bus branch from 469d68f to 21c3d02 Jul 30, 2019

@sarahdib sarahdib added QA ✔️ and removed waiting for QA labels Jul 31, 2019

@sarahdib sarahdib added this to the 1.7.7.0 milestone Jul 31, 2019

@PierreRambaud PierreRambaud merged commit 66cd74f into PrestaShop:develop Jul 31, 2019

2 checks passed

PrettyCI Code formatting
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@PierreRambaud

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.