Skip to content

Instantly share code, notes, and snippets.

@dimonx3
Created August 13, 2021 13:59
Show Gist options
  • Save dimonx3/009bf2b9ab66e071dc6724e1cb5a8ef9 to your computer and use it in GitHub Desktop.
Save dimonx3/009bf2b9ab66e071dc6724e1cb5a8ef9 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\Service;
use App\Entity;
use CodeCloud\Bundle\ShopifyBundle\Model\ShopifyStoreManagerInterface;
use Doctrine\Common\Persistence\ManagerRegistry;
/**
* Class ShopifyStoreManager
* @package App\Service
*/
class ShopifyStoreManager implements ShopifyStoreManagerInterface
{
/**
* @var ManagerRegistry
*/
private $doctrine;
/**
* ShopifyStoreManager constructor.
*
* @param ManagerRegistry $doctrine
*/
public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}
/**
* @param string $storeName
*
* @return Entity\ShopifyStore|null
*/
public function findStoreByName(string $storeName = null): ?Entity\ShopifyStore
{
return $this->doctrine->getRepository(Entity\ShopifyStore::class)->findOneBy(['storeName' => $storeName]);
}
public function getAccessToken($storeName): string
{
return $this->findStoreByName($storeName)->getAccessToken();
}
public function storeExists($storeName): bool
{
return (bool)$this->findStoreByName($storeName);
}
public function preAuthenticateStore($storeName, $nonce) {}
public function authenticateStore($storeName, $accessToken, $nonce)
{
$em = $this->doctrine->getManager();
$store = $this->findStoreByName($storeName) ?: new Entity\ShopifyStore();
$store
->setStoreName($storeName)
->setAccessToken($accessToken)
->setUninstall(false);
if (!$em->contains($store)) {
$em->persist($store);
}
$em->flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment