Skip to content

Commit 9c8d4a9

Browse files
committedAug 4, 2019
Add extension
0 parents  commit 9c8d4a9

File tree

6 files changed

+282
-0
lines changed

6 files changed

+282
-0
lines changed
 
+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Ecomteck
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Ecomteck.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://ecomteck.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Ecomteck
17+
* @package Ecomteck_OneStepCheckoutCompatible
18+
* @copyright Copyright (c) 2018 Ecomteck (https://ecomteck.com/)
19+
* @license https://ecomteck.com/LICENSE.txt
20+
*/
21+
namespace Ecomteck\OneStepCheckoutCompatible\Block\Checkout;
22+
23+
24+
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
25+
use Magento\Framework\App\Config\ScopeConfigInterface;
26+
use Magento\Store\Model\ScopeInterface;
27+
use \Magento\Framework\Module\Manager as ModuleManager;
28+
use Magento\Customer\Model\AttributeMetadataDataProvider;
29+
use Magento\Ui\Component\Form\AttributeMapper;
30+
use Magento\Checkout\Block\Checkout\AttributeMerger;
31+
use Magento\Checkout\Model\Session as CheckoutSession;
32+
use Magento\Framework\Stdlib\ArrayManager;
33+
class OneStepCheckoutProcessor implements LayoutProcessorInterface
34+
{
35+
const CONFIG_ENABLE_MAGEWORX_MULTIFEES = 'mageworx_multifees/main/enable_cart';
36+
37+
/**
38+
* @var ScopeConfigInterface
39+
*/
40+
private $scopeConfig;
41+
42+
/**
43+
* @var ScopeConfigInterface
44+
*/
45+
private $moduleManager;
46+
47+
/**
48+
* @var CheckoutSession
49+
*/
50+
public $checkoutSession;
51+
52+
/**
53+
* @var null
54+
*/
55+
public $quote = null;
56+
57+
/**
58+
* One step checkout helper
59+
*
60+
* @var \Ecomteck\OneStepCheckout\Helper\Config
61+
*/
62+
protected $_config;
63+
64+
protected $request;
65+
66+
/**
67+
* @param ScopeConfigInterface $scopeConfig
68+
* @param ModuleManager $moduleManager
69+
* @param CheckoutSession $checkoutSession
70+
* @param \Ecomteck\OneStepCheckout\Helper\Config $config
71+
* @param \Magento\Framework\App\Request\Http $request
72+
* @param ArrayManager $arrayManager
73+
*/
74+
public function __construct(
75+
ScopeConfigInterface $scopeConfig,
76+
ModuleManager $moduleManager,
77+
CheckoutSession $checkoutSession,
78+
\Ecomteck\OneStepCheckout\Helper\Config $config,
79+
\Magento\Framework\App\Request\Http $request,
80+
ArrayManager $arrayManager
81+
)
82+
{
83+
$this->scopeConfig = $scopeConfig;
84+
$this->moduleManager = $moduleManager;
85+
$this->checkoutSession = $checkoutSession;
86+
$this->arrayManager = $arrayManager;
87+
$this->_config = $config;
88+
$this->request = $request;
89+
}
90+
91+
/**
92+
* Changes cart items to be above totals in the cart summary.
93+
*
94+
* @param array $jsLayout
95+
* @return array
96+
*/
97+
private function modifyMageWorxMultiFees($jsLayout)
98+
{
99+
if(!$this->moduleManager->isOutputEnabled('MageWorx_MultiFees')){
100+
return $jsLayout;
101+
}
102+
if ($this->scopeConfig->getValue(self::CONFIG_ENABLE_MAGEWORX_MULTIFEES, ScopeInterface::SCOPE_STORE)) {
103+
$path = 'components/checkout/children/steps/children/shipping-step/children/shippingAddress/children/shippingAdditional/children/mageworx-shipping-fee-form-container';
104+
if($this->arrayManager->get($path, $jsLayout)){
105+
$jsLayout = $this->arrayManager->set($path.'/component', $jsLayout,'Ecomteck_OneStepCheckoutCompatible/js/MageWorx/MultiFees/view/shipping-fee');
106+
}
107+
}
108+
return $jsLayout;
109+
}
110+
111+
/**
112+
* {@inheritdoc}
113+
*/
114+
public function process($jsLayout)
115+
{
116+
if (!$this->_config->isEnabled()) {
117+
return $jsLayout;
118+
}
119+
120+
$jsLayout = $this->modifyMageWorxMultiFees($jsLayout);
121+
122+
return $jsLayout;
123+
}
124+
}

‎composer.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "ecomteck/module-one-step-checkout-compatible",
3+
"description": "Magento 2 One Step Checkout Compatible With other extension.",
4+
"type": "magento2-module",
5+
"license": "MIT",
6+
"autoload": {
7+
"files": [
8+
"registration.php"
9+
],
10+
"psr-4": {
11+
"Ecomteck\\OneStepCheckoutCompatible\\": ""
12+
}
13+
}
14+
}

