Skip to content

Commit

Permalink
add new Section class and fix cart blaming
Browse files Browse the repository at this point in the history
  • Loading branch information
arti0090 committed Apr 12, 2021
1 parent 87e13c5 commit 6505132
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
namespace Sylius\Bundle\ApiBundle\EventListener;

use Doctrine\Persistence\ObjectManager;
use Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection;
use Sylius\Bundle\ApiBundle\SectionResolver\ShopApiOrdersSubSection;
use Sylius\Bundle\CoreBundle\SectionResolver\SectionProviderInterface;
use Sylius\Bundle\ShopBundle\SectionResolver\ShopSection;
use Sylius\Bundle\UserBundle\Event\UserEvent;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
Expand Down Expand Up @@ -48,7 +47,7 @@ public function __construct(

public function onImplicitLogin(UserEvent $userEvent): void
{
if (!$this->uriBasedSectionContext->getSection() instanceof ShopSection) {
if (!$this->uriBasedSectionContext->getSection() instanceof ShopApiOrdersSubSection) {
return;
}

Expand All @@ -63,7 +62,7 @@ public function onImplicitLogin(UserEvent $userEvent): void
public function onInteractiveLogin(InteractiveLoginEvent $interactiveLoginEvent): void
{
$section = $this->uriBasedSectionContext->getSection();
if (!$section instanceof ShopSection && !$section instanceof ShopApiSection) {
if (!$section instanceof ShopApiOrdersSubSection) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parameters:
sylius.security.new_api_shop_regex: "^%sylius.security.new_api_shop_route%"
sylius.security.new_api_user_account_route: "%sylius.security.new_api_shop_route%/account"
sylius.security.new_api_user_account_regex: "^%sylius.security.new_api_user_account_route%"
sylius.new_api_orders_resource_route: "orders"

api_platform:
patch_formats:
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Bundle/ApiBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@

<service id="sylius.api.section_resolver.shop_api_uri_based_section_resolver" class="Sylius\Bundle\ApiBundle\SectionResolver\ShopApiUriBasedSectionResolver">
<argument>%sylius.security.new_api_shop_route%</argument>
<argument>%sylius.new_api_orders_resource_route%</argument>
<tag name="sylius.uri_based_section_resolver" priority="40" />
</service>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\ApiBundle\SectionResolver;

class ShopApiOrdersSubSection extends ShopApiSection
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@ final class ShopApiUriBasedSectionResolver implements UriBasedSectionResolverInt
/** @var string */
private $shopApiUriBeginning;

public function __construct(string $shopApiUriBeginning)
/** @var string */
private $shopApiOrdersResourceUri;

public function __construct(string $shopApiUriBeginning, string $shopApiOrdersResourceUri)
{
$this->shopApiUriBeginning = $shopApiUriBeginning;
$this->shopApiOrdersResourceUri = $shopApiOrdersResourceUri;
}

public function getSection(string $uri): SectionInterface
{
if (0 === strpos($uri, $this->shopApiUriBeginning)) {
if (str_contains($uri, $this->shopApiOrdersResourceUri)) {
return new ShopApiOrdersSubSection();
}

return new ShopApiSection();
}

Expand Down

0 comments on commit 6505132

Please sign in to comment.