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

Skip to content

[API] show product price#12279

Merged
AdamKasp merged 2 commits into
Sylius:masterfrom
SirDomin:api-product-price
Jan 28, 2021
Merged

[API] show product price#12279
AdamKasp merged 2 commits into
Sylius:masterfrom
SirDomin:api-product-price

Conversation

@SirDomin
Copy link
Copy Markdown
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets
License MIT

@SirDomin SirDomin added the API APIs related issues and PRs. label Jan 26, 2021
@SirDomin SirDomin requested a review from a team as a code owner January 26, 2021 13:43
Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
private function hasProductWithPrice(array $resource, int $price, ?string $productCode = null): bool
{
foreach ($resource as $product) {
if ($productCode && $product['code'] !== $productCode) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any case that $productCode may not exist? Just asking @SirDomin ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if you are checking collection, you should specify product code to check wanted product from the list. Otherwise we get only one product, so we dont need to search for it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$productCode should have explicit compare to null (to skip casting). Also $productCode check seems to always return false (if product code is equal to null, we will always return false), therefore we can extract this check before the foreach loop. Or even better remove nullable from this value

Comment thread src/Sylius/Behat/Resources/config/suites/api/product/viewing_products.yml Outdated
Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
private function hasProductWithPrice(array $resource, int $price, ?string $productCode = null): bool
{
foreach ($resource as $product) {
if ($productCode && $product['code'] !== $productCode) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$productCode should have explicit compare to null (to skip casting). Also $productCode check seems to always return false (if product code is equal to null, we will always return false), therefore we can extract this check before the foreach loop. Or even better remove nullable from this value

Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
@SirDomin SirDomin force-pushed the api-product-price branch 2 times, most recently from fac71d2 to e85ddfb Compare January 26, 2021 15:08
Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
@SirDomin SirDomin force-pushed the api-product-price branch 5 times, most recently from 276fb1d to 1f86004 Compare January 27, 2021 09:51
Comment thread src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/ChannelPricing.xml Outdated
Comment thread composer.json Outdated
Comment thread src/Sylius/Behat/Context/Api/Shop/ProductContext.php Outdated
Copy link
Copy Markdown
Contributor

@lchrusciel lchrusciel left a comment

Choose a reason for hiding this comment

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

Can we also try to reduce the amount of returned data to the current channel only?

Comment thread src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/ChannelPricing.xml Outdated
@AdamKasp AdamKasp merged commit b1508e4 into Sylius:master Jan 28, 2021
@AdamKasp
Copy link
Copy Markdown
Contributor

Thanks, @SirDomin! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API APIs related issues and PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants