-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1170 from magento-okapis/2.2-develop-pr-1
[Okapis] Bugs P1
- Loading branch information
Showing
24 changed files
with
1,444 additions
and
50 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,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Integration\Cron; | ||
|
||
use Magento\Integration\Model\ResourceModel\Oauth\Token as TokenResourceModel; | ||
use Magento\Authorization\Model\UserContextInterface; | ||
use Magento\Integration\Helper\Oauth\Data as OauthHelper; | ||
|
||
/** | ||
* Cron class for deleting expired OAuth tokens. | ||
*/ | ||
class CleanExpiredTokens | ||
{ | ||
/** | ||
* @var TokenResourceModel | ||
*/ | ||
private $tokenResourceModel; | ||
|
||
/** | ||
* @var OauthHelper | ||
*/ | ||
private $oauthHelper; | ||
|
||
/** | ||
* Initialize dependencies. | ||
* | ||
* @param TokenResourceModel $tokenResourceModel | ||
* @param OauthHelper $oauthHelper | ||
*/ | ||
public function __construct( | ||
TokenResourceModel $tokenResourceModel, | ||
OauthHelper $oauthHelper | ||
) { | ||
$this->tokenResourceModel = $tokenResourceModel; | ||
$this->oauthHelper = $oauthHelper; | ||
} | ||
|
||
/** | ||
* Delete expired customer and admin tokens. | ||
* | ||
* @return void | ||
*/ | ||
public function execute() | ||
{ | ||
$this->tokenResourceModel->deleteExpiredTokens( | ||
$this->oauthHelper->getAdminTokenLifetime(), | ||
[UserContextInterface::USER_TYPE_ADMIN] | ||
); | ||
$this->tokenResourceModel->deleteExpiredTokens( | ||
$this->oauthHelper->getCustomerTokenLifetime(), | ||
[UserContextInterface::USER_TYPE_CUSTOMER] | ||
); | ||
} | ||
} |
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
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
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
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
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
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
118 changes: 118 additions & 0 deletions
118
app/code/Magento/Persistent/Model/Checkout/GuestPaymentInformationManagementPlugin.php
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,118 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Persistent\Model\Checkout; | ||
|
||
use Magento\Checkout\Model\GuestPaymentInformationManagement; | ||
use Magento\Checkout\Model\Session; | ||
|
||
/** | ||
* Plugin to convert shopping cart from persistent cart to guest cart before order save when customer not logged in | ||
*/ | ||
class GuestPaymentInformationManagementPlugin | ||
{ | ||
/** | ||
* Persistence Session Helper | ||
* | ||
* @var \Magento\Persistent\Helper\Session | ||
*/ | ||
private $persistenceSessionHelper; | ||
|
||
/** | ||
* Persistence Data Helper | ||
* | ||
* @var \Magento\Persistent\Helper\Data | ||
*/ | ||
private $persistenceDataHelper; | ||
|
||
/** | ||
* Customer Session | ||
* | ||
* @var \Magento\Customer\Model\Session | ||
*/ | ||
private $customerSession; | ||
|
||
/** | ||
* Checkout Session | ||
* | ||
* @var \Magento\Checkout\Model\Session | ||
*/ | ||
private $checkoutSession; | ||
|
||
/** | ||
* Quote Manager | ||
* | ||
* @var \Magento\Persistent\Model\QuoteManager | ||
*/ | ||
private $quoteManager; | ||
|
||
/** | ||
* Cart Repository | ||
* | ||
* @var \Magento\Quote\Api\CartRepositoryInterface | ||
*/ | ||
private $cartRepository; | ||
|
||
/** | ||
* Initialize dependencies | ||
* | ||
* @param \Magento\Persistent\Helper\Data $persistenceDataHelper | ||
* @param \Magento\Persistent\Helper\Session $persistenceSessionHelper | ||
* @param \Magento\Customer\Model\Session $customerSession | ||
* @param \Magento\Checkout\Model\Session $checkoutSession | ||
* @param \Magento\Persistent\Model\QuoteManager $quoteManager | ||
* @param \Magento\Quote\Api\CartRepositoryInterface $cartRepository | ||
*/ | ||
public function __construct( | ||
\Magento\Persistent\Helper\Data $persistenceDataHelper, | ||
\Magento\Persistent\Helper\Session $persistenceSessionHelper, | ||
\Magento\Customer\Model\Session $customerSession, | ||
\Magento\Checkout\Model\Session $checkoutSession, | ||
\Magento\Persistent\Model\QuoteManager $quoteManager, | ||
\Magento\Quote\Api\CartRepositoryInterface $cartRepository | ||
) { | ||
$this->persistenceDataHelper = $persistenceDataHelper; | ||
$this->persistenceSessionHelper = $persistenceSessionHelper; | ||
$this->customerSession = $customerSession; | ||
$this->checkoutSession = $checkoutSession; | ||
$this->quoteManager = $quoteManager; | ||
$this->cartRepository = $cartRepository; | ||
} | ||
|
||
/** | ||
* Convert customer cart to guest cart before order is placed if customer is not logged in | ||
* | ||
* @param GuestPaymentInformationManagement $subject | ||
* @param string $cartId | ||
* @param string $email | ||
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod | ||
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress | ||
* @return void | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function beforeSavePaymentInformationAndPlaceOrder( | ||
GuestPaymentInformationManagement $subject, | ||
$cartId, | ||
$email, | ||
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod, | ||
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null | ||
) { | ||
if ($this->persistenceSessionHelper->isPersistent() | ||
&& !$this->customerSession->isLoggedIn() | ||
&& $this->persistenceDataHelper->isShoppingCartPersist() | ||
&& $this->quoteManager->isPersistent() | ||
) { | ||
$this->customerSession->setCustomerId(null); | ||
$this->customerSession->setCustomerGroupId(null); | ||
$this->quoteManager->convertCustomerCartToGuest(); | ||
/** @var \Magento\Quote\Api\Data\CartInterface $quote */ | ||
$quote = $this->cartRepository->get($this->checkoutSession->getQuote()->getId()); | ||
$quote->setCustomerEmail($email); | ||
$quote->getAddressesCollection()->walk('setEmail', ['email' => $email]); | ||
$this->cartRepository->save($quote); | ||
} | ||
} | ||
} |
Oops, something went wrong.