Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a285b53

Browse files
committed
[Catalog Promotion] process checkout with always proper price
1 parent 62a0e7e commit a285b53

11 files changed

Lines changed: 94 additions & 25 deletions

File tree

features/cart/shopping_cart/seeing_current_prices_of_products_after_catalog_promotion_becomes_ineligible.feature

Lines changed: 0 additions & 25 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@checkout
2+
Feature: Seeing current prices of products after catalog promotion becomes ineligible
3+
In order to buy products in its correct prices
4+
As a Customer
5+
I want to have products with its current prices in the cart
6+
7+
Background:
8+
Given the store operates on a single channel in "United States"
9+
And the store has a product "T-Shirt"
10+
And this product has "PHP T-Shirt" variant priced at "$20.00" in "United States" channel
11+
And the store ships everywhere for free
12+
And the store allows paying offline
13+
And there is a catalog promotion "Winter sale" available in "United States" channel that reduces price by "25%" and applies on "PHP T-Shirt" variant
14+
And I am a logged in customer
15+
16+
@ui @api
17+
Scenario: Processing order with valid prices after catalog promotion becomes ineligibly
18+
Given I have "PHP T-Shirt" variant of this product in the cart
19+
When And the "Winter sale" catalog promotion is no longer available
20+
And I specified the billing address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
21+
And I proceed through checkout process
22+
Then I should be on the checkout summary step
23+
And I should see product "T-Shirt" with unit price "$20.00"

src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515

1616
use ApiPlatform\Core\Api\IriConverterInterface;
1717
use Behat\Behat\Context\Context;
18+
use Doctrine\Persistence\ObjectManager;
1819
use Sylius\Behat\Client\ApiClientInterface;
1920
use Sylius\Behat\Client\Request;
2021
use Sylius\Behat\Client\ResponseCheckerInterface;
2122
use Sylius\Behat\Service\SharedStorageInterface;
2223
use Sylius\Component\Addressing\Model\ProvinceInterface;
2324
use Sylius\Component\Core\Formatter\StringInflector;
2425
use Sylius\Component\Core\Model\AddressInterface;
26+
use Sylius\Component\Core\Model\CatalogPromotionInterface;
27+
use Sylius\Component\Core\Model\ChannelInterface;
2528
use Sylius\Component\Core\Model\CustomerInterface;
2629
use Sylius\Component\Core\Model\OrderInterface;
2730
use Sylius\Component\Core\Model\PaymentMethod;
@@ -1118,6 +1121,14 @@ public function iShouldBeNotifiedThatThisProductDoesNotHaveSufficientStock(Produ
11181121
));
11191122
}
11201123

