├── Divante └── VsBridge │ ├── Api │ └── Vue │ │ └── Webhook │ │ └── Catalog │ │ └── ProductWebhookInterface.php │ ├── LICENSE_DIVANTE.txt │ ├── Logger │ └── WebhookLoggerFactory.php │ ├── Model │ └── Vue │ │ ├── Webhook.php │ │ └── Webhook │ │ └── Catalog │ │ ├── Product │ │ └── MassAction.php │ │ └── ProductWebhook.php │ ├── Observer │ └── Product │ │ ├── DeleteAfter.php │ │ └── SaveAfter.php │ ├── Plugin │ └── Controller │ │ └── Adminhtml │ │ └── Product │ │ ├── Action │ │ └── Attribute │ │ │ └── Save.php │ │ └── MassStatus.php │ ├── Setup │ └── InstallData.php │ ├── composer.json │ ├── etc │ ├── adminhtml │ │ └── system.xml │ ├── config.xml │ ├── di.xml │ ├── events.xml │ └── module.xml │ └── registration.php └── README.md /Divante/VsBridge/Api/Vue/Webhook/Catalog/ProductWebhookInterface.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Api\Vue\Webhook\Catalog; 10 | 11 | /** 12 | * Interface ProductWebhookInterface 13 | */ 14 | interface ProductWebhookInterface 15 | { 16 | 17 | /** 18 | * @param array $productSkuArray 19 | * 20 | * @return void 21 | */ 22 | public function sendSkuDataAfterSave(array $productSkuArray); 23 | 24 | /** 25 | * @param array $productSkuArray 26 | * 27 | * @return void 28 | */ 29 | public function sendSkuDataAfterDelete(array $productSkuArray); 30 | } 31 | -------------------------------------------------------------------------------- /Divante/VsBridge/LICENSE_DIVANTE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Divante Sp. z o.o. http://divante.co 2 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 3 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 4 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Divante/VsBridge/Logger/WebhookLoggerFactory.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Logger; 10 | 11 | use Monolog\Handler\StreamHandler; 12 | use Monolog\Logger; 13 | 14 | /** 15 | * Class IndexerLoggerFactory 16 | */ 17 | class WebhookLoggerFactory 18 | { 19 | 20 | /** 21 | * @var string 22 | */ 23 | private static $path = BP . '/var/log/vs-bridge.log'; 24 | 25 | /** 26 | * @param string $channelName 27 | * 28 | * @return Logger 29 | * 30 | * @throws \Exception 31 | */ 32 | public function create(string $channelName = 'vs-bridge'): Logger 33 | { 34 | $logger = new Logger($channelName); 35 | $logger->pushHandler(new StreamHandler(self::$path)); 36 | 37 | return $logger; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Divante/VsBridge/Model/Vue/Webhook.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Model\Vue; 10 | 11 | use Divante\VsBridge\Logger\WebhookLoggerFactory; 12 | use Magento\Framework\App\Config\ScopeConfigInterface; 13 | use Magento\Framework\HTTP\Adapter\Curl; 14 | use Magento\Framework\Serialize\Serializer\Json; 15 | use Monolog\Logger; 16 | 17 | /** 18 | * Class Indexer 19 | */ 20 | abstract class Webhook 21 | { 22 | 23 | /** 24 | * @var string 25 | */ 26 | private static $isEnabledConfigPath = 'vs_bridge/general/is_active'; 27 | /** 28 | * @var Curl 29 | */ 30 | protected $curlAdapter; 31 | /** 32 | * @var WebhookLoggerFactory 33 | */ 34 | private $indexerLoggerFactory; 35 | /** 36 | * @var Json 37 | */ 38 | protected $jsonSerializer; 39 | /** 40 | * @var ScopeConfigInterface 41 | */ 42 | protected $scopeConfig; 43 | /** 44 | * @var string 45 | */ 46 | public static $secretKeyConfigPath = 'vs_bridge/general/secret_key'; 47 | 48 | /** 49 | * AbstractClass constructor. 50 | * 51 | * @param Curl $curlAdapter 52 | * @param WebhookLoggerFactory $indexerLoggerFactory 53 | * @param Json $jsonSerializer 54 | * @param ScopeConfigInterface $scopeConfig 55 | */ 56 | public function __construct( 57 | Curl $curlAdapter, 58 | WebhookLoggerFactory $indexerLoggerFactory, 59 | Json $jsonSerializer, 60 | ScopeConfigInterface $scopeConfig 61 | ) 62 | { 63 | $this->curlAdapter = $curlAdapter; 64 | $this->indexerLoggerFactory = $indexerLoggerFactory; 65 | $this->jsonSerializer = $jsonSerializer; 66 | $this->scopeConfig = $scopeConfig; 67 | } 68 | 69 | /** 70 | * @param string[] $identifiers 71 | * 72 | * @return string 73 | */ 74 | private function hashChecksum(array $identifiers): string 75 | { 76 | $secretKey = $this->scopeConfig->getValue(self::$secretKeyConfigPath); 77 | $encodedIdentifiers = $this->encodeIdentifiers($identifiers); 78 | 79 | return md5($encodedIdentifiers . $secretKey); 80 | } 81 | 82 | /** 83 | * @return bool 84 | */ 85 | protected function getIsEnabled(): bool 86 | { 87 | return $this->scopeConfig->isSetFlag(self::$isEnabledConfigPath); 88 | } 89 | 90 | /** 91 | * @return Logger 92 | * 93 | * @throws \Exception 94 | */ 95 | protected function getLogger(): Logger 96 | { 97 | return $this->indexerLoggerFactory->create(); 98 | } 99 | 100 | /** 101 | * @param string[] $identifiers 102 | * 103 | * @return string 104 | */ 105 | protected function encodeIdentifiers(array $identifiers): string 106 | { 107 | return urlencode(implode(',', $identifiers)); 108 | } 109 | 110 | /** 111 | * @param string $configPath 112 | * @param string[] $identifiers 113 | * 114 | * @return string|false 115 | */ 116 | protected function getEndpoint(string $configPath, array $identifiers = []) 117 | { 118 | $endpoint = $this->scopeConfig->getValue($configPath); 119 | 120 | if (empty($endpoint) || !$this->getIsEnabled()) { 121 | return false; 122 | } 123 | 124 | return empty($identifiers) ? $endpoint : $endpoint . '?checksum=' . $this->hashChecksum($identifiers); 125 | } 126 | 127 | /** 128 | * @param string $url 129 | * @param array $data 130 | * @param array $headers 131 | * 132 | * @return void 133 | */ 134 | protected function sendRequest(string $url, array $data, array $headers = ['Content-Type: application/json']) 135 | { 136 | if ($this->getIsEnabled()) { 137 | $jsonBody = $this->jsonSerializer->serialize($data); 138 | 139 | $request = $this->curlAdapter->write('POST', $url, '1.1', $headers, $jsonBody); 140 | $response = $this->curlAdapter->read(); 141 | 142 | $this->curlAdapter->close(); 143 | 144 | try { 145 | $logger = $this->getLogger(); 146 | 147 | $logger->debug($request); 148 | $logger->debug($response); 149 | } catch (\Exception $e) { 150 | // DO NOTHING 151 | } 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /Divante/VsBridge/Model/Vue/Webhook/Catalog/Product/MassAction.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Model\Vue\Webhook\Catalog\Product; 10 | 11 | use Divante\VsBridge\Api\Vue\Webhook\Catalog\ProductWebhookInterface; 12 | use Magento\Catalog\Api\ProductRepositoryInterface; 13 | use Magento\Framework\Api\SearchCriteriaBuilder; 14 | 15 | /** 16 | * Class MassAction 17 | */ 18 | class MassAction 19 | { 20 | 21 | /** 22 | * @var ProductWebhookInterface 23 | */ 24 | private $productIndexer; 25 | /** 26 | * @var ProductRepositoryInterface 27 | */ 28 | private $productRepository; 29 | /** 30 | * @var SearchCriteriaBuilder 31 | */ 32 | private $searchCriteriaBuilder; 33 | 34 | /** 35 | * Save constructor. 36 | * 37 | * @param ProductWebhookInterface $productIndexer 38 | * @param ProductRepositoryInterface $productRepository 39 | * @param SearchCriteriaBuilder $searchCriteriaBuilder 40 | */ 41 | public function __construct( 42 | ProductWebhookInterface $productIndexer, 43 | ProductRepositoryInterface $productRepository, 44 | SearchCriteriaBuilder $searchCriteriaBuilder 45 | ) 46 | { 47 | $this->productRepository = $productRepository; 48 | $this->searchCriteriaBuilder = $searchCriteriaBuilder; 49 | $this->productIndexer = $productIndexer; 50 | } 51 | 52 | /** 53 | * @param array $productIds 54 | * 55 | * @return void 56 | */ 57 | public function update(array $productIds) 58 | { 59 | if (!empty($productIds)) { 60 | $searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $productIds, 'in')->create(); 61 | $products = $this->productRepository->getList($searchCriteria); 62 | 63 | if ($products->getTotalCount() > 0) { 64 | $productSkuArray = []; 65 | 66 | foreach ($products->getItems() as $product) { 67 | $productSkuArray[] = $product->getSku(); 68 | } 69 | 70 | $this->productIndexer->sendSkuDataAfterSave($productSkuArray); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Divante/VsBridge/Model/Vue/Webhook/Catalog/ProductWebhook.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Model\Vue\Webhook\Catalog; 10 | 11 | use Divante\VsBridge\Api\Vue\Webhook\Catalog\ProductWebhookInterface; 12 | use Divante\VsBridge\Model\Vue\Webhook; 13 | 14 | /** 15 | * Class ProductWebhook 16 | */ 17 | class ProductWebhook extends Webhook implements ProductWebhookInterface 18 | { 19 | 20 | /** 21 | * @var string 22 | */ 23 | private static $saveEndpointConfPath = 'vs_bridge/general/product_edit_endpoint'; 24 | /** 25 | * @var string 26 | */ 27 | private static $deleteEndpointConfPath = 'vs_bridge/general/product_delete_endpoint'; 28 | 29 | /** 30 | * @param array $productSkuArray 31 | * 32 | * @return void 33 | */ 34 | public function sendSkuDataAfterSave(array $productSkuArray) 35 | { 36 | $saveEndpoint = $this->getEndpoint(self::$saveEndpointConfPath, $productSkuArray); 37 | 38 | if ($saveEndpoint) { 39 | $this->sendRequest($saveEndpoint, ['sku' => $productSkuArray]); 40 | } 41 | } 42 | 43 | /** 44 | * @param array $productSkuArray 45 | * 46 | * @return void 47 | */ 48 | public function sendSkuDataAfterDelete(array $productSkuArray) 49 | { 50 | $deleteEndpoint = $this->getEndpoint(self::$deleteEndpointConfPath, $productSkuArray); 51 | 52 | if ($deleteEndpoint) { 53 | $this->sendRequest($deleteEndpoint, ['sku' => $productSkuArray]); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Divante/VsBridge/Observer/Product/DeleteAfter.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Observer\Product; 10 | 11 | use Divante\VsBridge\Api\Vue\Webhook\Catalog\ProductWebhookInterface; 12 | use Magento\Catalog\Model\Product; 13 | use Magento\Framework\Event\Observer; 14 | use Magento\Framework\Event\ObserverInterface; 15 | 16 | /** 17 | * Class DeleteAfter 18 | */ 19 | class DeleteAfter implements ObserverInterface 20 | { 21 | 22 | /** 23 | * @var ProductWebhookInterface 24 | */ 25 | private $productIndexer; 26 | 27 | /** 28 | * SaveAfter constructor. 29 | * 30 | * @param ProductWebhookInterface $productIndexer 31 | */ 32 | public function __construct(ProductWebhookInterface $productIndexer) 33 | { 34 | $this->productIndexer = $productIndexer; 35 | } 36 | 37 | /** 38 | * @param Observer $observer 39 | * 40 | * @return void 41 | */ 42 | public function execute(Observer $observer) 43 | { 44 | /** @var Product $product */ 45 | $product = $observer->getEvent()->getData('product'); 46 | 47 | $this->productIndexer->sendSkuDataAfterDelete([$product->getSku()]); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Divante/VsBridge/Observer/Product/SaveAfter.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Observer\Product; 10 | 11 | use Divante\VsBridge\Api\Vue\Webhook\Catalog\ProductWebhookInterface; 12 | use Magento\Framework\Event\Observer; 13 | use Magento\Framework\Event\ObserverInterface; 14 | 15 | /** 16 | * Class SaveAfter 17 | */ 18 | class SaveAfter implements ObserverInterface 19 | { 20 | 21 | /** 22 | * @var ProductWebhookInterface 23 | */ 24 | private $productIndexer; 25 | 26 | /** 27 | * SaveAfter constructor. 28 | * 29 | * @param ProductWebhookInterface $productIndexer 30 | */ 31 | public function __construct(ProductWebhookInterface $productIndexer) 32 | { 33 | $this->productIndexer = $productIndexer; 34 | } 35 | 36 | /** 37 | * @param Observer $observer 38 | * 39 | * @return void 40 | */ 41 | public function execute(Observer $observer) 42 | { 43 | /** @var \Magento\Catalog\Model\Product $product */ 44 | $product = $observer->getEvent()->getData('product'); 45 | 46 | $this->productIndexer->sendSkuDataAfterSave([$product->getSku()]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Divante/VsBridge/Plugin/Controller/Adminhtml/Product/Action/Attribute/Save.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Plugin\Controller\Adminhtml\Product\Action\Attribute; 10 | 11 | use Divante\VsBridge\Model\Vue\Webhook\Catalog\Product\MassAction; 12 | use Magento\Backend\Model\View\Result\Redirect; 13 | use Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save as SaveController; 14 | use Magento\Catalog\Helper\Product\Edit\Action\Attribute; 15 | 16 | /** 17 | * Class Save 18 | */ 19 | class Save 20 | { 21 | 22 | /** 23 | * @var Attribute 24 | */ 25 | private $attributeHelper; 26 | /** 27 | * @var MassAction 28 | */ 29 | private $massAction; 30 | 31 | /** 32 | * Save constructor. 33 | * 34 | * @param Attribute $attributeHelper 35 | * @param MassAction $massAction 36 | * 37 | */ 38 | public function __construct(Attribute $attributeHelper, MassAction $massAction) 39 | { 40 | $this->attributeHelper = $attributeHelper; 41 | $this->massAction = $massAction; 42 | } 43 | 44 | /** 45 | * @param SaveController $saveController 46 | * @param Redirect $redirect 47 | * 48 | * @return Redirect 49 | * 50 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 51 | */ 52 | public function afterExecute(SaveController $saveController, Redirect $redirect) 53 | { 54 | $productIds = $this->attributeHelper->getProductIds(); 55 | 56 | $this->massAction->update($productIds); 57 | 58 | return $redirect; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Divante/VsBridge/Plugin/Controller/Adminhtml/Product/MassStatus.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Plugin\Controller\Adminhtml\Product; 10 | 11 | use Divante\VsBridge\Model\Vue\Webhook\Catalog\Product\MassAction; 12 | use Magento\Backend\Model\View\Result\Redirect; 13 | use Magento\Catalog\Controller\Adminhtml\Product\MassStatus as MassStatusController; 14 | use Magento\Catalog\Helper\Product\Edit\Action\Attribute; 15 | use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; 16 | use Magento\Framework\Exception\LocalizedException; 17 | use Magento\Ui\Component\MassAction\Filter; 18 | 19 | /** 20 | * Class MassStatus 21 | */ 22 | class MassStatus 23 | { 24 | 25 | /** 26 | * @var Attribute 27 | */ 28 | private $attributeHelper; 29 | /** 30 | * @var CollectionFactory 31 | */ 32 | private $collectionFactory; 33 | /** 34 | * @var Filter 35 | */ 36 | private $filter; 37 | /** 38 | * @var MassAction 39 | */ 40 | private $massAction; 41 | 42 | /** 43 | * MassStatus constructor. 44 | * 45 | * @param Attribute $attributeHelper 46 | * @param CollectionFactory $collectionFactory 47 | * @param Filter $filter 48 | * @param MassAction $massAction 49 | */ 50 | public function __construct( 51 | Attribute $attributeHelper, 52 | CollectionFactory $collectionFactory, 53 | Filter $filter, 54 | MassAction $massAction 55 | ) 56 | { 57 | $this->attributeHelper = $attributeHelper; 58 | $this->collectionFactory = $collectionFactory; 59 | $this->filter = $filter; 60 | $this->massAction = $massAction; 61 | } 62 | 63 | /** 64 | * @param MassStatusController $massStatusController 65 | * @param Redirect $redirect 66 | * 67 | * @return Redirect 68 | * 69 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) 70 | */ 71 | public function afterExecute(MassStatusController $massStatusController, Redirect $redirect) 72 | { 73 | try { 74 | $productsCollection = $this->filter->getCollection($this->collectionFactory->create()); 75 | 76 | $this->massAction->update($productsCollection->getAllIds()); 77 | } catch (LocalizedException $e) { 78 | // DO NOTHING 79 | } 80 | 81 | return $redirect; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Divante/VsBridge/Setup/InstallData.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | namespace Divante\VsBridge\Setup; 10 | 11 | use Divante\VsBridge\Model\Vue\Webhook; 12 | use Magento\Config\Model\ResourceModel\Config; 13 | use Magento\Framework\App\Config\ScopeConfigInterface; 14 | use Magento\Framework\Setup\InstallDataInterface; 15 | use Magento\Framework\Setup\ModuleContextInterface; 16 | use Magento\Framework\Setup\ModuleDataSetupInterface; 17 | use Magento\Store\Model\Store; 18 | 19 | /** 20 | * Class InstallData 21 | */ 22 | class InstallData implements InstallDataInterface 23 | { 24 | 25 | /** 26 | * @var Config 27 | */ 28 | private $resourceConfig; 29 | 30 | /** 31 | * InstallData constructor. 32 | * 33 | * @param Config $resourceConfig 34 | */ 35 | public function __construct(Config $resourceConfig) 36 | { 37 | $this->resourceConfig = $resourceConfig; 38 | } 39 | 40 | /** 41 | * Installs data for a module 42 | * 43 | * @param ModuleDataSetupInterface $setup 44 | * @param ModuleContextInterface $context 45 | * 46 | * @return void 47 | */ 48 | public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) 49 | { 50 | $setup->startSetup(); 51 | $this->generateSecretKey(); 52 | $setup->endSetup(); 53 | } 54 | 55 | /** 56 | * @return void 57 | */ 58 | private function generateSecretKey() 59 | { 60 | $secretKey = md5(microtime() . mt_rand()); 61 | 62 | $this->resourceConfig->saveConfig( 63 | Webhook::$secretKeyConfigPath, 64 | $secretKey, 65 | ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 66 | Store::DEFAULT_STORE_ID 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Divante/VsBridge/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magento/module-vs-bridge", 3 | "description": "Vue Storefront webhook for Magento", 4 | "require": { 5 | "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", 6 | "magento/module-store": "100.2.*", 7 | "magento/module-catalog": "102.0.*", 8 | "magento/module-backend": "100.2.*", 9 | "magento/module-eav": "101.0.*", 10 | "magento/module-config": "101.0.*", 11 | "magento/framework": "101.0.*" 12 | }, 13 | "type": "magento2-module", 14 | "version": "1.0.0", 15 | "license": [ 16 | "OSL-3.0", 17 | "AFL-3.0" 18 | ], 19 | "authors": [ 20 | { 21 | "name": "Mateusz Bukowski", 22 | "email": "mbukowski@divante.pl" 23 | } 24 | ], 25 | "autoload": { 26 | "files": [ 27 | "registration.php" 28 | ], 29 | "psr-4": { 30 | "Divante\\VsBridge\\": "" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Divante/VsBridge/etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | divante_vue 17 | Divante_VsBridge::vs_bridge 18 | 19 | 20 | 21 | 22 | Magento\Config\Model\Config\Source\Yesno 23 | 24 | 25 | 26 | Please enter edit product URL 27 | 28 | 29 | 30 | Please enter delete product URL 31 | 32 | 33 | 34 | 35 | 36 |
37 |
38 |
39 | -------------------------------------------------------------------------------- /Divante/VsBridge/etc/config.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | 0 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Divante/VsBridge/etc/di.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Divante/VsBridge/etc/events.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Divante/VsBridge/etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Divante/VsBridge/registration.php: -------------------------------------------------------------------------------- 1 | 5 | * @copyright 2018 Divante Sp. z o.o. 6 | * @license See LICENSE_DIVANTE.txt for license details. 7 | */ 8 | 9 | \Magento\Framework\Component\ComponentRegistrar::register( 10 | \Magento\Framework\Component\ComponentRegistrar::MODULE, 11 | 'Divante_VsBridge', 12 | __DIR__ 13 | ); 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Magento Vue Storefront utils 2 | 3 | This Magento extension enhances the [mage2vuestorefront](https://github.com/DivanteLtd/mage2vuestorefront) idnexer by providing on-demand Product indexing based on web-hooks mechanism. 4 | 5 | This module is designed to work with: [mage2vuestorefront](https://github.com/DivanteLtd/mage2vuestorefront) and [Vue Storefront](https://github.com/DivanteLtd/vue-storefront). 6 | 7 | ## Installation guide 8 | 9 | 0. Integrate Your Magento2 instance with Vue Storefront: [tutorial](https://medium.com/@piotrkarwatka/vue-storefront-cart-totals-orders-integration-with-magento2-6fbe6860fcd), [video tutorial](https://www.youtube.com/watch?v=CtDXddsyxvM) 10 | 1. Setup [mage2vuestorefront](https://medium.com/@piotrkarwatka/vue-storefront-how-to-install-and-integrate-with-magento2-227767dd65b2) bridge for product imports. 11 | 2. Please copy the `"Divante"` folder containing the extension to Your Magento modules directory (`app`) 12 | 3. Run `php bin/magento setup:upgrade` 13 | 4. Configure VsBridge module and mage2vuestorefront to work together by executing the steps desribed below. 14 | 15 | ### On-demand indexer (experimental!) support for mage2vuestorefront 16 | 17 | Mage2vuestorefront supports an on-demand indexer - where Magento calls a special webhook to update modified products. 18 | In the current version the webhook notifies mage2vuestorefront about changed product SKUs and mage2vuestorefront pulls the modified products data via Magento2 APIs. 19 | 20 | To start mage2vuestorefront in the on-demand mode, please execute the following steps. 21 | 22 | ```bash 23 | cd mage2vuestorefront/src 24 | export TIME_TO_EXIT=2000 25 | export MAGENTO_CONSUMER_KEY=byv3730rhoulpopcq64don8ukb8lf2gq 26 | export MAGENTO_CONSUMER_SECRET=u9q4fcobv7vfx9td80oupa6uhexc27rb 27 | export MAGENTO_ACCESS_TOKEN=040xx3qy7s0j28o3q0exrfop579cy20m 28 | export MAGENTO_ACCESS_TOKEN_SECRET=7qunl3p505rubmr7u1ijt7odyialnih9 29 | export PORT=6060 30 | export MAGENTO_URL=http://demo-magento2.vuestorefront.io/rest 31 | 32 | node --harmony webapi.js 33 | ``` 34 | 35 | The API will be listening on port 6060. Typically non-standard ports like this one are not exposed on the firewall. Please consider setting up [simple nginx proxy for this service](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04). 36 | 37 | Anyway - this API must be publicly available via Internet OR You must have the mage2vuestorefront installed on the same machine like Magento2. 38 | 39 | Go to Your Magento2 admin panel, then to Stores -> Configuration -> VsBridge and set-up "Edit product" url to: `http://localhost:6060/magento/products/update`. **Please note:** Product delete endpoint hasn't been implemented yet and it's good chance for Your PR. 40 | 41 | After having the webapi up and runing and this endpoint set, any Product save action will call `POST http://localhost:6060/magento/products/update` with the body set to `{"sku": ["modified-sku-list"]}`. 42 | 43 | Webapi will [add the products to the queue](https://github.com/DivanteLtd/mage2vuestorefront/blob/b44e7ede9aeb27f308e2a87033251a2491640da8/src/api/routes/magento.js#L19). 44 | 45 | Please run the queue worker to process all the queued updates (You may run multiple queue workers even distributed across many machines): 46 | 47 | ```bash 48 | cd mage2vuestorefront/src 49 | export TIME_TO_EXIT=2000 50 | export MAGENTO_CONSUMER_KEY=byv3730rhoulpopcq64don8ukb8lf2gq 51 | export MAGENTO_CONSUMER_SECRET=u9q4fcobv7vfx9td80oupa6uhexc27rb 52 | export MAGENTO_ACCESS_TOKEN=040xx3qy7s0j28o3q0exrfop579cy20m 53 | export MAGENTO_ACCESS_TOKEN_SECRET=7qunl3p505rubmr7u1ijt7odyialnih9 54 | export PORT=6060 55 | export MAGENTO_URL=http://demo-magento2.vuestorefront.io/rest 56 | 57 | node --harmony cli.js productsworker 58 | ``` 59 | 60 | **Please note:** We're using [kue based on Redis queue](https://github.com/Automattic/kue) which may be configured via `src/config.js` - `kue` + `redis` section. 61 | **Please note:** There is no authorization mechanism in place for the webapi calls. Please keep it local / private networked or add some kind of authorization as a PR to this project please :-) 62 | 63 | 64 | ## Credits 65 | 66 | Mateusz Bukowski (@gatzzu) 67 | --------------------------------------------------------------------------------