-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
e3e76bd
commit 53b175c
Showing
12 changed files
with
421 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,184 @@ | ||
<?php | ||
|
||
namespace MageGuide\Skroutz\Block; | ||
|
||
/** | ||
* Block class for order success page | ||
* @package MageGuide_Skroutz | ||
* @module Skroutz | ||
* @author MageGuide Developer | ||
*/ | ||
class SkroutzSuccess extends \Magento\Framework\View\Element\Template | ||
{ | ||
/** | ||
* @var \Magento\Checkout\Model\Session | ||
*/ | ||
protected $_checkoutSession; | ||
|
||
/** | ||
* @var \Magento\Sales\Model\OrderFactory | ||
*/ | ||
protected $_orderFactory; | ||
|
||
/** | ||
* @var \Magento\Catalog\Model\Product | ||
*/ | ||
protected $_product; | ||
|
||
/** | ||
* @var \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable | ||
*/ | ||
protected $_catalogProductTypeConfigurable; | ||
|
||
/** | ||
* @var \Magento\Framework\App\Config\ScopeConfigInterface | ||
*/ | ||
protected $_scopeConfig; | ||
|
||
/** | ||
* @var \Magento\Sales\Model\Order | ||
*/ | ||
protected $_order; | ||
|
||
/** | ||
* constructor class | ||
* | ||
* @param \Magento\Checkout\Model\Session $checkoutSession | ||
* @param \Magento\Sales\Model\OrderFactory $orderFactory | ||
* @param \Magento\Catalog\Model\Product $product | ||
* @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $catalogProductTypeConfigurable | ||
* @param \Magento\Framework\View\Element\Template\Context $context | ||
*/ | ||
public function __construct( | ||
\Magento\Checkout\Model\Session $checkoutSession, | ||
\Magento\Sales\Model\OrderFactory $orderFactory, | ||
\Magento\Catalog\Model\Product $product, | ||
\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $catalogProductTypeConfigurable, | ||
\Magento\Framework\View\Element\Template\Context $context) | ||
{ | ||
$this->_checkoutSession = $checkoutSession; | ||
$this->_orderFactory = $orderFactory; | ||
$this->_product = $product; | ||
$this->_catalogProductTypeConfigurable = $catalogProductTypeConfigurable; | ||
$this->_scopeConfig = $context->getScopeConfig(); | ||
|
||
if ($this->_checkoutSession->getLastRealOrderId()) { | ||
$this->_order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId()); | ||
} | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Returns the id of the last order | ||
* | ||
* @return integer|boolean | ||
*/ | ||
public function getRealOrderId() | ||
{ | ||
$order = $this->_order; | ||
if ($order) { | ||
$lastorderId = $order->getId(); | ||
return $lastorderId; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the order subtotal with added tax and shipping fee | ||
* | ||
* @return string|boolean | ||
*/ | ||
public function getPrice() | ||
{ | ||
$order = $this->_order; | ||
if ($order) { | ||
$price = number_format($order->getSubtotalInclTax() + $order->getShippingInclTax(), 2); | ||
return $price; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the order shipping fee | ||
* | ||
* @return string|boolean | ||
*/ | ||
public function getShippingCost() | ||
{ | ||
$order = $this->_order; | ||
if ($order) { | ||
$shippingCost = number_format($order->getShippingInclTax(), 2); | ||
return $shippingCost; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the order tax amount | ||
* | ||
* @return string|boolean | ||
*/ | ||
public function getTaxAmount() | ||
{ | ||
$order = $this->_order; | ||
if ($order) { | ||
$revenuefortax = $order->getSubtotalInclTax() + $order->getShippingInclTax(); | ||
$taxtotal = $revenuefortax / 1.24; | ||
$taxAmountAlmost = $revenuefortax - $taxtotal; | ||
$taxAmount = number_format($taxAmountAlmost, 2); | ||
return $taxAmount; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns all order items | ||
* | ||
* @return array|boolean | ||
*/ | ||
public function getAllOrderVisibleItems() | ||
{ | ||
$order = $this->_order; | ||
if ($order) { | ||
$items = $order->getAllVisibleItems(); | ||
return $items; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the id of a product given the sku | ||
* | ||
* @return integer|boolean | ||
*/ | ||
public function getChildId($sku) | ||
{ | ||
return $this->_product->getIdBySku($sku); | ||
} | ||
|
||
/** | ||
* Returns the id of a parent configurable product given the id of a child simple product | ||
* | ||
* @return integer|boolean | ||
*/ | ||
public function getParentId($childId) | ||
{ | ||
$parentByChild = $this->_catalogProductTypeConfigurable->getParentIdsByChild($childId); | ||
if(isset($parentByChild[0])){ | ||
$parentId = $parentByChild[0]; | ||
return $parentId; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns the sku of a product given the id | ||
* | ||
* @return string|boolean | ||
*/ | ||
public function getSkuFromId($productId) | ||
{ | ||
return $this->_product->load($productId)->getSku(); | ||
} | ||
|
||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace MageGuide\Skroutz\Helper; | ||
|
||
/** | ||
* Helper class | ||
* @package MageGuide_Skroutz | ||
* @module Skroutz | ||
* @author MageGuide Developer | ||
*/ | ||
class Data extends \Magento\Framework\App\Helper\AbstractHelper | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $_skroutzOptions; | ||
|
||
/** | ||
* Data constructor. | ||
* @param \Magento\Framework\App\Helper\Context $context | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Helper\Context $context | ||
) { | ||
parent::__construct($context); | ||
$this->_skroutzOptions = $this->scopeConfig->getValue('mageguide_skroutz', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function getIsActive() | ||
{ | ||
return $this->_skroutzOptions['general']['status']; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getProgramID() | ||
{ | ||
return trim($this->_skroutzOptions['general']['program_id']); | ||
} | ||
|
||
} | ||
|
||
?> |
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,24 @@ | ||
{ | ||
"name": "mageguide/skroutz", | ||
"description": "Add Skroutz Tracking Code to your Magento 2 E-shop", | ||
"require": { | ||
"php": "~7.0.0", | ||
"magento/framework": "100.*|101.*", | ||
"magento/module-ui": "100.*|101.*", | ||
"magento/module-config": "100.*|101.*", | ||
"magento/module-directory": "100.*|101.*", | ||
"mageguide/mgbase": "1.*" | ||
}, | ||
"type": "magento2-module", | ||
"version": "1.0.0", | ||
"license": [ | ||
"OSL-3.0", | ||
"AFL-3.0" | ||
], | ||
"autoload": { | ||
"files": [ "registration.php" ], | ||
"psr-4": { | ||
"MageGuide\\Skroutz\\": "" | ||
} | ||
} | ||
} |
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,21 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd"> | ||
<acl> | ||
<resources> | ||
<resource id="Magento_Backend::admin"> | ||
<resource id="Magento_Backend::stores"> | ||
<resource id="Magento_Backend::stores_settings"> | ||
<resource id="Magento_Config::config"> | ||
<resource id="MageGuide_Skroutz::config" title="MageGuide Skroutz" sortOrder="10" /> | ||
</resource> | ||
</resource> | ||
</resource> | ||
<resource id="MageGuide_Mgbase::MageGuide" > | ||
<resource id="MageGuide_Skroutz::Skroutz_Label" sortOrder="80" title="MageGuide Skroutz" > | ||
<resource id="MageGuide_Skroutz::Skroutz" sortOrder="1" title="Skroutz Configuration" /> | ||
</resource> | ||
</resource> | ||
</resource> | ||
</resources> | ||
</acl> | ||
</config> |
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 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd"> | ||
<menu> | ||
<add | ||
id="MageGuide_Skroutz::Skroutz_Label" | ||
title="MageGuide Skroutz" | ||
module="MageGuide_Skroutz" | ||
sortOrder="80" | ||
parent="MageGuide_Mgbase::MageGuide" | ||
resource="MageGuide_Skroutz::Skroutz_Label" | ||
/> | ||
<add | ||
id="MageGuide_Skroutz::Skroutz" | ||
title="Skroutz Analytics Configuration" | ||
module="MageGuide_Skroutz" | ||
action="adminhtml/system_config/edit/section/mageguide_skroutz/" | ||
sortOrder="1" | ||
parent="MageGuide_Skroutz::Skroutz_Label" | ||
resource="MageGuide_Skroutz::Skroutz" | ||
/> | ||
</menu> | ||
</config> |
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,27 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © 2017 MageGuide. All rights reserved. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<section id="mageguide_skroutz" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<label>Skroutz</label> | ||
<tab>mageguide</tab> | ||
<resource>MageGuide_Skroutz::config</resource> | ||
<group id="general" translate="label" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<label>General Settings</label> | ||
<field id="status" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<label>Enabled</label> | ||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> | ||
</field> | ||
<field id="program_id" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<label>Program ID</label> | ||
<!--<validate>required-entry</validate>--> | ||
<comment>Please enter Skroutz Merchant ID.</comment> | ||
</field> | ||
</group> | ||
</section> | ||
</system> | ||
</config> |
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,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="MageGuide_Skroutz" setup_version="1.0.0"> | ||
<sequence> | ||
<module name="MageGuide_Mgbase"/> | ||
</sequence> | ||
</module> | ||
</config> |
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,7 @@ | ||
<?php | ||
|
||
use \Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'MageGuide_Skroutz', __DIR__); | ||
|
||
?> |
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,7 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<referenceContainer name="before.body.end"> | ||
<block class="MageGuide\Skroutz\Block\SkroutzSuccess" template="MageGuide_Skroutz::skroutz-success.phtml" name="skroutz" /> | ||
</referenceContainer> | ||
</page> | ||
|
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,8 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="before.body.end"> | ||
<block class="Magento\Framework\View\Element\Template" template="MageGuide_Skroutz::skroutz-body.phtml" name="skroutz" /> | ||
</referenceContainer> | ||
</body> | ||
</page> |
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,21 @@ | ||
<?php | ||
|
||
$_helper = $this->helper('MageGuide\Skroutz\Helper\Data'); | ||
$isActive = $_helper->getIsActive(); | ||
$programID = $_helper->getProgramID(); | ||
|
||
if ($isActive && $programID != ""): | ||
?> | ||
|
||
<!-- SKROUTZ ANALYTICS CODE start --> | ||
<script> | ||
(function(a,b,c,d,e,f,g){a[e]= a[e] || function(){ | ||
(a[e].q = a[e].q || []).push(arguments);};f=b.createElement(c);f.async=true; | ||
f.src=d;g=b.getElementsByTagName(c)[0];g.parentNode.insertBefore(f,g); | ||
})(window,document,'script','https://analytics.skroutz.gr/analytics.min.js','sa'); | ||
|
||
sa('session', 'connect', '<?php echo $programID; ?>'); // Connect your Account. | ||
</script> | ||
<!-- SKROUTZ ANALYTICS CODE end --> | ||
|
||
<?php endif; ?> |
Oops, something went wrong.