-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Henry Chan
committed
Feb 17, 2017
0 parents
commit 65111f5
Showing
33 changed files
with
939 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Klaviyo\Reclaim\Block\Catalog\Product; | ||
|
||
class ViewedProduct extends \Magento\Framework\View\Element\Template | ||
{ | ||
protected $_helper; | ||
protected $_objectManager; | ||
protected $_registry; | ||
protected $_categoryFactory; | ||
|
||
public function __construct( | ||
\Magento\Framework\View\Element\Template\Context $context, | ||
\Klaviyo\Reclaim\Helper\Data $helper, | ||
\Magento\Framework\ObjectManagerInterface $objectManager, | ||
\Magento\Framework\Registry $registry, | ||
\Magento\Catalog\Model\CategoryFactory $categoryFactory, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->_helper = $helper; | ||
$this->_objectManager = $objectManager; | ||
$this->_registry = $registry; | ||
$this->_categoryFactory = $categoryFactory; | ||
} | ||
|
||
/** | ||
* Grab the Klaviyo public API key from the configuration helper and return it. | ||
* Used to make `identify` calls for `Active on Site` metric (for signed in users) | ||
* and `track` calls for `Viewed Product` metrics. | ||
* | ||
* @return string | ||
*/ | ||
public function getPublicApiKey() | ||
{ | ||
return $this->_helper->getPublicApiKey(); | ||
} | ||
|
||
/** | ||
* Grab whether the Klaviyo_Reclaim extension is enabled through Admin from | ||
* the configuration helper and return it. | ||
* | ||
* @return boolean | ||
*/ | ||
public function isKlaviyoEnabled() | ||
{ | ||
return $this->_helper->getEnabled(); | ||
} | ||
|
||
/** | ||
* View helper to return the currently viewed catalog product. Used to track | ||
* the `Viewed Product` metric. | ||
* | ||
* @return Catalog_Product | ||
*/ | ||
public function getProduct() | ||
{ | ||
return $this->_registry->registry('current_product'); | ||
} | ||
|
||
/** | ||
* View helper to return a list of category names for the currently viewed | ||
* catalog product. Used to track the `Viewed Product` metric. | ||
* | ||
* @return JSON | ||
*/ | ||
public function getProductCategoriesAsJson() | ||
{ | ||
$categories = array(); | ||
foreach ($this->getProduct()->getCategoryIds() as $category_id) { | ||
$category = $category = $this->_categoryFactory->create()->load($category_id); | ||
$categories[] = $category->getName(); | ||
} | ||
return json_encode($categories); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Klaviyo\Reclaim\Block; | ||
|
||
class Initialize extends \Magento\Framework\View\Element\Template | ||
{ | ||
protected $_helper; | ||
protected $_objectManager; | ||
|
||
public function __construct( | ||
\Magento\Framework\View\Element\Template\Context $context, | ||
\Klaviyo\Reclaim\Helper\Data $helper, | ||
\Magento\Framework\ObjectManagerInterface $objectManager, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->_helper = $helper; | ||
$this->_objectManager = $objectManager; | ||
} | ||
|
||
/** | ||
* Grab the Klaviyo public API key from the configuration helper and return it. | ||
* Used to make `identify` calls for `Active on Site` metric (for signed in users) | ||
* and `track` calls for `Viewed Product` metrics. | ||
* | ||
* @return string | ||
*/ | ||
public function getPublicApiKey() | ||
{ | ||
return $this->_helper->getPublicApiKey(); | ||
} | ||
|
||
/** | ||
* Grab whether the Klaviyo_Reclaim extension is enabled through Admin from | ||
* the configuration helper and return it. | ||
* | ||
* @return boolean | ||
*/ | ||
public function isKlaviyoEnabled() | ||
{ | ||
return $this->_helper->getEnabled(); | ||
} | ||
|
||
/** | ||
* View helper to see if the current user is logged it. Used to know whether | ||
* we can send an `identify` call for the `Active on Site` metric. | ||
* | ||
* @return boolean | ||
*/ | ||
public function isLoggedIn() | ||
{ | ||
$customerSession = $this->_objectManager->create('Magento\Customer\Model\Session'); | ||
return $customerSession->isLoggedIn(); | ||
} | ||
|
||
/** | ||
* View helper to get the current users email address. Used to send an | ||
* `identify` call for the `Active on Site` metric. | ||
* | ||
* @return string | ||
*/ | ||
public function getCustomerEmail() | ||
{ | ||
$customerSession = $this->_objectManager->create('Magento\Customer\Model\Session'); | ||
return $customerSession->getCustomerData()->getEmail(); | ||
} | ||
|
||
/** | ||
* View helper to get the current users first name. Used to send an | ||
* `identify` call for the `Active on Site` metric. | ||
* | ||
* @return string | ||
*/ | ||
public function getCustomerFirstname() | ||
{ | ||
$customerSession = $this->_objectManager->create('Magento\Customer\Model\Session'); | ||
return $customerSession->getCustomerData()->getFirstname(); | ||
} | ||
|
||
/** | ||
* View helper to get the current users last name. Used to send an | ||
* `identify` call for the `Active on Site` metric. | ||
* | ||
* @return string | ||
*/ | ||
public function getCustomerLastname() | ||
{ | ||
$customerSession = $this->_objectManager->create('Magento\Customer\Model\Session'); | ||
return $customerSession->getCustomerData()->getLastname(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace Klaviyo\Reclaim\Block\System\Config\Form\Field; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class Newsletter extends \Magento\Config\Block\System\Config\Form\Field | ||
{ | ||
protected function _getElementHtml(AbstractElement $element) | ||
{ | ||
$values = $element->getValues(); | ||
|
||
if (sizeof($values) > 1) return parent::_getElementHtml($element); | ||
|
||
$message = '<p>' . $values[0]['label'] . '</p>'; | ||
|
||
$html = '<script type="text/javascript"> | ||
var el = document.getElementById("klaviyo_reclaim_newsletter_newsletter"); | ||
el.outerHTML = \'' . $message .'\'; | ||
</script>'; | ||
|
||
return $html; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Klaviyo\Reclaim\Controller\Checkout; | ||
|
||
class Cart extends \Magento\Framework\App\Action\Action | ||
{ | ||
protected $quoteRepository; | ||
protected $resultRedirectFactory; | ||
protected $cart; | ||
protected $request; | ||
|
||
public function __construct( | ||
\Magento\Checkout\Model\Cart $cart, | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Quote\Model\QuoteRepository $quoteRepository | ||
) { | ||
$this->quoteRepository = $quoteRepository; | ||
$this->resultRedirectFactory = $context->getResultRedirectFactory(); | ||
$this->cart = $cart; | ||
$this->request = $context->getRequest(); | ||
|
||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Endpoint /reclaim/checkout/cart resolves here. This endpoint will load an existing | ||
* quote into the current Customer's cart and redirect the Customer to checkout/cart | ||
* If no quote is found it will not do anything to the Customer's cart | ||
* | ||
* @return JSON | ||
*/ | ||
public function execute() | ||
{ | ||
$quoteId = $this->request->getParam('quote_id'); | ||
|
||
try { | ||
$quote = $this->quoteRepository->get($quoteId); | ||
$this->cart->setQuote($quote); | ||
$this->cart->save(); | ||
} catch (\Magento\Framework\Exception\NoSuchEntityException $ex) { | ||
} | ||
|
||
$redirect = $this->resultRedirectFactory->create(); | ||
$redirect->setPath('checkout/cart'); | ||
return $redirect; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Klaviyo\Reclaim\Controller\Checkout; | ||
|
||
class Email extends \Magento\Framework\App\Action\Action | ||
{ | ||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory | ||
) { | ||
parent::__construct($context); | ||
$this->resultJsonFactory = $resultJsonFactory; | ||
$this->_objectManager = $context->getObjectManager(); | ||
} | ||
|
||
/** | ||
* Endpoint /reclaim/checkout/email resolves here. A quote's email address | ||
* is AJAX'd here after the email input changes. We look up the current | ||
* quote and save the email on it, since Magento doesn't do that on its own. | ||
* | ||
* @return JSON | ||
*/ | ||
public function execute() | ||
{ | ||
$result = $this->resultJsonFactory->create(); | ||
$quote = $this->_objectManager->create('Magento\Checkout\Model\Cart')->getQuote(); | ||
|
||
$customer_email = $this->getRequest()->getParam('email'); | ||
$quote->setCustomerEmail($customer_email); | ||
$quote->save(); | ||
|
||
return $result->setData(['success' => $quote->getData()]); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Klaviyo\Reclaim\Controller\Checkout; | ||
|
||
class Reload extends \Magento\Framework\App\Action\Action | ||
{ | ||
protected $resultJsonFactory; | ||
|
||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory | ||
) { | ||
$this->resultJsonFactory = $resultJsonFactory; | ||
parent::__construct($context); | ||
} | ||
/** | ||
* Enpoint /reclaim/checkout/reload resolves here. This endpoint is used indirectly | ||
* via sections.xml so that the minicart can be updated on the client side on request | ||
* | ||
* @return JSON | ||
*/ | ||
public function execute() | ||
{ | ||
$result = $this->resultJsonFactory->create(); | ||
|
||
return $result->setData(['success' => 1]); | ||
} | ||
} |
Oops, something went wrong.