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

Stop using getContext() methods for SalesChannelContext instances #1483

Closed
moorl opened this issue Nov 5, 2020 · 3 comments
Closed

Stop using getContext() methods for SalesChannelContext instances #1483

moorl opened this issue Nov 5, 2020 · 3 comments

Comments

@moorl
Copy link

moorl commented Nov 5, 2020

Description
In this example I have two similar events with different methods to get the SalesChannelContext. Its a problem and force us devs to duplicate similar code. Maybe the first step could be to add a equal method with the right name to get the SalesChannelContext.

Example

    public static function getSubscribedEvents(): array
    {
        return [
            ProductListingCollectFilterEvent::class => 'addFilter',
            ProductListingCriteriaEvent::class => 'addCriteria',
            ProductPageCriteriaEvent::class => 'addCriteria'
        ];
    }

    public function addCriteria($event)
    {
        if ($event instanceof ProductListingCriteriaEvent) {
            $salesChannelContext = $event->getSalesChannelContext();
        } elseif ($event instanceof ProductPageCriteriaEvent) {
            $salesChannelContext = $event->getContext();
        }

        $criteria = $event->getCriteria();
        //$criteria->addAssociation('merchantStocks.merchant');
        //$criteria->addAggregation(new EntityAggregation('merchants', 'product.merchantStocks.merchant.id', MerchantDefinition::ENTITY_NAME));

        $criteria->addAssociation('merchants');
        $criteria->addAggregation($this->getEntityAggregation());
        $criteria->addFilter(new MultiFilter(MultiFilter::CONNECTION_OR, [
            new EqualsFilter('merchants.salesChannelId', $salesChannelContext->getSalesChannel()->getId()),
            new EqualsFilter('merchants.salesChannelId', null)
        ]));
    }
@shopwareBot
Copy link

Hello,

thank you for creating this issue.
I have opened a ticket on our Issue Tracker for you. See the ticket link: https://issues.shopware.com/issues/NEXT-11926

Please use this ticket to track the state of your issue.

@mitelg
Copy link
Member

mitelg commented Nov 6, 2020

oh, that should not be the case. I will take care of that

shopwareBot pushed a commit to shopware/storefront that referenced this issue Nov 9, 2020
shopwareBot pushed a commit to shopware/core that referenced this issue Nov 9, 2020
@mitelg
Copy link
Member

mitelg commented Nov 10, 2020

hey @moorl

thanks again for bringing this up. yesterday we merged a new convention (ADR) on how events have to look like in the future: dacf9cf

the event you mentioned in the first place, will only be fixed with the upcoming major version 6.4.0.0 because changing the return type would be a breaking change. But from now on, there is already a getSalesChannelContext present, which will be usable from the next minor version 6.3.4.0

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

No branches or pull requests

3 participants