Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOL-658 apple pay direct for esd products #348

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions Components/Account/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Shopware\Components\Password\Manager;
use Shopware\Models\Customer\Customer;
use Shopware\Models\Order\Order;
use Shopware\Models\User\User;
use Shopware_Components_Config;
use Symfony\Component\Validator\ConstraintViolation;
use Throwable;
Expand Down Expand Up @@ -92,6 +93,16 @@ public function isLoggedIn()
return !empty($userId);
}

/**
* Gets if the user is signed in with a guest account.
*
* @return bool
*/
public function isLoggedInAsGuest()
{
return boolval($this->session->offsetGet('sOneTimeAccount'));
}

/**
* @param string $email
* @param string $firstname
Expand Down
40 changes: 32 additions & 8 deletions Components/ApplePayDirect/Services/ApplePayButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace MollieShopware\Components\ApplePayDirect\Services;

use Doctrine\ORM\EntityNotFoundException;
use Enlight_Controller_Request_Request;
use Enlight_View;
use MollieShopware\Components\Account\Account;
use MollieShopware\Components\ApplePayDirect\Models\Button\ApplePayButton;
use MollieShopware\Components\ApplePayDirect\Models\Button\DisplayOption;
use MollieShopware\Components\Config;
use MollieShopware\Components\Country\CountryIsoParser;
use Shopware\Models\Shop\Shop;
use Symfony\Component\Validator\Constraints\NotBlank;

class ApplePayButtonBuilder
{
Expand All @@ -22,6 +21,13 @@ class ApplePayButtonBuilder
*/
const KEY_MOLLIE_APPLEPAY_BUTTON = 'sMollieApplePayDirectButton';

/** @var Account */
private $accountService;

/**
* @var \Shopware_Proxies_sBasketProxy
*/
private $sBasket;

/**
* @var Config
Expand All @@ -34,7 +40,7 @@ class ApplePayButtonBuilder
private $configShopware;

/**
* @var \sAdmin
* @var \Shopware_Proxies_sAdminProxy
*/
private $sAdmin;

Expand All @@ -50,20 +56,25 @@ class ApplePayButtonBuilder


/**
* @param Account $accountService
* @param Config $configMollie
* @param \Shopware_Components_Config $configShopware
* @param ApplePayPaymentMethod $applePayPaymentMethod
* @param ApplePayDirectDisplayOptions $restrictionService
* @param \sAdmin|\Shopware_Proxies_sAdminProxy $sAdmin
* @param \sBasket|\Shopware_Proxies_sBasketProxy $sBasket
*/
public function __construct(Config $configMollie, \Shopware_Components_Config $configShopware, ApplePayPaymentMethod $applePayPaymentMethod, ApplePayDirectDisplayOptions $restrictionService)
public function __construct(Account $accountService, Config $configMollie, \Shopware_Components_Config $configShopware, ApplePayPaymentMethod $applePayPaymentMethod, ApplePayDirectDisplayOptions $restrictionService, $sAdmin, $sBasket)
{
$this->accountService = $accountService;
$this->configMollie = $configMollie;
$this->configShopware = $configShopware;
$this->restrictionService = $restrictionService;
$this->applePayPaymentMethod = $applePayPaymentMethod;

# attention, modules does not exist in CLI
$this->sAdmin = Shopware()->Modules()->Admin();
$this->applePayPaymentMethod = $applePayPaymentMethod;
$this->sAdmin = $sAdmin;
iamreinder marked this conversation as resolved.
Show resolved Hide resolved
$this->sBasket = $sBasket;
}


Expand All @@ -78,7 +89,6 @@ public function addButtonStatus(Enlight_Controller_Request_Request $request, Enl
/** @var string $controller */
$controller = strtolower($request->getControllerName());


$isActive = $this->applePayPaymentMethod->isApplePayDirectEnabled();

if ($isActive) {
Expand All @@ -90,8 +100,17 @@ public function addButtonStatus(Enlight_Controller_Request_Request $request, Enl
if ($isRiskManagementBlocked) {
$isActive = false;
}
}

# if a customer has esd products in the basket, check if
# the customer is logged in with a full customer account
$hasEsdProductsInBasket = $controller === 'checkout' && $this->basketHasEsdProducts();
boxblinkracer marked this conversation as resolved.
Show resolved Hide resolved
$isEsdProductDetailPage = $controller === 'detail' && boolval($view->getAssign('sArticle')['esd']) === true;
$isUserLoggedIn = $this->accountService->isLoggedIn() && !$this->accountService->isLoggedInAsGuest();

if (($hasEsdProductsInBasket || $isEsdProductDetailPage) && !$isUserLoggedIn) {
$isActive = false;
}
}

# apple pay requires a country iso
# we use the first one from our country list.
Expand Down Expand Up @@ -137,4 +156,9 @@ public function addButtonStatus(Enlight_Controller_Request_Request $request, Enl

$view->assign(self::KEY_MOLLIE_APPLEPAY_BUTTON, $button->toArray());
}

private function basketHasEsdProducts()
{
return $this->sBasket->sCheckForESD();
}
}
3 changes: 3 additions & 0 deletions Resources/services/components/applepay_direct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

<service id="mollie_shopware.components.apple_pay_direct.services.button_builder"
class="MollieShopware\Components\ApplePayDirect\Services\ApplePayButtonBuilder" public="true">
<argument type="service" id="mollie_shopware.components.account.account" />
<argument type="service" id="mollie_shopware.config"/>
<argument type="service" id="config"/>
<argument type="service" id="mollie_shopware.components.apple_pay_direct.services.payment_method"/>
<argument type="service" id="mollie_shopware.components.apple_pay_direct.services.display_option"/>
<argument type="expression">container.get('Shopware_Components_Modules').Admin()</argument>
iamreinder marked this conversation as resolved.
Show resolved Hide resolved
<argument type="expression">container.get('Shopware_Components_Modules').Basket()</argument>
</service>

<service id="mollie_shopware.components.apple_pay_direct.services.formatter"
Expand Down
Loading