-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[API]Add inStock serialization to productVariant #12639
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Sylius/Behat/Resources/config/suites/api/inventory/cart_inventory.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This file is part of the Sylius package. | ||
# (c) Paweł Jędrzejewski | ||
|
||
default: | ||
suites: | ||
api_cart_inventory: | ||
contexts: | ||
- sylius.behat.context.hook.doctrine_orm | ||
|
||
- sylius.behat.context.setup.channel | ||
- sylius.behat.context.setup.product | ||
|
||
- sylius.behat.context.transform.lexical | ||
- sylius.behat.context.transform.product | ||
- sylius.behat.context.transform.shared_storage | ||
|
||
- sylius.behat.context.api.shop.cart | ||
- sylius.behat.context.api.shop.product | ||
|
||
arti0090 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
filters: | ||
tags: "@cart_inventory && @api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
|
||
use Sylius\Component\Channel\Context\ChannelContextInterface; | ||
use Sylius\Component\Channel\Context\ChannelNotFoundException; | ||
use Sylius\Component\Core\Calculator\ProductVariantPriceCalculatorInterface; | ||
use Sylius\Component\Core\Calculator\ProductVariantPricesCalculatorInterface; | ||
use Sylius\Component\Core\Model\ProductVariantInterface; | ||
use Sylius\Component\Inventory\Checker\AvailabilityCheckerInterface; | ||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
use Webmozart\Assert\Assert; | ||
|
@@ -17,20 +18,25 @@ final class ProductVariantSerializer implements ContextAwareNormalizerInterface | |
/** @var NormalizerInterface */ | ||
private $objectNormalizer; | ||
|
||
/** @var ProductVariantPriceCalculatorInterface */ | ||
/** @var ProductVariantPricesCalculatorInterface */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed this Interface, as It shows as deprecated. |
||
private $priceCalculator; | ||
|
||
/** @var ChannelContextInterface */ | ||
private $channelContext; | ||
|
||
/** @var AvailabilityCheckerInterface */ | ||
private $availabilityChecker; | ||
|
||
public function __construct( | ||
NormalizerInterface $objectNormalizer, | ||
ProductVariantPriceCalculatorInterface $priceCalculator, | ||
ChannelContextInterface $channelContext | ||
ProductVariantPricesCalculatorInterface $priceCalculator, | ||
ChannelContextInterface $channelContext, | ||
AvailabilityCheckerInterface $availabilityChecker | ||
) { | ||
$this->objectNormalizer = $objectNormalizer; | ||
$this->priceCalculator = $priceCalculator; | ||
$this->channelContext = $channelContext; | ||
$this->availabilityChecker = $availabilityChecker; | ||
} | ||
|
||
public function normalize($object, $format = null, array $context = []) | ||
|
@@ -45,15 +51,17 @@ public function normalize($object, $format = null, array $context = []) | |
unset($data['price']); | ||
} | ||
|
||
$data['inStock'] = $this->availabilityChecker->isStockAvailable($object); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it also shown in api reference in swagger? |
||
|
||
return $data; | ||
} | ||
|
||
public function supportsNormalization($data, $format = null, $context = []): bool | ||
{ | ||
return $data instanceof ProductVariantInterface && $this->isAdminGetOperation($context); | ||
return $data instanceof ProductVariantInterface && $this->isNotAdminGetOperation($context); | ||
} | ||
|
||
private function isAdminGetOperation(array $context): bool | ||
private function isNotAdminGetOperation(array $context): bool | ||
{ | ||
return !isset($context['item_operation_name']) || !($context['item_operation_name'] === 'admin_get'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you check here validation message instead status code?
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'd like to explain myself why I check status Code; the step is about 'unable to add it to the cart' and I dont think that this step cares why it happens (what validation message). This I think should be checked somewhere else, in add to cart validation behats 😃