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

[Association] Associated products #3165

Merged
merged 18 commits into from
Jan 29, 2016

Conversation

lchrusciel
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets
License MIT
Doc PR WIP

It is extended #2098 PR. @l3l0 has done awsome work so I only extracted it to separated bundle.
This PR was reviewed once, but feel free to point me out more problems ;)

Update

Important change

Due to extraction to different budnle the previous configuration does not apply any more.
Previous config:

sylius_product:
    product_association:
        classes:
            product: Sylius\Component\Product\Model\ProductAssociation
            myOwn: MyOwn\SomeAssociation\Model\MyOwnAssociation

After feedback it was decided to change a configuration to more dynamic. Current version is inspired by AttributesBundle configuration.
Now it has to be done in separated tree, where you have to precise a subject of association. The most basic config looks like that:

sylius_association:
    classes:
        product:
            subject: Sylius\Component\Core\Model\Product
            association:
                model: Sylius\Component\Product\Model\ProductAssociation

Because of assigning this PR to v0.16 milestone it was associated with @pamil #3110 PR

TODOs:

  • Write new behats
  • Adapt ProductAssociationContext to new test

Update

Since last time I have worked on this PR plenty things changed in Sylius core, so new dynamic configuration has to be adjusted to them. For now, new association configuration looks like this:

sylius_association:
    resources:
        product:
            subject: Sylius\Component\Core\Model\Product
            association:
                classes:
                    model: Sylius\Component\Product\Model\ProductAssociation

@pjedrzejewski pjedrzejewski added this to the v0.16.0 milestone Aug 20, 2015
public function thereAreFollowingAssociationTypes(TableNode $table)
{
foreach ($table->getHash() as $row) {
$associationType = new AssociationType();
Copy link
Member

Choose a reason for hiding this comment

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

We should use the factory method here.

@lchrusciel lchrusciel changed the title Associated products [AssociationBundle] Associated products Aug 20, 2015
->createQueryBuilder('p')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
Copy link
Contributor

Choose a reason for hiding this comment

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

Either setMaxResults(1) or getOneOrNullResult()

@lchrusciel lchrusciel changed the title [AssociationBundle] Associated products [Association] Associated products Aug 20, 2015
*/
class AssociationInheritanceMetadataSubscriber implements EventSubscriber
{
const ASSOCIATION_CLASS_NAME = 'Sylius\Component\Association\Model\Association';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
*/
interface AssociatableInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Associable without ta is correct! ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it is indeed associable.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@lchrusciel lchrusciel force-pushed the associated-products branch 3 times, most recently from dd9ce5e to 73f1cba Compare January 28, 2016 12:36
@@ -21,6 +21,10 @@ Feature: Products
| Black T-Shirt | 19.99 | T-Shirt size | T-Shirt fabric:Cotton |
| Mug | 5.99 | | |
| Sticker | 10.00 | | |
And there are following association types:
| name | code |
| Cross sell | PAs1 |
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we automatically generate the code as it doesn't have any specific role in the scenarios?

Copy link
Member Author

Choose a reason for hiding this comment

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

The convention in a file is to write them explicitly. I think that it will be better to be consistent.

@lchrusciel
Copy link
Member Author

All review comments were applied. Waiting for green and it is ready to be merged.

*/
private function createSubjectMapping($associationEntity, $subject, ClassMetadata $associationEntityMetadata)
{
$subjectMapping = ['fieldName' => 'owner', 'targetEntity' => $associationEntity, 'inversedBy' => 'associations', 'joinColumns' => [['name' => $subject . '_id', 'referencedColumnName' => $associationEntityMetadata->fieldMappings['id']['columnName'], 'nullable' => false, 'onDelete' => 'CASCADE',]],];
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be too long.

@lchrusciel lchrusciel force-pushed the associated-products branch 2 times, most recently from 4eb76b4 to 0b92f1a Compare January 28, 2016 13:42
pjedrzejewski pushed a commit that referenced this pull request Jan 29, 2016
@pjedrzejewski pjedrzejewski merged commit 0729b3a into Sylius:master Jan 29, 2016
@pjedrzejewski
Copy link
Member

Great work, thanks Łukasz and all reviewers! 👍 I will setup repositories later today. :)

@lchrusciel lchrusciel deleted the associated-products branch February 1, 2016 15:12
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

9 participants