Skip to content

Commit ea9731b

Browse files
authored
Merge pull request #1 from ecomteck/dev
updated code compatible for Mageplaza_SocialLogin extension
2 parents bbdd87d + ad6a5cb commit ea9731b

File tree

7 files changed

+233
-2
lines changed

7 files changed

+233
-2
lines changed

Block/Checkout/OneStepCheckoutProcessor.php

+45-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class OneStepCheckoutProcessor implements LayoutProcessorInterface
3434
{
3535
const CONFIG_ENABLE_MAGEWORX_MULTIFEES = 'mageworx_multifees/main/enable_cart';
3636

37+
const CONFIG_ENABLE_MAGEPLAZA_SOCIALLOGIN = 'sociallogin/general/enabled';
38+
3739
/**
3840
* @var ScopeConfigInterface
3941
*/
@@ -63,21 +65,25 @@ class OneStepCheckoutProcessor implements LayoutProcessorInterface
6365

6466
protected $request;
6567

68+
protected $_moduleList;
69+
6670
/**
6771
* @param ScopeConfigInterface $scopeConfig
6872
* @param ModuleManager $moduleManager
6973
* @param CheckoutSession $checkoutSession
7074
* @param \Ecomteck\OneStepCheckout\Helper\Config $config
7175
* @param \Magento\Framework\App\Request\Http $request
7276
* @param ArrayManager $arrayManager
77+
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
7378
*/
7479
public function __construct(
7580
ScopeConfigInterface $scopeConfig,
7681
ModuleManager $moduleManager,
7782
CheckoutSession $checkoutSession,
7883
\Ecomteck\OneStepCheckout\Helper\Config $config,
7984
\Magento\Framework\App\Request\Http $request,
80-
ArrayManager $arrayManager
85+
ArrayManager $arrayManager,
86+
\Magento\Framework\Module\ModuleListInterface $moduleList
8187
)
8288
{
8389
$this->scopeConfig = $scopeConfig;
@@ -86,8 +92,24 @@ public function __construct(
8692
$this->arrayManager = $arrayManager;
8793
$this->_config = $config;
8894
$this->request = $request;
95+
$this->_moduleList = $moduleList;
8996
}
9097

98+
/**
99+
* Check the module was installed on magento 2 site or not
100+
* @param string $moduleName
101+
* @return boolean
102+
*/
103+
public function checkModuleInstalled($moduleName){
104+
$is_installed = $this->_moduleList->has($moduleName);
105+
if($is_installed) {
106+
if(!$this->moduleManager->isOutputEnabled($moduleName)){
107+
$is_installed = false;
108+
}
109+
}
110+
111+
return $is_installed;
112+
}
91113
/**
92114
* Changes cart items to be above totals in the cart summary.
93115
*
@@ -96,7 +118,7 @@ public function __construct(
96118
*/
97119
private function modifyMageWorxMultiFees($jsLayout)
98120
{
99-
if(!$this->moduleManager->isOutputEnabled('MageWorx_MultiFees')){
121+
if(!$this->checkModuleInstalled("MageWorx_MultiFees")){
100122
return $jsLayout;
101123
}
102124
if ($this->scopeConfig->getValue(self::CONFIG_ENABLE_MAGEWORX_MULTIFEES, ScopeInterface::SCOPE_STORE)) {
@@ -108,6 +130,25 @@ private function modifyMageWorxMultiFees($jsLayout)
108130
return $jsLayout;
109131
}
110132

133+
/**
134+
* Override mageplaza social login to display social login on checkout page
135+
*
136+
* @param array $jsLayout
137+
* @return array
138+
*/
139+
private function modifyMageplazaSocialLogin($jsLayout)
140+
{
141+
if(!$this->checkModuleInstalled("Mageplaza_SocialLogin")){
142+
return $jsLayout;
143+
}
144+
if ($this->scopeConfig->getValue(self::CONFIG_ENABLE_MAGEPLAZA_SOCIALLOGIN, ScopeInterface::SCOPE_STORE)) {
145+
$path = 'components/checkout/children/steps/children/shipping-step/children/shippingAddress/children/social-login';
146+
$jsLayout = $this->arrayManager->set($path.'/component', $jsLayout,'Ecomteck_OneStepCheckoutCompatible/js/Mageplaza/SocialLogin/view/social-buttons');
147+
$jsLayout = $this->arrayManager->set($path.'/displayArea', $jsLayout,'social-login');
148+
}
149+
return $jsLayout;
150+
}
151+
111152
/**
112153
* {@inheritdoc}
113154
*/
@@ -118,6 +159,8 @@ public function process($jsLayout)
118159
}
119160

120161
$jsLayout = $this->modifyMageWorxMultiFees($jsLayout);
162+
163+
$jsLayout = $this->modifyMageplazaSocialLogin($jsLayout);
121164

122165
return $jsLayout;
123166
}

composer.json

100644100755
File mode changed.

etc/frontend/di.xml

100644100755
File mode changed.
+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_OneStepCheckoutCompatible
19+
* @copyright Copyright (c) 2019 Ecomteck (https://ecomteck.com/)
20+
* @license https://ecomteck.com/LICENSE.txt
21+
*/
22+
-->
23+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
24+
<body>
25+
<referenceBlock name="social-login-popup-authentication-social">
26+
<action method="setTemplate">
27+
<argument name="template" xsi:type="string">Ecomteck_OneStepCheckoutCompatible::Mageplaza/SocialLogin/popup/form/authentication/social.phtml</argument>
28+
</action>
29+
</referenceBlock>
30+
</body>
31+
</page>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.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 Mageplaza
17+
* @package Mageplaza_SocialLogin
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
use Mageplaza\SocialLogin\Model\System\Config\Source\Position;
23+
24+
?>
25+
<?php $availableSocials = $block->getAvailableSocials(); ?>
26+
<?php if (sizeof($availableSocials)) : ?>
27+
<div class="block social-login-authentication-channel col-mp mp-5">
28+
<div class="block-title">
29+
<?= __('Or Sign In With') ?>
30+
</div>
31+
<div class="block-content">
32+
<?php foreach ($availableSocials as $key => $social) : ?>
33+
<div class="actions-toolbar social-btn <?= $key ?>-login">
34+
<a class="btn btn-block btn-social btn-<?= $block->getBtnKey($key) ?>"
35+
data-mage-init='{"socialProvider": {"url": "<?= $social['login_url'] ?>", "label": "<?= __('Login By %1', $social['label']) ?>"}}'>
36+
<span class="fa fa-<?= $block->getBtnKey($key) ?>"></span>
37+
<?= __('Sign in with %1', $social['label']) ?>
38+
</a>
39+
</div>
40+
<?php endforeach; ?>
41+
</div>
42+
</div>
43+
<script type="text/javascript">
44+
require(['jquery'], function ($) {
45+
$('#social-login-authentication').removeClass('mp-12').addClass('mp-7');
46+
});
47+
</script>
48+
<?php endif; ?>
49+
50+
<?php
51+
/**
52+
* Add variable to show social buttons on customer authentication popup
53+
*/
54+
?>
55+
<?php $authenConfig = $block->getSocialButtonsConfig(); ?>
56+
<?php if (sizeof($availableSocials)) : ?>
57+
<script>
58+
window.socialAuthenticationPopup = <?= Zend_Json::encode($authenConfig); ?>;
59+
</script>
60+
<?php endif; ?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Ecomteck
3+
*
4+
* NOTICE OF LICENSE
5+
*
6+
* This source file is subject to the Ecomteck.com license that is
7+
* available through the world-wide-web at this URL:
8+
* https://ecomteck.com/LICENSE.txt
9+
*
10+
* DISCLAIMER
11+
*
12+
* Do not edit or add to this file if you wish to upgrade this extension to newer
13+
* version in the future.
14+
*
15+
* @category Ecomteck
16+
* @package Ecomteck_SocialLogin
17+
* @copyright Copyright (c) 2018 Ecomteck (https://ecomteck.com/)
18+
* @license https://ecomteck.com/LICENSE.txt
19+
*/
20+
/*jshint browser:true jquery:true*/
21+
/*global alert*/
22+
define(
23+
[
24+
'jquery',
25+
'ko',
26+
'uiComponent',
27+
'socialProvider'
28+
],
29+
function ($, ko, Component, socialProvider) {
30+
'use strict';
31+
32+
ko.bindingHandlers.socialButton = {
33+
init: function (element, valueAccessor, allBindings) {
34+
var config = {
35+
url: allBindings.get('url'),
36+
label: allBindings.get('label')
37+
};
38+
39+
socialProvider(config, element);
40+
}
41+
};
42+
43+
return Component.extend({
44+
defaults: {
45+
template: 'Ecomteck_OneStepCheckoutCompatible/Mageplaza/SocialLogin/social-buttons'
46+
},
47+
buttonLists: window.socialAuthenticationPopup,
48+
49+
socials: function () {
50+
var socials = [];
51+
52+
$.each(this.buttonLists, function (key, social) {
53+
socials.push(social);
54+
});
55+
56+
return socials;
57+
},
58+
59+
isActive: function () {
60+
return (typeof this.buttonLists !== 'undefined');
61+
}
62+
});
63+
}
64+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
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+
-->
22+
23+
<!-- ko if: isActive() -->
24+
<div class="block social-login-authentication-popup">
25+
<div class="block-content" data-bind="foreach: socials()">
26+
<div class="actions-toolbar social-btn" data-bind="css: key + '-login'">
27+
<a class="btn btn-block btn-social" style="height:20px" data-bind="css: 'btn-' + btn_key, socialButton: $parent.isActive, url: url, label: label">
28+
<span class="fab fa-3x" data-bind="css: 'fa-' + btn_key"></span>
29+
</a>
30+
</div>
31+
</div>
32+
</div>
33+
<!-- /ko -->

0 commit comments

Comments
 (0)