Skip to content
This repository was archived by the owner on Feb 8, 2019. It is now read-only.

Renamed package to VueStorefront/CartSync #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/*
.php_cs.cache
.idea/*
*~
70 changes: 36 additions & 34 deletions Controller/Cart/Sync.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<?php
/**
* @package Divante\CartSync
* @author Mateusz Bukowski <[email protected]>
* @copyright 2018 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/
declare(strict_types=1);

namespace Divante\CartSync\Controller\Cart;
namespace VueStorefront\CartSync\Controller\Cart;

use Divante\CartSync\Service\SyncInterface;
use Divante\CartSync\Service\SyncLoggerFactory;
use VueStorefront\CartSync\Model\Config;
use VueStorefront\CartSync\Service\SyncInterface;
use VueStorefront\CartSync\Service\SyncLoggerFactory;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Action\Action;
Expand All @@ -28,69 +24,75 @@
*/
class Sync extends Action
{

/**
* @var CustomerRepositoryInterface
*/
private $customerRepository;
protected $customerRepository;
/**
* @var CustomerSession
*/
private $customerSession;
protected $customerSession;
/**
* @var Logger
*/
private $logger;
protected $logger;
/**
* @var TokenFactory
*/
private $tokenFactory;
protected $tokenFactory;
/**
* @var SyncInterface
*/
private $sync;
protected $sync;
/**
* @var Config
*/
protected $config;

/**
* Sync constructor.
*
* @param Context $context
* @param Config $config
* @param Context $context
* @param CustomerRepositoryInterface $customerRepository
* @param CustomerSession $customerSession
* @param SyncInterface $sync
* @param SyncLoggerFactory $syncLoggerFactory
* @param TokenFactory $tokenFactory
* @param CustomerSession $customerSession
* @param SyncInterface $sync
* @param SyncLoggerFactory $syncLoggerFactory
* @param TokenFactory $tokenFactory
*
* @throws \Exception
*/
public function __construct(
Config $config,
Context $context,
CustomerRepositoryInterface $customerRepository,
CustomerSession $customerSession,
SyncInterface $sync,
SyncLoggerFactory $syncLoggerFactory,
TokenFactory $tokenFactory
)
{
) {
parent::__construct($context);

$this->customerRepository = $customerRepository;
$this->customerSession = $customerSession;
$this->tokenFactory = $tokenFactory;
$this->sync = $sync;
$this->logger = $syncLoggerFactory->create();
$this->customerSession = $customerSession;
$this->tokenFactory = $tokenFactory;
$this->sync = $sync;
$this->logger = $syncLoggerFactory->create();
$this->config = $config;
}

/**
* @return ResponseInterface|Json|ResultInterface
*/
public function execute()
{
$checkoutPath = $this->config->getCheckoutPath();

if (!$this->hasRequestAllRequiredParams()) {
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
return $this->resultRedirectFactory->create()->setPath($checkoutPath);
}

$customerToken = $this->getRequest()->getParam('token');
$cartId = $this->getRequest()->getParam('cart');
$cartId = $this->getRequest()->getParam('cart');

/** @var Token $token */
$token = $this->tokenFactory->create()->loadByToken($customerToken);
Expand Down Expand Up @@ -121,12 +123,12 @@ public function execute()
$this->logger->addError($e->getMessage());
$this->messageManager->addErrorMessage(__('Required customer doesn\'t exist'));

return $this->resultRedirectFactory->create()->setPath('checkout/cart');
return $this->resultRedirectFactory->create()->setPath($checkoutPath);
} catch (LocalizedException $e) {
$this->logger->addError($e->getMessage());
$this->messageManager->addErrorMessage(__('Cannot synchronize customer cart'));

return $this->resultRedirectFactory->create()->setPath('checkout/cart');
return $this->resultRedirectFactory->create()->setPath($checkoutPath);
}

$this->customerSession->loginById($customer->getId());
Expand All @@ -135,7 +137,7 @@ public function execute()
$this->sync->synchronizeCustomerCart($this->customerSession->getCustomerId(), $cartId);
}

return $this->resultRedirectFactory->create()->setPath('checkout/cart');
return $this->resultRedirectFactory->create()->setPath($checkoutPath);
}

/**
Expand All @@ -144,7 +146,7 @@ public function execute()
private function hasRequestAllRequiredParams(): bool
{
return null !== $this->getRequest()->getParam('token')
&& !empty($this->getRequest()->getParam('cart'));
&& !empty($this->getRequest()->getParam('cart'));
}

/**
Expand Down Expand Up @@ -191,7 +193,7 @@ private function logoutCustomer(string $customerToken, string $cartId): Response
'vue/cart/sync',
[
'token' => $customerToken,
'cart' => $cartId,
'cart' => $cartId,
]
);
}
Expand Down
25 changes: 21 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
Copyright (c) 2018 Divante Sp. z o.o. http://divante.co
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
MIT License

Copyright (c) 2018 Divante Ltd.

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
43 changes: 43 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

namespace VueStorefront\CartSync\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Config
{
const CHECKOUT_PATH = 'vuestorefront_externalcheckout/externalcheckout_general/checkout_path';
const VUESTOREFRONT_SUCCES_PATH = 'vuestorefront_externalcheckout/externalcheckout_general/externalcheckout_link';

/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;

public function __construct(
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

public function getCheckoutPath()
{
$value = $this->getConfigValue(self::CHECKOUT_PATH);
if (!$value) {
return 'checkout/cart';
}
return trim($value);
}

public function getVueStorefrontSuccessUrl()
{
return $this->getConfigValue(self::VUESTOREFRONT_SUCCES_PATH);
}

protected function getConfigValue($key)
{
return $this->scopeConfig->getValue($key, ScopeInterface::SCOPE_STORE);
}
}
36 changes: 9 additions & 27 deletions Observer/SuccessObserver.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,35 @@
<?php
/**
* @package Divante\CartSync
* @author Maciej Daniłowicz <mdanił[email protected]>
* @copyright 2018 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/
declare(strict_types=1);

namespace Divante\CartSync\Observer;
namespace VueStorefront\CartSync\Observer;

use VueStorefront\CartSync\Model\Config;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;

/**
* Class SuccessObserver
*
* @package Divante\CartSync\Observer
* @package VueStorefront\CartSync\Observer
*/
class SuccessObserver implements ObserverInterface
{
/**
* @var string
* @var Config
*/
private $confPath = 'vuestorefront_externalcheckout/externalcheckout_general/externalcheckout_link';
protected $config;

/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;

/**
* SuccessObserver constructor.
*
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
ScopeConfigInterface $scopeConfig
Config $config
) {
$this->scopeConfig = $scopeConfig;
$this->config = $config;
}

/**
* @param \Magento\Framework\Event\Observer $observer
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$url = $this->scopeConfig->getValue(
$this->confPath,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$url = $this->config->getVueStorefrontSuccessUrl();

if ($url && $url !== '') {
if (!(strpos($url, "http://") !== false || strpos($url, "https://") !== false)) {
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

This Magento extension allow You to merge given shopping cart with current's user session. It performs a auto-login if user-token provided.

This module is designed to work with: [Vue Storefront External Checkout](https://github.com/filrak/vsf-external-checkout).
This module is designed to work with: [Vue Storefront External Checkout](https://github.com/Vendic/vsf-external-checkout).

This extension allows the user to start the session within the Vue Storefront shop and finalize the order in Magento2. It's great when You have very extended/customized Magento checkout which will be hard to port to Vue Storefront.

![External checkout for Vue Storefront](https://github.com/filrak/vsf-external-checkout/raw/master/diagram.png)
![External checkout for Vue Storefront](https://raw.githubusercontent.com/Vendic/vsf-external-checkout/master/media/diagram.png)

## Demo
You can check this extension in action on: https://demo-magento-checkout.vuestorefront.io
Please add some items to the cart and then go to **Cart -> Go to chechkout**. You will be redirected to the [Magento2 instance](http://demo-magento2.vuestorefront.io/) synchronized with the [Vue Storefront instance](demo-magento-checkout.vuestorefront.io). Shopping carts, logged in user, totals, item prices - should be alligned.
### Demo
[A demo is not yet available.](https://github.com/Vendic/magento2-external-checkout/issues/1)

### Compatibility
- Magento 2.2 or Magento 2.3

## Installation guide
### Prerequisites (the Vue Storefront part)
1. 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)
2. Install [Vue Storefront External Checkout](https://github.com/Vendic/vsf-external-checkout) on your Vue Storefront instance

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)
1. Copy the module files from the repo to `app/code/Divante/CartSync`
### Installation guide (the Magento 2 part)
1. Install the module with composer:
```bash
composer require vuestorefront/magento2-vue-cart-sync
```
3. Run `php bin/magento setup:upgrade`
4. Please install the [`vsf-external-checkout`](https://github.com/filrak/vsf-external-checkout) module for Vue Storefront. [See the instruction](https://github.com/filrak/vsf-external-checkout).
5. Go to: Stores -> Configuration | VueStorefront -> External Checkout and set URL
Expand Down
12 changes: 3 additions & 9 deletions Service/Sync.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?php
/**
* @package Divante\CartSync
* @author Mateusz Bukowski <[email protected]>
* @copyright 2018 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/
declare(strict_types=1);

namespace Divante\CartSync\Service;
namespace VueStorefront\CartSync\Service;

use Magento\Checkout\Model\Session;
use Magento\Customer\Api\CustomerRepositoryInterface;
Expand Down Expand Up @@ -82,8 +77,7 @@ public function __construct(
QuoteIdMaskFactory $quoteIdMaskFactory,
QuoteFactory $quoteFactory,
QuoteRepository $quoteRepository
)
{
) {
$this->cartRepository = $cartRepository;
$this->checkoutSession = $checkoutSession;
$this->customerRepository = $customerRepository;
Expand Down
9 changes: 2 additions & 7 deletions Service/SyncInterface.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?php
/**
* @package Divante\CartSync
* @author Mateusz Bukowski <[email protected]>
* @copyright 2018 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/
declare(strict_types=1);

namespace Divante\CartSync\Service;
namespace VueStorefront\CartSync\Service;

/**
* Interface SyncInterface
Expand Down
Loading