Skip to content
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

[Admin][Product] Sort products within taxon #6612

Merged
merged 21 commits into from
Nov 22, 2016

Conversation

tuka217
Copy link
Contributor

@tuka217 tuka217 commented Nov 2, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? yes
Related tickets -
License MIT

@tuka217 tuka217 changed the title [Admin][Product] Sort products within taxon [WIP][Admin][Product] Sort products within taxon Nov 2, 2016
@@ -0,0 +1,113 @@
@managing_products
Feature: Adding a new product
Copy link
Member

Choose a reason for hiding this comment

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

This feature title and body do not describe well enough what we are checking here.

Feature: Adding a new product with a position within a taxon
In order to organize products within taxons in my shop
As an Administrator
I want to assign positions in taxons to products when I create them

I would suggest sth like that.

And I add it
Then I should be notified that it has been successfully created
And the product "Old Pug" should appear in the shop
And its position should be 0 in taxon "Soft Toys"
Copy link
Member

Choose a reason for hiding this comment

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

its position should be 0 in the "Soft Toys" taxon

When I specify its code as "OLD_PUG"
And I name it "Old Pug" in "English (United States)"
And I set its price to "$10.00"
And I assign its to "Soft Toys" taxon
Copy link
Member

Choose a reason for hiding this comment

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

I assign it to the "Soft Toys" taxon

And its position should be 2 in taxon "Soft Toys"

@todo
Scenario: Adding a new simple product in many taxons with different positions
Copy link
Member

Choose a reason for hiding this comment

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

Adding a new simple product with different positions in many taxons

Scenario: Adding a new simple product without position
And the store has a product "Young pug"
And this product belongs to "Soft Toys"
And this product is at position 1 at this taxon
Copy link
Member

Choose a reason for hiding this comment

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

this product is at position 1 in this taxon

And the last product on the list should have name "Small Pug"

@todo
Scenario: Shipping method added at no position is added as the last one
Copy link
Member

Choose a reason for hiding this comment

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

A shipping method added without position is added as the last one

@tuka217 tuka217 force-pushed the sort-products-in-taxon branch 13 times, most recently from b38ddfc to 36d9593 Compare November 14, 2016 09:28
@tuka217 tuka217 force-pushed the sort-products-in-taxon branch 6 times, most recently from 3eafcb9 to e113928 Compare November 16, 2016 10:53
@tuka217 tuka217 changed the title [WIP][Admin][Product] Sort products within taxon [Admin][Product] Sort products within taxon Nov 16, 2016
@tuka217 tuka217 force-pushed the sort-products-in-taxon branch 7 times, most recently from 7b99692 to b33fec4 Compare November 18, 2016 10:59
@michalmarcinkowski
Copy link
Contributor

Travis was stalled, so I needed to trigger the hook once again.

@pjedrzejewski pjedrzejewski merged commit 645752c into Sylius:master Nov 22, 2016
@pjedrzejewski
Copy link
Member

Thank you Ania, nice work! :)

@tchapi
Copy link
Contributor

tchapi commented Nov 22, 2016

How do we find if a product has a taxon if we only know the slug of the taxon now ?

Suppose I have a filtered /products/{taxonSlug} route, and in my controller :

[...]
$taxon = $this->get('sylius.repository.taxon')->findOneBySlug($taxonSlug);

// Do I need to iterate over each productTaxon of each product ??
foreach ($products as $product) {
  foreach($product->getProductTaxons() as $productTaxon) {
    if ($productTaxon()->getTaxon() == $taxon) {
       // filter or do whatever
    }
  }
}

This seems a bit overkill, no ? Did I miss something ?

@michalmarcinkowski
Copy link
Contributor

michalmarcinkowski commented Nov 22, 2016

How about something like:
$this->get('sylius.repository.product')->findByTaxonSlug($taxonSlug);

return $this->createQueryBuilder('o')
            ->innerJoin('o.product_taxons', 'product_taxon')
            ->innerJoin('product_taxon.taxon', 'taxon')
            ->andWhere('product_taxon.taxon.slug = :slug')
            ->setParameter('slug', $taxonSlug)
            ->getQuery()
            ->getResult()
        ;

@michalmarcinkowski
Copy link
Contributor

michalmarcinkowski commented Nov 22, 2016

Anyway the previous implementation would look almost exactly the same as yours now:

foreach ($products as $product) {
  foreach($product->getTaxons() as $productTaxon) {
    if ($productTaxon == $taxon) {
       // filter or do whatever
    }
  }
}

@tchapi
Copy link
Contributor

tchapi commented Nov 22, 2016

The for loop looks the same but doctrine hydrates thing differentely between the two, and performance can get tricky. I'll go with the Repository method I guess

pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
[Admin][Product] Sort products within taxon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants