diff --git a/Block/Adminhtml/System/Authenticate.php b/Block/Adminhtml/System/Authenticate.php index c03128b..22ab68e 100644 --- a/Block/Adminhtml/System/Authenticate.php +++ b/Block/Adminhtml/System/Authenticate.php @@ -7,18 +7,13 @@ use Macopedia\Allegro\Model\Api\TokenProvider; use Magento\Backend\Block\Template\Context; use Magento\Config\Block\System\Config\Form\Field; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Data\Form\Element\AbstractElement; -use Magento\Framework\Exception\LocalizedException; /** * Class responsible for authentication with Allegro API */ class Authenticate extends Field { - /** @var ScopeConfigInterface */ - private $scopeConfig; - /** @var TokenProvider */ private $tokenProvider; @@ -27,19 +22,16 @@ class Authenticate extends Field /** * @param Context $context - * @param ScopeConfigInterface $scopeConfig * @param TokenProvider $tokenProvider * @param Auth $auth * @param array $data */ public function __construct( Context $context, - ScopeConfigInterface $scopeConfig, TokenProvider $tokenProvider, Auth $auth, array $data = [] ) { - $this->scopeConfig = $scopeConfig; $this->tokenProvider = $tokenProvider; $this->auth = $auth; parent::__construct($context, $data); diff --git a/Console/Command/CleanOffersMapping.php b/Console/Command/CleanOffersMapping.php index 160c317..b4da5f8 100644 --- a/Console/Command/CleanOffersMapping.php +++ b/Console/Command/CleanOffersMapping.php @@ -4,7 +4,6 @@ namespace Macopedia\Allegro\Console\Command; -use Macopedia\Allegro\Model\Api\ClientException; use Macopedia\Allegro\Model\OffersMapping; use Magento\Framework\App\Area; use Magento\Framework\App\State; @@ -52,7 +51,7 @@ protected function configure() /** * @param InputInterface $input * @param OutputInterface $output - * @return int|void + * @return void * @throws LocalizedException */ protected function execute(InputInterface $input, OutputInterface $output) @@ -65,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $this->offersMapping->clean(); - } catch (ClientException $e) { + } catch (\Exception $e) { $output->writeln('Error occurred while trying to clean old offers mapping'); $output->writeln($e->getMessage()); } diff --git a/Cron/CleanOffersMapping.php b/Cron/CleanOffersMapping.php index e38b241..69934cc 100644 --- a/Cron/CleanOffersMapping.php +++ b/Cron/CleanOffersMapping.php @@ -5,7 +5,6 @@ namespace Macopedia\Allegro\Cron; use Macopedia\Allegro\Logger\Logger; -use Macopedia\Allegro\Model\Api\ClientException; use Magento\Framework\App\Config\ScopeConfigInterface; use Macopedia\Allegro\Model\OffersMapping; @@ -43,7 +42,7 @@ public function execute() $this->logger->addInfo("Cronjob clean offers mapping is executed."); try { $this->offersMapping->clean(); - } catch (ClientException $e) { + } catch (\Exception $e) { $this->logger->error('Error while trying to clean old offers mapping: ' . $e->getMessage()); } } diff --git a/Model/Api/Credentials.php b/Model/Api/Credentials.php index c9a4aa9..e2f422b 100644 --- a/Model/Api/Credentials.php +++ b/Model/Api/Credentials.php @@ -6,6 +6,7 @@ use Macopedia\Allegro\Model\Api\Auth\Data\TokenSerializer; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\FlagManager; /** @@ -110,10 +111,9 @@ public function getToken() if (!$tokenString) { throw new ClientException(__('Allegro account is not connected. Connect to Allegro account and try again')); } - try { return $this->tokenSerializer->decode($tokenString); - } catch (TokenSerializer\TokenSerializerException $e) { + } catch (Auth\Data\TokenSerializerException $e) { throw new ClientException(__('Something went wrong while decoding Allegro Api token')); } } diff --git a/Model/Api/TokenProvider.php b/Model/Api/TokenProvider.php index 2fd7c32..c106491 100644 --- a/Model/Api/TokenProvider.php +++ b/Model/Api/TokenProvider.php @@ -3,7 +3,6 @@ namespace Macopedia\Allegro\Model\Api; use Macopedia\Allegro\Api\Data\TokenInterface; -use Macopedia\Allegro\Logger\Logger; /** * Class to get current access token received from Allegro API @@ -16,22 +15,16 @@ class TokenProvider /** @var Credentials */ private $credentials; - /** @var Logger */ - private $logger; - /** * @param Auth $auth * @param Credentials $credentials - * @param Logger $logger */ public function __construct( Auth $auth, - Credentials $credentials, - Logger $logger + Credentials $credentials ) { $this->auth = $auth; $this->credentials = $credentials; - $this->logger = $logger; } /** diff --git a/Model/OffersMapping.php b/Model/OffersMapping.php index 0d7fa79..192c98e 100644 --- a/Model/OffersMapping.php +++ b/Model/OffersMapping.php @@ -5,6 +5,7 @@ namespace Macopedia\Allegro\Model; use Macopedia\Allegro\Logger\Logger; +use Macopedia\Allegro\Model\Api\TokenProvider; use Macopedia\Allegro\Model\ResourceModel\Sale\Offers; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; @@ -22,30 +23,39 @@ class OffersMapping /** @var CollectionFactory */ protected $productCollection; + /** @var TokenProvider */ + protected $tokenProvider; + /** * OffersMapping constructor. * @param Offers $offers * @param Logger $logger * @param Configuration $configuration * @param CollectionFactory $productCollection + * @param TokenProvider $tokenProvider */ public function __construct( Offers $offers, Logger $logger, Configuration $configuration, - CollectionFactory $productCollection + CollectionFactory $productCollection, + TokenProvider $tokenProvider ) { $this->offers = $offers; $this->logger = $logger; $this->configuration = $configuration; $this->productCollection = $productCollection; + $this->tokenProvider = $tokenProvider; } /** - * @throws Api\ClientException + * @throws \Exception */ public function clean() { + //Check connection with Allegro + $this->tokenProvider->getCurrent(); + $collection = $this->productCollection->create(); $collection->addAttributeToSelect('*') ->addStoreFilter($this->configuration->getStoreId()) diff --git a/README.md b/README.md index 767426c..cfd276b 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,8 @@ Oferta wystawiana jest ze zdjęciami pobranymi z produktu. Po uzupełnieniu wszystkich pół i kliknięciu "Zapisz" - zostanie wystawiony szkic oferty na Allegro i zostaniemy przekierowani na stronę edycji oferty. Teraz wystarczy kliknąć "Opublikuj", aby oferta stała się aktywna. W każdej chwili możemy edytować ofertę, zakończyć ją, a potem następnie aktywować. Produkt jest już teraz powiązany z ofertą na Allegro. ![publish_offer](README/publishButton.png) +W konfiguracji jest opcja włączenia zadania cron, które będzie usuwać z produktu ID oferty, która już nie istnieje na Allegro (Sklepy->Konfiguracja->Allegro->Konfiguracja->Import zamówień->Cron do czyszczenia starych rezerwacji jest włączony). + ## DEBUG MODE Wtyczka oferuje możliwość logowania wszystkich danych przesyłanych do i z API Allegro. Włączyć ją można na stronie konfiguracji (sklepy->Konfiguracja->Allegro->Konfiguracja->Debug mode) ![debug_mode](README/allegroDebugMode.png) diff --git a/README/allegroOrderImporterConfiguration.png b/README/allegroOrderImporterConfiguration.png index 3410843..fc6a91c 100644 Binary files a/README/allegroOrderImporterConfiguration.png and b/README/allegroOrderImporterConfiguration.png differ