Skip to content

Instantly share code, notes, and snippets.

@AltayAkkus
Created December 22, 2022 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AltayAkkus/409e0f51859859ed7a6e6bdb18bc5bc1 to your computer and use it in GitHub Desktop.
Save AltayAkkus/409e0f51859859ed7a6e6bdb18bc5bc1 to your computer and use it in GitHub Desktop.
Example cart error with resubmit enabled in Shopware 6
<?php declare(strict_types=1);
namespace Shopware\Core\Checkout\Cart\Address\Error;
use Shopware\Core\Checkout\Cart\Error\Error;
/**
* @package checkout
*/
class ShippingAddressBlockedError extends Error
{
private const KEY = 'shipping-address-blocked';
/**
* @var string
*/
private $name;
public function __construct(string $name)
{
$this->name = $name;
$this->message = sprintf(
'Shippings to shipping address %s are not possible.',
$name
);
parent::__construct($this->message);
}
public function getName(): string
{
return $this->name;
}
public function blockOrder(): bool
{
return true;
}
public function blockResubmit(): bool
{
return false;
}
public function getKey(): string
{
return sprintf('%s-%s', self::KEY, $this->name);
}
public function getLevel(): int
{
return self::LEVEL_ERROR;
}
public function getMessageKey(): string
{
return self::KEY;
}
public function getId(): string
{
return $this->getKey();
}
public function getParameters(): array
{
return ['name' => $this->name];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment