Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

I want to be informed about every item being out of stock #17

Conversation

bartoszpietrzak1994
Copy link
Contributor

    Scenario: Reordering previously placed order when one of items is out of stock
        Given the product "Angel T-Shirt" is out of stock
        When I browse my orders
        And I click reorder button next to the order "#00000666"
        Then I should be on my cart summary page
        And I should be notified that product "Angel T-Shirt" is out of stock
        And I should be notified that previous order total was "$59.00"
        And I should see exactly 2 notifications

    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
        When I browse my orders
        And I click reorder button next to the order "#00000666"
        Then I should be on my cart summary page
        And I should be notified that products "Angel T-Shirt", "Awesome Mug" are out of stock
        And I should be notified that previous order total was "$59.00"
        And I should see exactly 2 notifications

Scenarios fulfilled

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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

@@ -75,6 +76,13 @@ private function copyOrderItemsToReorder(OrderInterface $order, OrderInterface $

/** @var OrderItemInterface $orderItem */
foreach ($orderItems as $orderItem) {

Copy link
Member

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);
Copy link
Member

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
*/
Copy link
Member

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.

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.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong order of keys

@bartoszpietrzak1994 bartoszpietrzak1994 force-pushed the i-want-to-be-informed-about-every-item-being-out-of-stock branch from 535bce6 to ac1131a Compare June 12, 2018 11:54
@@ -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())) {
Copy link
Member

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())

@bartoszpietrzak1994 bartoszpietrzak1994 force-pushed the i-want-to-be-informed-about-every-item-being-out-of-stock branch 2 times, most recently from 98331f7 to 0c0c3e2 Compare June 12, 2018 12:20
@bartoszpietrzak1994 bartoszpietrzak1994 force-pushed the i-want-to-be-informed-about-every-item-being-out-of-stock branch from 0c0c3e2 to eef1d4d Compare June 12, 2018 12:29
'message' => 'sylius.reorder.items_out_of_stock',
'parameters' => [
'%order_items%' => $this->reorderEligibilityConstraintMessageFormatter->format($variantsOutOfStock),
]
Copy link
Member

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());
Copy link
Member

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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!isset($variantName, $reorderVariantNamesToTotal)

Copy link
Contributor Author

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
Copy link
Member

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:

  1. Class EligibilityCheckerResult which contains some message what has gone wrong (and maybe a status? success/failure?)
  2. Each checkers returns array/collection of EligibilityCheckerResults
  3. Composite checker merges all responses into returns them to the controller
  4. 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 ReorderEligibilityCheckerResponseProcessors 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(
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

@GSadee GSadee merged commit 86313fe into Sylius:master Jun 19, 2018
@GSadee
Copy link
Member

GSadee commented Jun 19, 2018

Thanks Bartek 🤘

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants