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

Skip to content

Commit 9073bad

Browse files
committed
[API] Minor fixes according to filtering product variants by option values
1 parent 5c07c86 commit 9073bad

3 files changed

Lines changed: 60 additions & 40 deletions

File tree

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -187,34 +187,6 @@ public function iAddThisProductWithToTheCart(
187187
$this->cartsClient->executeCustomRequest($request);
188188
}
189189

190-
/**
191-
* @Given /^(this product) should have ([^"]+) "([^"]+)"$/
192-
*/
193-
public function thisItemShouldHaveOptionValue(ProductInterface $product, string $optionName, string $optionValue): void
194-
{
195-
$item = $this->sharedStorage->get('item');
196-
197-
$variantData = json_decode($this->cartsClient->showByIri(urldecode($item['variant']))->getContent(), true, 512, \JSON_THROW_ON_ERROR);
198-
199-
foreach ($variantData['optionValues'] as $valueIri) {
200-
$optionValueData = json_decode($this->cartsClient->showByIri($valueIri)->getContent(), true, 512, \JSON_THROW_ON_ERROR);
201-
202-
if ($optionValueData['value'] !== $optionValue) {
203-
continue;
204-
}
205-
206-
$optionData = json_decode($this->cartsClient->showByIri($optionValueData['option'])->getContent(), true, 512, \JSON_THROW_ON_ERROR);
207-
208-
if ($optionData['name'] !== $optionName) {
209-
continue;
210-
}
211-
212-
return;
213-
}
214-
215-
throw new \DomainException(sprintf('Could not find item with option "%s" set to "%s"', $optionName, $optionValue));
216-
}
217-
218190
/**
219191
* @When /^I change (product "[^"]+") quantity to (\d+) in my (cart)$/
220192
* @When /^the (?:visitor|customer) change (product "[^"]+") quantity to (\d+) in his (cart)$/
@@ -532,6 +504,34 @@ public function iShouldHaveEmptyCart(string $tokenValue): void
532504
Assert::same(count($items), 0, 'There should be an empty cart');
533505
}
534506

507+
/**
508+
* @Then /^(this product) should have ([^"]+) "([^"]+)"$/
509+
*/
510+
public function thisItemShouldHaveOptionValue(ProductInterface $product, string $optionName, string $optionValue): void
511+
{
512+
$item = $this->sharedStorage->get('item');
513+
514+
$variantData = json_decode($this->cartsClient->showByIri(urldecode($item['variant']))->getContent(), true, 512, \JSON_THROW_ON_ERROR);
515+
516+
foreach ($variantData['optionValues'] as $valueIri) {
517+
$optionValueData = json_decode($this->cartsClient->showByIri($valueIri)->getContent(), true, 512, \JSON_THROW_ON_ERROR);
518+
519+
if ($optionValueData['value'] !== $optionValue) {
520+
continue;
521+
}
522+
523+
$optionData = json_decode($this->cartsClient->showByIri($optionValueData['option'])->getContent(), true, 512, \JSON_THROW_ON_ERROR);
524+
525+
if ($optionData['name'] !== $optionName) {
526+
continue;
527+
}
528+
529+
return;
530+
}
531+
532+
throw new \DomainException(sprintf('Could not find item with option "%s" set to "%s"', $optionName, $optionValue));
533+
}
534+
535535
private function pickupCart(?string $localeCode = null): string
536536
{
537537
$this->cartsClient->buildCreateRequest();

src/Sylius/Bundle/ApiBundle/DataProvider/ChannelAwareItemDataProvider.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
declare(strict_types=1);
413

514
namespace Sylius\Bundle\ApiBundle\DataProvider;
@@ -12,14 +21,10 @@
1221
/** @experimental */
1322
final class ChannelAwareItemDataProvider implements ItemDataProviderInterface
1423
{
15-
/**
16-
* @var ItemDataProviderInterface
17-
*/
24+
/** @var ItemDataProviderInterface */
1825
private $itemDataProvider;
1926

20-
/**
21-
* @var ChannelContextInterface
22-
*/
27+
/** @var ChannelContextInterface */
2328
private $channelContext;
2429

2530
public function __construct(ItemDataProviderInterface $itemDataProvider, ChannelContextInterface $channelContext)

src/Sylius/Bundle/ApiBundle/Doctrine/Filter/ProductVariantOptionValueFilter.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
declare(strict_types=1);
413

514
namespace Sylius\Bundle\ApiBundle\Doctrine\Filter;
@@ -15,15 +24,20 @@
1524
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
1625
use Webmozart\Assert\Assert;
1726

27+
/** @experimental */
1828
final class ProductVariantOptionValueFilter extends AbstractContextAwareFilter
1929
{
20-
/**
21-
* @var IriConverterInterface
22-
*/
30+
/** @var IriConverterInterface */
2331
private IriConverterInterface $iriConverter;
2432

25-
public function __construct(IriConverterInterface $iriConverter, ManagerRegistry $managerRegistry, ?RequestStack $requestStack = null, LoggerInterface $logger = null, array $properties = null, NameConverterInterface $nameConverter = null)
26-
{
33+
public function __construct(
34+
IriConverterInterface $iriConverter,
35+
ManagerRegistry $managerRegistry,
36+
?RequestStack $requestStack = null,
37+
LoggerInterface $logger = null,
38+
array $properties = null,
39+
NameConverterInterface $nameConverter = null
40+
) {
2741
parent::__construct($managerRegistry, $requestStack, $logger, $properties, $nameConverter);
2842

2943
$this->iriConverter = $iriConverter;
@@ -49,7 +63,8 @@ protected function filterProperty(
4963
$parameterName = $queryNameGenerator->generateParameterName($property);
5064
$queryBuilder
5165
->andWhere(sprintf(':%s MEMBER OF o.optionValues', $parameterName))
52-
->setParameter($parameterName, $optionValue);
66+
->setParameter($parameterName, $optionValue)
67+
;
5368
}
5469
}
5570

0 commit comments

Comments
 (0)