1124+
/**
1125+
* @When /^I should see (product "[^"]+") with unit price ("[^"]+")$/
1126+
*/
1127+
public function iShouldSeeWithUnitPrice(ProductInterface $product, int $unitPrice): void
1128+
{
1129+
Assert::true($this->hasProductWithUnitPrice($product->getName(), $unitPrice));
1130+
}
1131+
11211132
private function assertProvinceMessage(string $addressType): void
11221133
{
11231134
$response = $this->ordersClient->getLastResponse();
@@ -1269,6 +1280,20 @@ private function hasProductWithNameAndQuantityInCart(string $productName, int $q
12691280
return false;
12701281
}
12711282

1283+
private function hasProductWithUnitPrice(string $productName, int $unitPrice): bool
1284+
{
1285+
/** @var array $items */
1286+
$items = $this->responseChecker->getValue($this->ordersClient->getLastResponse(), 'items');
1287+
1288+
foreach ($items as $item) {
1289+
if ($item['productName'] === $productName && $item['unitPrice'] === $unitPrice) {
1290+
return true;
1291+
}
1292+
}
1293+
1294+
return false;
1295+
}
1296+
12721297
private function fillAddress(string $addressType, AddressInterface $address): void
12731298
{
12741299
$this->content[$addressType]['city'] = $address->getCity() ?? '';

src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\ORM\EntityManagerInterface;
1818
use Sylius\Behat\Service\SharedStorageInterface;
1919
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
20+
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
2021
use Sylius\Component\Core\Formatter\StringInflector;
2122
use Sylius\Component\Core\Model\CatalogPromotionInterface;
2223
use Sylius\Component\Core\Model\CatalogPromotionRuleInterface;
@@ -35,19 +36,23 @@ final class CatalogPromotionContext implements Context
3536

3637
private EntityManagerInterface $entityManager;
3738

39+
private ChannelRepositoryInterface $channelRepository;
40+
3841
private SharedStorageInterface $sharedStorage;
3942

4043
public function __construct(
4144
ExampleFactoryInterface $catalogPromotionExampleFactory,
4245
FactoryInterface $catalogPromotionRuleFactory,
4346
FactoryInterface $catalogPromotionActionFactory,
4447
EntityManagerInterface $entityManager,
48+
ChannelRepositoryInterface $channelRepository,
4549
SharedStorageInterface $sharedStorage
4650
) {
4751
$this->catalogPromotionExampleFactory = $catalogPromotionExampleFactory;
4852
$this->catalogPromotionRuleFactory = $catalogPromotionRuleFactory;
4953
$this->catalogPromotionActionFactory = $catalogPromotionActionFactory;
5054
$this->entityManager = $entityManager;
55+
$this->channelRepository = $channelRepository;
5156
$this->sharedStorage = $sharedStorage;
5257
}
5358

@@ -172,6 +177,19 @@ public function thereIsACatalogPromotionAvailableInChannelThatReducesPriceByAndA
172177
$this->entityManager->flush();
173178
}
174179

180+
/**
181+
* @When And the :catalogPromotion catalog promotion is no longer available
182+
*/
183+
public function theAdministratorMakesThisCatalogPromotionUnavailableInTheChannel(
184+
CatalogPromotionInterface $catalogPromotion
185+
): void {
186+
foreach ($this->channelRepository->findAll() as $channel) {
187+
$catalogPromotion->removeChannel($channel);
188+
}
189+
$this->entityManager->persist($catalogPromotion);
190+
$this->entityManager->flush();
191+
}
192+
175193
private function createCatalogPromotion(
176194
string $name,
177195
?string $code = null,

src/Sylius/Behat/Context/Ui/Shop/CartContext.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
use Behat\Behat\Context\Context;
1717
use Behat\Mink\Exception\ElementNotFoundException;
18+
use Doctrine\Persistence\ObjectManager;
1819
use Sylius\Behat\NotificationType;
1920
use Sylius\Behat\Page\Shop\Cart\SummaryPageInterface;
2021
use Sylius\Behat\Page\Shop\Product\ShowPageInterface;
2122
use Sylius\Behat\Service\NotificationCheckerInterface;
2223
use Sylius\Behat\Service\SharedStorageInterface;
24+
use Sylius\Component\Core\Model\CatalogPromotionInterface;
25+
use Sylius\Component\Core\Model\ChannelInterface;
2326
use Sylius\Component\Product\Model\ProductInterface;
2427
use Sylius\Component\Product\Model\ProductOptionInterface;
2528
use Webmozart\Assert\Assert;

src/Sylius/Behat/Context/Ui/Shop/Checkout/CheckoutCompleteContext.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515

1616
use Behat\Behat\Context\Context;
1717
use Behat\Mink\Exception\ElementNotFoundException;
18+
use Doctrine\Persistence\ObjectManager;
1819
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;
1920
use Sylius\Behat\NotificationType;
2021
use Sylius\Behat\Page\Shop\Checkout\CompletePageInterface;
2122
use Sylius\Behat\Service\NotificationCheckerInterface;
2223
use Sylius\Behat\Service\SharedStorageInterface;
2324
use Sylius\Component\Core\Formatter\StringInflector;
25+
use Sylius\Component\Core\Model\CatalogPromotionInterface;
26+
use Sylius\Component\Core\Model\ChannelInterface;
2427
use Sylius\Component\Core\Model\PaymentMethodInterface;
2528
use Sylius\Component\Core\Model\ProductInterface;
2629
use Sylius\Component\Core\Model\ProductVariantInterface;
@@ -40,6 +43,7 @@ final class CheckoutCompleteContext implements Context
4043
/** @var NotificationCheckerInterface */
4144
private $notificationChecker;
4245

46+
4347
public function __construct(
4448
SharedStorageInterface $sharedStorage,
4549
CompletePageInterface $completePage,
@@ -380,4 +384,12 @@ public function iShouldNotBeAbleToProceedCheckoutCompleteStep(): void
380384

381385
throw new UnexpectedPageException('It should not be possible to complete checkout complete step.');
382386
}
387+
388+
/**
389+
* @When /^I should see (product "[^"]+") with unit price ("[^"]+")$/
390+
*/
391+
public function iShouldSeeWithUnitPrice(ProductInterface $product, int $unitPrice): void
392+
{
393+
Assert::same($this->completePage->getProductUnitPrice($product), $unitPrice);
394+
}
383395
}

src/Sylius/Behat/Page/Shop/Checkout/CompletePage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public function hasPaymentMethod(): bool
9292
return $this->hasElement('payment_method');
9393
}
9494

95+
public function getProductUnitPrice(ProductInterface $product): int
96+
{
97+
return $this->getPriceFromString($this->getElement('product_unit_price', ['%name%' => $product->getName()])->getText());
98+
}
99+
95100
public function hasProductDiscountedUnitPriceBy(ProductInterface $product, int $amount): bool
96101
{
97102
$priceWithoutDiscount = $this->getPriceFromString($this->getElement('product_old_price', ['%name%' => $product->getName()])->getText());

src/Sylius/Behat/Page/Shop/Checkout/CompletePageInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function getPaymentMethodName(): string;
3030

3131
public function hasPaymentMethod(): bool;
3232

33+
public function getProductUnitPrice(ProductInterface $product): int;
34+
3335
public function hasProductDiscountedUnitPriceBy(ProductInterface $product, int $amount): bool;
3436

3537
public function hasOrderTotal(int $total): bool;

src/Sylius/Behat/Resources/config/services/contexts/setup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
<argument type="service" id="sylius.factory.catalog_promotion_rule" />
299299
<argument type="service" id="sylius.factory.catalog_promotion_action" />
300300
<argument type="service" id="sylius.manager.catalog_promotion" />
301+
<argument type="service" id="sylius.repository.channel" />
301302
<argument type="service" id="sylius.behat.shared_storage" />
302303
</service>
303304
</services>

src/Sylius/Behat/Resources/config/suites/api/checkout/checkout.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ default:
2525
- sylius.behat.context.transform.tax_category
2626
- sylius.behat.context.transform.user
2727
- sylius.behat.context.transform.zone
28+
- Sylius\Behat\Context\Transform\CatalogPromotionContext
2829

2930
- sylius.behat.context.setup.address
3031
- sylius.behat.context.setup.admin_user
@@ -44,6 +45,7 @@ default:
4445
- sylius.behat.context.setup.taxation
4546
- sylius.behat.context.setup.user
4647
- sylius.behat.context.setup.zone
48+
- Sylius\Behat\Context\Setup\CatalogPromotionContext
4749

4850
- sylius.behat.context.api.shop.cart
4951
- sylius.behat.context.api.shop.channel

0 commit comments

Comments
 (0)