Skip to content

Commit 9997e7c

Browse files
author
graschik
committed
Initial commit. Add core functionality
0 parents  commit 9997e7c

File tree

17 files changed

+639
-0
lines changed

17 files changed

+639
-0
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Grasch\CheckoutLoginStep\Block\Checkout;
5+
6+
use Grasch\CheckoutLoginStep\Helper\Data as Helper;
7+
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
8+
use Magento\Customer\Model\Context as CustomerContext;
9+
use Magento\Customer\Model\Url;
10+
use Magento\Framework\App\Http\Context;
11+
use Magento\Framework\Stdlib\ArrayManager;
12+
use Magento\Framework\Url\Helper\Data;
13+
14+
class LoginStepProcessor implements LayoutProcessorInterface
15+
{
16+
/**
17+
* @var ArrayManager
18+
*/
19+
private ArrayManager $arrayManager;
20+
21+
/**
22+
* @var Context
23+
*/
24+
private Context $httpContext;
25+
26+
/**
27+
* @var string
28+
*/
29+
protected string $childrenStepsPath = 'components/checkout/children/steps';
30+
31+
/**
32+
* @var string
33+
*/
34+
protected string $customerEmailPath = 'components/checkout/children/steps' .
35+
'/children/shipping-step/children/shippingAddress/children/customer-email';
36+
37+
/**
38+
* @var string
39+
*/
40+
protected string $loginFormPath = 'components/checkout/children/steps/children/' .
41+
'login-step/children/login/children/login-form';
42+
43+
/**
44+
* @var Url
45+
*/
46+
private Url $customerUrl;
47+
48+
/**
49+
* @var Data
50+
*/
51+
private Data $coreUrl;
52+
53+
/**
54+
* @var Helper
55+
*/
56+
private Helper $helper;
57+
58+
/**
59+
* @param ArrayManager $arrayManager
60+
* @param Context $httpContext
61+
* @param Url $customerUrl
62+
* @param Data $coreUrl
63+
* @param Helper $helper
64+
*/
65+
public function __construct(
66+
ArrayManager $arrayManager,
67+
Context $httpContext,
68+
Url $customerUrl,
69+
Data $coreUrl,
70+
Helper $helper
71+
) {
72+
$this->arrayManager = $arrayManager;
73+
$this->httpContext = $httpContext;
74+
$this->customerUrl = $customerUrl;
75+
$this->coreUrl = $coreUrl;
76+
$this->helper = $helper;
77+
}
78+
79+
/**
80+
* @inheritdoc
81+
*/
82+
public function process($jsLayout): array
83+
{
84+
if (!$this->helper->isEnabled()) {
85+
return $jsLayout;
86+
}
87+
88+
if ($this->httpContext->getValue(CustomerContext::CONTEXT_AUTH)) {
89+
return $jsLayout;
90+
}
91+
92+
if (!$this->arrayManager->exists($this->childrenStepsPath, $jsLayout)) {
93+
return $jsLayout;
94+
}
95+
if (!$this->arrayManager->exists($this->customerEmailPath, $jsLayout)) {
96+
return $jsLayout;
97+
}
98+
99+
$jsLayout = $this->createLoginStepComponents($jsLayout);
100+
$jsLayout = $this->createLoginFormComponent($jsLayout);
101+
102+
return $jsLayout;
103+
}
104+
105+
/**
106+
* Create login form component
107+
*
108+
* @param array $jsLayout
109+
* @return array
110+
*/
111+
protected function createLoginFormComponent(array $jsLayout): array
112+
{
113+
$component = array_merge(
114+
$this->arrayManager->get($this->customerEmailPath, $jsLayout),
115+
[
116+
'component' => 'Grasch_CheckoutLoginStep/js/view/form/login',
117+
'template' => 'Grasch_CheckoutLoginStep/form/login',
118+
'displayArea' => 'login-form'
119+
]
120+
);
121+
122+
$jsLayout = $this->arrayManager->set($this->loginFormPath, $jsLayout, []);
123+
$jsLayout = $this->arrayManager->merge(
124+
$this->loginFormPath,
125+
$jsLayout,
126+
$component
127+
);
128+
129+
return $jsLayout;
130+
}
131+
132+
/**
133+
* Create login step components
134+
*
135+
* @param array $jsLayout
136+
* @return array
137+
*/
138+
protected function createLoginStepComponents(array $jsLayout): array
139+
{
140+
$createAccountComponent = [
141+
'component' => 'uiComponent',
142+
'template' => 'Grasch_CheckoutLoginStep/login/create-account',
143+
'displayArea' => 'create-account',
144+
'createAccountUrl' => $this->getCreateAccountUrl()
145+
];
146+
$proceedWithoutLoginComponent = [
147+
'component' => 'uiComponent',
148+
'template' => 'Grasch_CheckoutLoginStep/login/proceed-without-login',
149+
'displayArea' => 'proceed-without-login'
150+
];
151+
152+
return $this->arrayManager->merge(
153+
$this->childrenStepsPath . '/children',
154+
$jsLayout,
155+
[
156+
'login-step' => [
157+
'component' => 'uiComponent',
158+
'sortOrder' => 0,
159+
'children' => [
160+
'login' => [
161+
'component' => 'Grasch_CheckoutLoginStep/js/view/login',
162+
'template' => 'Grasch_CheckoutLoginStep/login',
163+
'sortOrder' => 0,
164+
'config' => [
165+
'deps' => [
166+
'checkout.sidebar.summary'
167+
]
168+
],
169+
'children' => [
170+
'create-account' => $createAccountComponent,
171+
'proceed-without-login' => $proceedWithoutLoginComponent
172+
]
173+
]
174+
]
175+
]
176+
]
177+
);
178+
}
179+
180+
/**
181+
* Get create account url
182+
*
183+
* @return string
184+
*/
185+
private function getCreateAccountUrl(): string
186+
{
187+
$url = $this->customerUrl->getRegisterUrl();
188+
$url = $this->coreUrl->addRequestParam($url, ['context' => 'checkout']);
189+
190+
return $url;
191+
}
192+
}

