-
Notifications
You must be signed in to change notification settings - Fork 25
I want to be informed about every item being out of stock #17
I want to be informed about every item being out of stock #17
Conversation
Given the store operates on a single channel in the "United States" named "Web" | ||
And the store has a product "Angel T-Shirt" priced at "$39.00" | ||
And there are 25 units of product "Angel T-Shirt" available in the inventory | ||
And this product is tracked by the inventory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that there is no need for this step, because the product is set as tracked in the previous step
@ui | ||
Scenario: Reordering previously placed order when several items are out of stock | ||
Given the product "Angel T-Shirt" is out of stock | ||
Given the product "Awesome Mug" is out of stock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And
@@ -25,38 +27,15 @@ Feature: Reordering previously placed order | |||
Then I should be on my cart summary page | |||
And I should see "Angel T-Shirt" with quantity 1 in my cart | |||
And my cart total should be "$19.00" | |||
And I should see exactly 0 notifications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I should not see any notifications
or sth similar?
|
||
final class ItemsOutOfStockEligibilityCheckerSpec extends ObjectBehavior | ||
{ | ||
function let(ReorderEligibilityConstraintMessageFormatterInterface $reorderEligibilityConstraintMessageFormatter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return types here and in other functions of this class
src/Factory/OrderFactory.php
Outdated
@@ -75,6 +76,13 @@ private function copyOrderItemsToReorder(OrderInterface $order, OrderInterface $ | |||
|
|||
/** @var OrderItemInterface $orderItem */ | |||
foreach ($orderItems as $orderItem) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary blank line
* @param OrderInterface $reorder | ||
* @return mixed | ||
*/ | ||
public function check(OrderInterface $order, OrderInterface $reorder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return type
* @param OrderInterface $order | ||
* @param OrderInterface $reorder | ||
* @return mixed | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary docblock
$message = ''; | ||
|
||
if (count($messageParameters) === 1) { | ||
$message = array_pop($messageParameters); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
promotion_not_enabled: 'Some promotions are no longer enabled. It may have affected order total.' | ||
items_price_changed: 'Prices of products: %product_names% have changed, which have affected order total.' | ||
promotion_not_enabled: 'Following promotions: %promotion_names% are no longer enabled, which have affected order total.' | ||
items_out_of_stock: 'Following items: %order_items% are out of stock. It may have affected order total.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong order of keys
535bce6
to
ac1131a
Compare
src/Factory/OrderFactory.php
Outdated
@@ -75,6 +76,12 @@ private function copyOrderItemsToReorder(OrderInterface $order, OrderInterface $ | |||
|
|||
/** @var OrderItemInterface $orderItem */ | |||
foreach ($orderItems as $orderItem) { | |||
/** @var ProductVariantInterface $productVariant */ | |||
$productVariant = $orderItem->getVariant(); | |||
if (!($productVariant->isTracked() && $productVariant->isInStock())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this if should look like: if ($productVariant->isTracked() && !$productVariant->isInStock())
98331f7
to
0c0c3e2
Compare
0c0c3e2
to
eef1d4d
Compare
'message' => 'sylius.reorder.items_out_of_stock', | ||
'parameters' => [ | ||
'%order_items%' => $this->reorderEligibilityConstraintMessageFormatter->format($variantsOutOfStock), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering does ReorderEligibilityChecker should return a serialized flash message... It's against SRP principle for me. What I would expect from such a service is returning boolean flag or event better - throwing an exception if something is wrong. Then these exceptions can be caught where the main checker is used and passed to some "notifier" that would create a flash message basing on an exception.
/** @var ProductVariantInterface $productVariant */ | ||
$productVariant = $orderItem->getVariant(); | ||
if ($productVariant->isTracked() && !$productVariant->isInStock()) { | ||
array_push($variantsOutOfStock, $orderItem->getVariantName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preferred way to add something to an array is $variantsOutOfStock[] = $orderItem->getVariantName()
$orderVariantsWithChangedPrice = []; | ||
|
||
foreach (array_keys($orderVariantNamesToTotal) as $variantName) { | ||
if (!array_key_exists($variantName, $reorderVariantNamesToTotal)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!isset($variantName, $reorderVariantNamesToTotal)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to check if the key exists in the array, not if the value for given key is set.
|
||
namespace Sylius\CustomerReorderPlugin\ReorderEligibility; | ||
|
||
class ReorderEligibilityCheckerResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we've misunderstood about this class a little bit. What I was thinking about was:
- Class
EligibilityCheckerResult
which contains some message what has gone wrong (and maybe a status? success/failure?) - Each checkers returns array/collection of
EligibilityCheckerResult
s - Composite checker merges all responses into returns them to the controller
- We need one more service that would convert each result into the flash message
And that's all. I didn't dig deep into these ReorderEligibilityCheckerResponseProcessor
s but I think they're just not needed. I think we should discuss it in live conversation.
$this->reorder($order, $channel); | ||
} | ||
|
||
function it_checks_if_price_of_any_item_has_changed( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to keep the order of parameters from let
method here and in other method in spec files
@@ -51,7 +52,8 @@ function it_returns_empty_array_when_prices_are_the_same( | |||
$secondOrderItem->getVariantName()->willReturn('test_variant_name_02'); | |||
$secondOrderItem->getUnitPrice()->willReturn(100); | |||
|
|||
$this->check($order, $reorder)->shouldReturn([]); | |||
$response = $this->check($order, $reorder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change it?
'parameters' => [ | ||
'%product_names%' => 'test_variant_name_01, test_variant_name_02' | ||
] | ||
$response = $this->check($order, $reorder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
Thanks Bartek 🤘 |
Scenarios fulfilled