Skip to content

Commit

Permalink
Add check to GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Oct 21, 2024
1 parent 952a3ec commit 1b02b36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Fruitcake\B2BEssentials\Helper;

use Magento\Customer\Model\Session;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\Http\Context as HttpContext;
Expand All @@ -16,13 +17,18 @@ class Data extends AbstractHelper
/** @var HttpContext */
private $httpContext;

/** @var Session */
private $customerSession;

public function __construct(
Context $context,
HttpContext $httpContext
HttpContext $httpContext,
Session $customerSession
) {
parent::__construct($context);

$this->httpContext = $httpContext;
$this->customerSession = $customerSession;
}

/**
Expand All @@ -37,6 +43,6 @@ public function getConfig($code = '')

public function isLoggedIn()
{
return $this->httpContext->getValue(CustomerContext::CONTEXT_AUTH);
return $this->httpContext->getValue(CustomerContext::CONTEXT_AUTH) || $this->customerSession->isLoggedIn();
}
}
13 changes: 13 additions & 0 deletions etc/graphql/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_quote_product_add_after">
<observer name="fruitcake_b2b_essentials_disable_addtocart" instance="Fruitcake\B2BEssentials\Observer\QuoteProductObserver"/>
</event>
<event name="catalog_product_load_after">
<observer name="fruitcake_b2b_essentials_product_after" instance="Fruitcake\B2BEssentials\Observer\ProductObserver" />
</event>
<event name="catalog_product_collection_load_after">
<observer name="fruitcake_b2b_essentials_product_collection_after" instance="Fruitcake\B2BEssentials\Observer\ProductCollectionObserver" />
</event>

</config>

0 comments on commit 1b02b36

Please sign in to comment.