fix context for checkout. do not assign checkout context when already in a paypal session

This commit is contained in:
David Remer 2020-04-09 09:33:57 +03:00
parent 74129c5914
commit 4a5e805534
2 changed files with 10 additions and 4 deletions

View file

@ -6,18 +6,22 @@ namespace Inpsyde\PayPalCommerce\Button\Assets;
use Inpsyde\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint;
use Inpsyde\PayPalCommerce\Session\SessionHandler;
class SmartButton
{
private $moduleUrl;
private $sessionHandler;
private $isSandbox;
public function __construct(
string $moduleUrl,
SessionHandler $sessionHandler,
bool $isSandbox
) {
$this->moduleUrl = $moduleUrl;
$this->sessionHandler = $sessionHandler;
$this->isSandbox = $isSandbox;
}
@ -112,7 +116,7 @@ class SmartButton
if (is_cart()) {
$context = 'cart';
}
if (is_checkout()) {
if (is_checkout() && ! $this->sessionHandler->order()) {
$context = 'checkout';
}
return $context;

View file

@ -29,20 +29,22 @@ class ButtonModule implements ModuleInterface
*/
public function run(ContainerInterface $container)
{
$smartButton = $container->get('button.smart-button');
/**
* @var SmartButton $smartButton
*/
add_action(
'wp',
function () use ($smartButton) {
function () use ($container) {
if (is_admin()) {
return;
}
$smartButton = $container->get('button.smart-button');
$smartButton->renderWrapper();
}
);
add_action('wp_enqueue_scripts', function () use ($smartButton) {
add_action('wp_enqueue_scripts', function () use ($container) {
$smartButton = $container->get('button.smart-button');
$smartButton->enqueue();
});