Created
August 13, 2021 13:59
-
-
Save dimonx3/009bf2b9ab66e071dc6724e1cb5a8ef9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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