Skip to content

Commit b1456cf

Browse files
author
Oleksandr Iegorov
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGETWO-81901
2 parents ab48104 + 1224795 commit b1456cf

File tree

45 files changed

+1935
-632
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1935
-632
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogUrlRewrite\Plugin\Store\Block;
7+
8+
use Magento\Framework\Data\Helper\PostHelper;
9+
use Magento\Store\Api\StoreResolverInterface;
10+
use Magento\Store\Model\Store;
11+
use Magento\UrlRewrite\Model\UrlFinderInterface;
12+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
13+
use Magento\Framework\App\Request\Http as HttpRequest;
14+
15+
/**
16+
* Plugin makes connection between Store and UrlRewrite modules
17+
* because Magento\Store\Block\Switcher should not know about UrlRewrite module functionality
18+
*/
19+
class Switcher
20+
{
21+
/**
22+
* @var PostHelper
23+
*/
24+
private $postHelper;
25+
26+
/**
27+
* @var UrlFinderInterface
28+
*/
29+
private $urlFinder;
30+
31+
/**
32+
* @var HttpRequest
33+
*/
34+
private $request;
35+
36+
/**
37+
* @param PostHelper $postHelper
38+
* @param UrlFinderInterface $urlFinder
39+
* @param HttpRequest $request
40+
*/
41+
public function __construct(
42+
PostHelper $postHelper,
43+
UrlFinderInterface $urlFinder,
44+
HttpRequest $request
45+
) {
46+
$this->postHelper = $postHelper;
47+
$this->urlFinder = $urlFinder;
48+
$this->request = $request;
49+
}
50+
51+
/**
52+
* @param \Magento\Store\Block\Switcher $subject
53+
* @param string $result
54+
* @param Store $store
55+
* @param array $data
56+
* @return string
57+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
58+
*/
59+
public function afterGetTargetStorePostData(
60+
\Magento\Store\Block\Switcher $subject,
61+
string $result,
62+
Store $store,
63+
array $data = []
64+
): string {
65+
$data[StoreResolverInterface::PARAM_NAME] = $store->getCode();
66+
67+
$currentUrl = $store->getCurrentUrl(true);
68+
$baseUrl = $store->getBaseUrl();
69+
$urlPath = parse_url($currentUrl, PHP_URL_PATH);
70+
71+
$urlToSwitch = $currentUrl;
72+
73+
//check only catalog pages
74+
if ($this->request->getFrontName() === 'catalog') {
75+
$currentRewrite = $this->urlFinder->findOneByData([
76+
UrlRewrite::REQUEST_PATH => ltrim($urlPath, '/'),
77+
UrlRewrite::STORE_ID => $store->getId(),
78+
]);
79+
if (null === $currentRewrite) {
80+
$urlToSwitch = $baseUrl;
81+
}
82+
}
83+
84+
return $this->postHelper->getPostData($urlToSwitch, $data);
85+
}
86+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="\Magento\Store\Block\Switcher">
10+
<plugin name="store_switcher_plugin" type="Magento\CatalogUrlRewrite\Plugin\Store\Block\Switcher"/>
11+
</type>
12+
</config>

app/code/Magento/Checkout/Block/Registration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getEmailAddress()
9191
*/
9292
public function getCreateAccountUrl()
9393
{
94-
return $this->getUrl('checkout/account/create');
94+
return $this->getUrl('checkout/account/delegateCreate');
9595
}
9696

9797
/**

app/code/Magento/Checkout/Controller/Account/Create.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
use Magento\Framework\Exception\AlreadyExistsException;
99
use Magento\Framework\Exception\NoSuchEntityException;
1010

11+
/**
12+
* @deprecated
13+
* @see DelegateCreate
14+
*/
1115
class Create extends \Magento\Framework\App\Action\Action
1216
{
1317
/**
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Checkout\Controller\Account;
10+
11+
use Magento\Framework\App\Action\Action;
12+
use Magento\Framework\App\Action\Context;
13+
use Magento\Checkout\Model\Session;
14+
use Magento\Sales\Api\OrderCustomerDelegateInterface;
15+
16+
/**
17+
* Redirect guest customer for registration.
18+
*/
19+
class DelegateCreate extends Action
20+
{
21+
/**
22+
* @var OrderCustomerDelegateInterface
23+
*/
24+
private $delegateService;
25+
26+
/**
27+
* @var Session
28+
*/
29+
private $session;
30+
31+
/**
32+
* @param Context $context
33+
* @param OrderCustomerDelegateInterface $customerDelegation
34+
* @param Session $session
35+
*/
36+
public function __construct(
37+
Context $context,
38+
OrderCustomerDelegateInterface $customerDelegation,
39+
Session $session
40+
) {
41+
parent::__construct($context);
42+
$this->delegateService = $customerDelegation;
43+
$this->session = $session;
44+
}
45+
46+
/**
47+
* @inheritDoc
48+
*/
49+
public function execute()
50+
{
51+
/** @var string|null $orderId */
52+
$orderId = $this->session->getLastOrderId();
53+
if (!$orderId) {
54+
return $this->resultRedirectFactory->create()->setPath('/');
55+
}
56+
57+
return $this->delegateService->delegateNew((int)$orderId);
58+
}
59+
}

app/code/Magento/Checkout/view/frontend/web/js/view/registration.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ define([
3838
},
3939

4040
/**
41-
* Create new user account
41+
* @return String
42+
*/
43+
getUrl: function () {
44+
return this.registrationUrl;
45+
},
46+
47+
/**
48+
* Create new user account.
49+
*
50+
* @deprecated
4251
*/
4352
createAccount: function () {
4453
this.creationStarted(true);

app/code/Magento/Checkout/view/frontend/web/template/registration.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
<!-- ko if: isFormVisible -->
1212
<p data-bind="i18n: 'You can track your order status by creating an account.'"></p>
1313
<p><span data-bind="i18n: 'Email Address'"></span>: <span data-bind="text: getEmailAddress()"></span></p>
14-
<form method="post" data-bind="submit: createAccount">
15-
<input type="submit" class="action primary" data-bind="value: $t('Create an Account'), disable: creationStarted" />
14+
<form method="get" data-bind="attr: { action: getUrl() }">
15+
<input type="submit" class="action primary" data-bind="value: $t('Create an Account')" />
1616
</form>
17-
<!-- /ko -->
18-
<!-- ko if: accountCreated -->
19-
<p data-bind="i18n: 'A letter with further instructions will be sent to your email.'"></p>
20-
<!-- /ko -->
17+
<!--/ko-->
2118
</div>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\Customer\Api;
11+
12+
use Magento\Customer\Api\Data\CustomerInterface;
13+
use Magento\Framework\Controller\Result\Redirect;
14+
15+
/**
16+
* Delegating account actions from outside of customer module.
17+
*/
18+
interface AccountDelegationInterface
19+
{
20+
/**
21+
* Create redirect to default new account form.
22+
*
23+
* @param CustomerInterface $customer Pre-filled customer data.
24+
* @param array|null $mixedData Add this data to new-customer event
25+
* if the new customer is created.
26+
*
27+
* @return Redirect
28+
*/
29+
public function createRedirectForNew(
30+
CustomerInterface $customer,
31+
array $mixedData = null
32+
): Redirect;
33+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\Customer\Model\Delegation;
11+
12+
use Magento\Customer\Api\Data\CustomerInterface;
13+
use Magento\Customer\Api\AccountDelegationInterface;
14+
use Magento\Framework\Controller\Result\Redirect;
15+
use Magento\Framework\Controller\Result\RedirectFactory;
16+
17+
/**
18+
* @inheritDoc
19+
*/
20+
class AccountDelegation implements AccountDelegationInterface
21+
{
22+
/**
23+
* @var RedirectFactory
24+
*/
25+
private $redirectFactory;
26+
27+
/**
28+
* @var Storage
29+
*/
30+
private $storage;
31+
32+
/**
33+
* @param RedirectFactory $redirectFactory
34+
* @param Storage $storage
35+
*/
36+
public function __construct(
37+
RedirectFactory $redirectFactory,
38+
Storage $storage
39+
) {
40+
$this->redirectFactory = $redirectFactory;
41+
$this->storage = $storage;
42+
}
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
public function createRedirectForNew(
48+
CustomerInterface $customer,
49+
array $mixedData = null
50+
): Redirect {
51+
$this->storage->storeNewOperation($customer, $mixedData);
52+
53+
return $this->redirectFactory->create()
54+
->setPath('customer/account/create');
55+
}
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\Customer\Model\Delegation\Data;
11+
12+
use Magento\Customer\Api\Data\CustomerInterface;
13+
14+
/**
15+
* Data required for delegated new-account operation.
16+
*/
17+
class NewOperation
18+
{
19+
/**
20+
* @var CustomerInterface
21+
*/
22+
private $customer;
23+
24+
/**
25+
* @var array
26+
*/
27+
private $additionalData;
28+
29+
/**
30+
* @param CustomerInterface $customer
31+
* @param array $additionalData
32+
*/
33+
public function __construct(
34+
CustomerInterface $customer,
35+
array $additionalData
36+
) {
37+
$this->customer = $customer;
38+
$this->additionalData = $additionalData;
39+
}
40+
41+
/**
42+
* @return CustomerInterface
43+
*/
44+
public function getCustomer(): CustomerInterface
45+
{
46+
return $this->customer;
47+
}
48+
49+
/**
50+
* @return array
51+
*/
52+
public function getAdditionalData(): array
53+
{
54+
return $this->additionalData;
55+
}
56+
}

0 commit comments

Comments
 (0)