Skip to content

Commit

Permalink
Merge branch 'ppi-807/improved-script-loading-in-storefront' into 'tr…
Browse files Browse the repository at this point in the history
…unk'

PPI-807 - Improved script loading in storefront

See merge request shopware/6/services/paypal!765
  • Loading branch information
mstegmeyer committed Jul 16, 2024
2 parents ecc86b4 + f63b4ae commit 4476ec7
Show file tree
Hide file tree
Showing 21 changed files with 601 additions and 531 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 9.4.0
- PPI-951 - Fixes an issue, where only generic error messages were displayed during checkout without Smart Payment Buttons
- PPI-807 - Improved script loading performance in the Storefront
- PPI-924 - Added more explicit error messages for errors happening during express checkout
- PPI-951 - Fixes an issue, where only generic error messages were displayed during checkout without Smart Payment Buttons
- PPI-953 - Fixes an issue, where shipping tracking codes were not synced with an invalid carrier

# 9.3.1
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# 9.4.0
- PPI-807 - Verbessert die Ladezeit der Scripte in der Storefront
- PPI-924 - Fügt genauere Fehlermeldungen für Fehler während des Express Checkouts hinzu
- PPI-951 - Behebt ein Problem, bei dem ohne Smart Payment Buttons nur generische Fehlermeldungen während des Bestellprozesses angezeigt wurden
- PPI-953 - Behebt ein Problem, bei dem Sendungsverfolgungsdaten bei invaliden Versanddienstleister nicht an PayPal übermittelt wurden

Expand Down
127 changes: 123 additions & 4 deletions src/Checkout/ExpressCheckout/ExpressCheckoutButtonData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace Swag\PayPal\Checkout\ExpressCheckout;

use Shopware\Core\Framework\Log\Package;
use Swag\PayPal\Storefront\Data\Struct\AbstractCheckoutData;
use Swag\PayPal\Storefront\Data\Struct\AbstractScriptData;

#[Package('checkout')]
class ExpressCheckoutButtonData extends AbstractCheckoutData
class ExpressCheckoutButtonData extends AbstractScriptData
{
protected bool $productDetailEnabled;

Expand All @@ -23,16 +23,29 @@ class ExpressCheckoutButtonData extends AbstractCheckoutData

protected bool $cartEnabled;

protected string $buttonColor;

protected string $buttonShape;

protected bool $addProductToCart;

protected string $contextSwitchUrl;

protected ?string $payPalPaymentMethodId = null;

protected string $createOrderUrl;

protected string $prepareCheckoutUrl;

protected string $checkoutConfirmUrl;

/**
* @deprecated tag:v10.0.0 - Will be removed, use {@link handleErrorUrl} instead
*/
protected string $addErrorUrl;

protected string $handleErrorUrl;

protected string $cancelRedirectUrl;

protected bool $showPayLater;
Expand All @@ -42,61 +55,167 @@ public function getProductDetailEnabled(): bool
return $this->productDetailEnabled;
}

public function setProductDetailEnabled(bool $productDetailEnabled): void
{
$this->productDetailEnabled = $productDetailEnabled;
}

public function getOffCanvasEnabled(): bool
{
return $this->offCanvasEnabled;
}

public function setOffCanvasEnabled(bool $offCanvasEnabled): void
{
$this->offCanvasEnabled = $offCanvasEnabled;
}

public function getLoginEnabled(): bool
{
return $this->loginEnabled;
}

public function setLoginEnabled(bool $loginEnabled): void
{
$this->loginEnabled = $loginEnabled;
}

public function getListingEnabled(): bool
{
return $this->listingEnabled;
}

public function getButtonColor(): string
public function setListingEnabled(bool $listingEnabled): void
{
return $this->buttonColor;
$this->listingEnabled = $listingEnabled;
}

public function getCartEnabled(): bool
{
return $this->cartEnabled;
}

public function setCartEnabled(bool $cartEnabled): void
{
$this->cartEnabled = $cartEnabled;
}

public function getButtonColor(): string
{
return $this->buttonColor;
}

public function setButtonColor(string $buttonColor): void
{
$this->buttonColor = $buttonColor;
}