Helper/Data.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Grasch\CheckoutLoginStep\Helper;
5+
6+
use Magento\Framework\App\Helper\AbstractHelper;
7+
use Magento\Store\Model\ScopeInterface;
8+
9+
class Data extends AbstractHelper
10+
{
11+
public const IS_LOGIN_STEP_ENABLED = 'checkout/options/login_step/is_enabled';
12+
13+
/**
14+
* Check if module is enabled
15+
*
16+
* @return bool
17+
*/
18+
public function isEnabled(): bool
19+
{
20+
return $this->scopeConfig->isSetFlag(
21+
self::IS_LOGIN_STEP_ENABLED,
22+
ScopeInterface::SCOPE_STORES
23+
);
24+
}
25+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Aliaksandr Hrashchanka
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<h1 align="center">grasch/magento-2-checkout-login-step</h1>
2+
3+
<div align="center">
4+
<img src="https://img.shields.io/badge/magento-2.X-brightgreen.svg?logo=magento&longCache=true" alt="Supported Magento Versions" />
5+
<a href="https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity" target="_blank"><img src="https://img.shields.io/badge/maintained%3F-yes-brightgreen.svg" alt="Maintained - Yes" /></a>
6+
</div>
7+
8+
## Highlight features for module
9+
- <h3>You can add the login step on the checkout page.</h3>
10+
<img alt="Settings" src="docs/img/login-step.png" width="60%">
11+
12+
## How to install module?
13+
14+
### ✓ Install via composer (recommend)
15+
16+
Run the following commands in Magento 2 root folder:
17+
18+
```
19+
composer require grasch/module-checkout-login-step
20+
php bin/magento setup:upgrade
21+
php bin/magento setup:static-content:deploy
22+
```
23+
### ✓ Install via downloading
24+
25+
Download and copy files into `app/code/Grasch/CheckoutLoginStep` and run the following commands:
26+
```
27+
php bin/magento setup:upgrade
28+
php bin/magento setup:static-content:deploy
29+
```
30+
31+
## How to configure?
32+
- Go to Stores -> Configuration -> Sales -> Checkout -> Checkout Options -> Login Step Config.
33+
- Enable the module.
34+
35+
## The MIT License
36+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
37+

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "grasch/module-checkout-login-step",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.4.0",
7+
"magento/framework": "103.0.*"
8+
},
9+
"license": [
10+
"MIT"
11+
],
12+
"autoload": {
13+
"files": [
14+
"registration.php"
15+
],
16+
"psr-4": {
17+
"Grasch\\CheckoutLoginStep\\": ""
18+
}
19+
}
20+
}

docs/img/login-step.png

84.5 KB
Loading

etc/adminhtml/system.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
4+
<system>
5+
<section id="checkout">
6+
<group id="options">
7+
<group id="login_step" translate="label" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
8+
<label>Login Step Config</label>
9+
<field id="is_enabled" translate="label" type="select" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
10+
<label>Enabled</label>
11+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
12+
</field>
13+
</group>
14+
</group>
15+
</section>
16+
</system>
17+
</config>

etc/frontend/di.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
4+
<type name="Magento\Checkout\Block\Onepage">
5+
<arguments>
6+
<argument name="layoutProcessors" xsi:type="array">
7+
<item name="loginStepProcessor" xsi:type="object">Grasch\CheckoutLoginStep\Block\Checkout\LoginStepProcessor</item>
8+
</argument>
9+
</arguments>
10+
</type>
11+
</config>

etc/module.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4+
<module name="Grasch_CheckoutLoginStep">
5+
<sequence>
6+
<module name="Magento_Checkout"/>
7+
</sequence>
8+
</module>
9+
</config>

registration.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Magento\Framework\Component\ComponentRegistrar;
5+
6+
ComponentRegistrar::register(
7+
ComponentRegistrar::MODULE,
8+
'Grasch_CheckoutLoginStep',
9+
__DIR__
10+
);

0 commit comments

Comments
 (0)