‎etc/frontend/di.xml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Ecomteck
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Ecomteck.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://ecomteck.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category Ecomteck
18+
* @package Ecomteck_OneStepCheckout
19+
* @copyright Copyright (c) 2018 Ecomteck (https://ecomteck.com/)
20+
* @license https://ecomteck.com/LICENSE.txt
21+
*/
22+
-->
23+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
24+
<type name="Magento\Checkout\Block\Onepage">
25+
<arguments>
26+
<argument name="layoutProcessors" xsi:type="array">
27+
<item name="onestepcheckout_compatible" xsi:type="object">Ecomteck\OneStepCheckoutCompatible\Block\Checkout\OneStepCheckoutProcessor</item>
28+
</argument>
29+
</arguments>
30+
</type>
31+
</config>

‎etc/module.xml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Ecomteck
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Ecomteck.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://ecomteck.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category Ecomteck
18+
* @package Ecomteck_OneStepCheckoutCompatible
19+
* @copyright Copyright (c) 2019 Ecomteck (https://ecomteck.com/)
20+
* @license https://ecomteck.com/LICENSE.txt
21+
*/
22+
-->
23+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
24+
<module name="Ecomteck_OneStepCheckoutCompatible" setup_version="1.0.0">
25+
<sequence>
26+
<module name="Ecomteck_OneStepCheckout" />
27+
</sequence>
28+
</module>
29+
</config>

‎registration.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Ecomteck
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Ecomteck.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://ecomteck.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Ecomteck
17+
* @package Ecomteck_OneStepCheckoutCompatible
18+
* @copyright Copyright (c) 2019 Ecomteck (https://ecomteck.com/)
19+
* @license https://ecomteck.com/LICENSE.txt
20+
*/
21+
use Magento\Framework\Component\ComponentRegistrar;
22+
23+
ComponentRegistrar::register(
24+
ComponentRegistrar::MODULE,
25+
'Ecomteck_OneStepCheckoutCompatible',
26+
__DIR__
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright © MageWorx. All rights reserved.
3+
* See LICENSE.txt for license details.
4+
*/
5+
define([
6+
'jquery',
7+
'MageWorx_MultiFees/js/view/shipping-fee',
8+
'Magento_Checkout/js/action/get-totals'
9+
], function ($,ShippingFee,getTotalsAction) {
10+
'use strict';
11+
$(document).ajaxSuccess(function(event, xhr, settings) {
12+
if ( settings.url.indexOf("multifees/checkout/fee") >=0) {
13+
getTotalsAction(function(){});
14+
}
15+
});
16+
return ShippingFee.extend({
17+
/**
18+
* Update shipping fees by selected shipping method
19+
*
20+
* @param code
21+
* @returns {exports}
22+
*/
23+
updateContent: function (code) {
24+
var content = this.reloadData(code),
25+
self = this,
26+
fieldset = self.getChild('mageworx-shipping-fee-form-fieldset');
27+
28+
content.done(function (components) {
29+
fieldset = self.getChild('mageworx-shipping-fee-form-fieldset');
30+
// Before we do update elements in the from we are destroying the old ones
31+
if (fieldset.elems) {
32+
fieldset.destroyChildren();
33+
}
34+
35+
// When components are updated we should check is form should be visible
36+
// or not (empty elements or just hidden inputs)
37+
var visibleComponents = _.isEmpty(components) ?
38+
[] :
39+
components.filter(function (component) {
40+
return component.isVisibleInputType;
41+
}),
42+
wholeFormVisibility = !_.isEmpty(visibleComponents);
43+
44+
self.shouldShow(wholeFormVisibility);
45+
self.childCandidates = components;
46+
_.forEach(components, function (o, i) {
47+
o.index = i;
48+
components[i] = require(o.component)(_.extend(o, o.config));
49+
});
50+
fieldset.insertChild(components);
51+
});
52+
53+
return this;
54+
}
55+
});
56+
});
57+

0 commit comments

Comments
 (0)
Please sign in to comment.