public function getButtonShape(): string
{
return $this->buttonShape;
}

public function setButtonShape(string $buttonShape): void
{
$this->buttonShape = $buttonShape;
}

public function getAddProductToCart(): bool
{
return $this->addProductToCart;
}

public function setAddProductToCart(bool $addProductToCart): void
{
$this->addProductToCart = $addProductToCart;
}

public function getContextSwitchUrl(): string
{
return $this->contextSwitchUrl;
}

public function setContextSwitchUrl(string $contextSwitchUrl): void
{
$this->contextSwitchUrl = $contextSwitchUrl;
}

public function getPayPalPaymentMethodId(): ?string
{
return $this->payPalPaymentMethodId;
}

public function setPayPalPaymentMethodId(?string $payPalPaymentMethodId): void
{
$this->payPalPaymentMethodId = $payPalPaymentMethodId;
}

public function getCreateOrderUrl(): string
{
return $this->createOrderUrl;
}

public function setCreateOrderUrl(string $createOrderUrl): void
{
$this->createOrderUrl = $createOrderUrl;
}

public function getPrepareCheckoutUrl(): string
{
return $this->prepareCheckoutUrl;
}

public function setPrepareCheckoutUrl(string $prepareCheckoutUrl): void
{
$this->prepareCheckoutUrl = $prepareCheckoutUrl;
}

public function getCheckoutConfirmUrl(): string
{
return $this->checkoutConfirmUrl;
}

public function setCheckoutConfirmUrl(string $checkoutConfirmUrl): void
{
$this->checkoutConfirmUrl = $checkoutConfirmUrl;
}

/**
* @deprecated tag:v10.0.0 - Will be removed, use {@link handleErrorUrl} instead
*/
public function getAddErrorUrl(): string
{
return $this->addErrorUrl;
}

/**
* @deprecated tag:v10.0.0 - Will be removed, use {@link handleErrorUrl} instead
*/
public function setAddErrorUrl(string $addErrorUrl): void
{
$this->addErrorUrl = $addErrorUrl;
}

public function getHandleErrorUrl(): string
{
return $this->handleErrorUrl;
}

public function setHandleErrorUrl(string $handleErrorUrl): void
{
$this->handleErrorUrl = $handleErrorUrl;
}

public function getCancelRedirectUrl(): string
{
return $this->cancelRedirectUrl;
}

public function setCancelRedirectUrl(string $cancelRedirectUrl): void
{
$this->cancelRedirectUrl = $cancelRedirectUrl;
}

public function isShowPayLater(): bool
{
return $this->showPayLater;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
Expand All @@ -18,46 +17,27 @@
use Swag\PayPal\Checkout\Payment\PayPalPaymentHandler;
use Swag\PayPal\Setting\Service\CredentialsUtilInterface;
use Swag\PayPal\Setting\Settings;
use Swag\PayPal\Storefront\Data\Service\AbstractScriptDataService;
use Swag\PayPal\Util\LocaleCodeProvider;
use Swag\PayPal\Util\PaymentMethodUtil;
use Symfony\Component\Routing\RouterInterface;

#[Package('checkout')]
class PayPalExpressCheckoutDataService implements ExpressCheckoutDataServiceInterface
class PayPalExpressCheckoutDataService extends AbstractScriptDataService implements ExpressCheckoutDataServiceInterface
{
private CartService $cartService;

private LocaleCodeProvider $localeCodeProvider;

private RouterInterface $router;

private PaymentMethodUtil $paymentMethodUtil;

private SystemConfigService $systemConfigService;

private CredentialsUtilInterface $credentialsUtil;

private CartPriceService $cartPriceService;

/**
* @internal
*/
public function __construct(
CartService $cartService,
private readonly CartService $cartService,
LocaleCodeProvider $localeCodeProvider,
RouterInterface $router,
PaymentMethodUtil $paymentMethodUtil,
private readonly RouterInterface $router,
private readonly PaymentMethodUtil $paymentMethodUtil,
SystemConfigService $systemConfigService,
CredentialsUtilInterface $credentialsUtil,
CartPriceService $cartPriceService
private readonly CartPriceService $cartPriceService
) {
$this->cartService = $cartService;
$this->localeCodeProvider = $localeCodeProvider;
$this->router = $router;
$this->paymentMethodUtil = $paymentMethodUtil;
$this->systemConfigService = $systemConfigService;
$this->credentialsUtil = $credentialsUtil;
$this->cartPriceService = $cartPriceService;
parent::__construct($localeCodeProvider, $systemConfigService, $credentialsUtil);
}

public function buildExpressCheckoutButtonData(
Expand Down Expand Up @@ -87,17 +67,14 @@ public function buildExpressCheckoutButtonData(
$salesChannelId = $salesChannelContext->getSalesChannelId();

return (new ExpressCheckoutButtonData())->assign([
...parent::getBaseData($salesChannelContext),
'productDetailEnabled' => $this->systemConfigService->getBool(Settings::ECS_DETAIL_ENABLED, $salesChannelId),
'offCanvasEnabled' => $this->systemConfigService->getBool(Settings::ECS_OFF_CANVAS_ENABLED, $salesChannelId),
'loginEnabled' => $this->systemConfigService->getBool(Settings::ECS_LOGIN_ENABLED, $salesChannelId),
'cartEnabled' => $this->systemConfigService->getBool(Settings::ECS_CART_ENABLED, $salesChannelId),
'listingEnabled' => $this->systemConfigService->getBool(Settings::ECS_LISTING_ENABLED, $salesChannelId),
'buttonColor' => $this->systemConfigService->getString(Settings::ECS_BUTTON_COLOR, $salesChannelId),
'buttonShape' => $this->systemConfigService->getString(Settings::ECS_BUTTON_SHAPE, $salesChannelId),
'clientId' => $this->credentialsUtil->getClientId($salesChannelId),
'languageIso' => $this->getInContextButtonLanguage($salesChannelId, $context),
'currency' => $salesChannelContext->getCurrency()->getIsoCode(),
'intent' => \mb_strtolower($this->systemConfigService->getString(Settings::INTENT, $salesChannelId)),
'addProductToCart' => $addProductToCart,
'contextSwitchUrl' => $this->router->generate('frontend.paypal.express.prepare_cart'),
'payPalPaymentMethodId' => $this->paymentMethodUtil->getPayPalPaymentMethodId($context),
Expand All @@ -108,21 +85,22 @@ public function buildExpressCheckoutButtonData(
[PayPalPaymentHandler::PAYPAL_EXPRESS_CHECKOUT_ID => true],
RouterInterface::ABSOLUTE_URL
),
/** @deprecated tag:v10.0.0 - Will be removed, use handleErrorUrl instead */
'addErrorUrl' => $this->router->generate('frontend.paypal.error'),
'handleErrorUrl' => $this->router->generate('frontend.paypal.handle-error'),
'cancelRedirectUrl' => $this->router->generate($addProductToCart ? 'frontend.checkout.cart.page' : 'frontend.checkout.register.page'),
'showPayLater' => $this->systemConfigService->getBool(Settings::ECS_SHOW_PAY_LATER, $salesChannelId),
'merchantPayerId' => $this->credentialsUtil->getMerchantPayerId($salesChannelId),
]);
}

private function getInContextButtonLanguage(string $salesChannelId, Context $context): string
protected function getButtonLanguage(SalesChannelContext $context): string
{
if ($settingsLocale = $this->systemConfigService->getString(Settings::ECS_BUTTON_LANGUAGE_ISO, $salesChannelId)) {
if ($settingsLocale = $this->systemConfigService->getString(Settings::ECS_BUTTON_LANGUAGE_ISO, $context->getSalesChannelId())) {
return $this->localeCodeProvider->getFormattedLocaleCode($settingsLocale);
}

return $this->localeCodeProvider->getFormattedLocaleCode(
$this->localeCodeProvider->getLocaleCodeFromContext($context)
$this->localeCodeProvider->getLocaleCodeFromContext($context->getContext())
);
}
}
Loading

0 comments on commit 4476ec7

Please sign in to comment.