diff --git a/src/CoreShop/Bundle/CoreBundle/Resources/config/services/shipping.yml b/src/CoreShop/Bundle/CoreBundle/Resources/config/services/shipping.yml index 25168404a6..e2e194e61b 100644 --- a/src/CoreShop/Bundle/CoreBundle/Resources/config/services/shipping.yml +++ b/src/CoreShop/Bundle/CoreBundle/Resources/config/services/shipping.yml @@ -69,7 +69,6 @@ services: tags: - { name: coreshop.shipping_rule.action, type: discountAmount, form-type: CoreShop\Bundle\CoreBundle\Form\Type\Shipping\Rule\Action\DiscountAmountActionConfigurationType } - coreshop.carrier.price_calculator.taxed: class: CoreShop\Component\Core\Shipping\Calculator\TaxedCarrierPriceRuleCalculator arguments: @@ -81,5 +80,6 @@ services: class: CoreShop\Component\Core\Shipping\Discover\StoreBasedShippableCarriersDiscovery decorates: coreshop.carrier.resolver arguments: + - '@coreshop.carrier.cart.store_based_resolver.inner' - '@coreshop.repository.carrier' - - '@coreshop.shipping.carrier.validator' \ No newline at end of file + - '@coreshop.shipping.carrier.validator' diff --git a/src/CoreShop/Component/Core/Shipping/Calculator/TaxedCarrierPriceRuleCalculator.php b/src/CoreShop/Component/Core/Shipping/Calculator/TaxedCarrierPriceRuleCalculator.php index 8782d6b727..891fd7eb59 100644 --- a/src/CoreShop/Component/Core/Shipping/Calculator/TaxedCarrierPriceRuleCalculator.php +++ b/src/CoreShop/Component/Core/Shipping/Calculator/TaxedCarrierPriceRuleCalculator.php @@ -14,15 +14,14 @@ use CoreShop\Component\Address\Model\AddressInterface; use CoreShop\Component\Core\Model\CarrierInterface as CoreCarrierInterface; -use CoreShop\Component\Core\Model\CartInterface; use CoreShop\Component\Core\Taxation\TaxApplicatorInterface; use CoreShop\Component\Core\Taxation\TaxCalculatorFactoryInterface; use CoreShop\Component\Shipping\Calculator\CarrierPriceCalculatorInterface; use CoreShop\Component\Shipping\Model\CarrierInterface as BaseCarrierInterface; use CoreShop\Component\Shipping\Model\ShippableInterface; +use CoreShop\Component\Store\Model\StoreAwareInterface; use CoreShop\Component\Taxation\Calculator\TaxCalculatorInterface; use CoreShop\Component\Taxation\Model\TaxRuleGroupInterface; -use Webmozart\Assert\Assert; final class TaxedCarrierPriceRuleCalculator implements TaxedShippingCalculatorInterface { @@ -61,11 +60,6 @@ public function __construct( */ public function getPrice(BaseCarrierInterface $carrier, ShippableInterface $shippable, AddressInterface $address, $withTax = true) { - /** - * @var $shippable CartInterface - */ - Assert::isInstanceOf($shippable, CartInterface::class); - $price = $this->carrierPriceCalculator->getPrice($carrier, $shippable, $address); if (!$carrier instanceof CoreCarrierInterface) { @@ -74,7 +68,7 @@ public function getPrice(BaseCarrierInterface $carrier, ShippableInterface $ship $taxCalculator = $this->getTaxCalculator($carrier, $address); - if ($taxCalculator instanceof TaxCalculatorInterface) { + if ($taxCalculator instanceof TaxCalculatorInterface && $shippable instanceof StoreAwareInterface) { return $this->taxApplicator->applyTax($price, ['store' => $shippable->getStore()], $taxCalculator, $withTax); } diff --git a/src/CoreShop/Component/Core/Shipping/Discover/StoreBasedShippableCarriersDiscovery.php b/src/CoreShop/Component/Core/Shipping/Discover/StoreBasedShippableCarriersDiscovery.php index 275f01fad2..cab5a82a1e 100644 --- a/src/CoreShop/Component/Core/Shipping/Discover/StoreBasedShippableCarriersDiscovery.php +++ b/src/CoreShop/Component/Core/Shipping/Discover/StoreBasedShippableCarriersDiscovery.php @@ -13,15 +13,19 @@ namespace CoreShop\Component\Core\Shipping\Discover; use CoreShop\Component\Address\Model\AddressInterface; -use CoreShop\Component\Core\Model\CartInterface; use CoreShop\Component\Core\Repository\CarrierRepositoryInterface; use CoreShop\Component\Shipping\Model\ShippableInterface; use CoreShop\Component\Shipping\Resolver\CarriersResolverInterface; use CoreShop\Component\Shipping\Validator\ShippableCarrierValidatorInterface; -use Webmozart\Assert\Assert; +use CoreShop\Component\Store\Model\StoreAwareInterface; final class StoreBasedShippableCarriersDiscovery implements CarriersResolverInterface { + /** + * @var CarriersResolverInterface + */ + private $inner; + /** * @var CarrierRepositoryInterface */ @@ -33,13 +37,16 @@ final class StoreBasedShippableCarriersDiscovery implements CarriersResolverInte private $shippableCarrierValidator; /** + * @param CarriersResolverInterface $inner * @param CarrierRepositoryInterface $carrierRepository * @param ShippableCarrierValidatorInterface $shippableCarrierValidator */ public function __construct( + CarriersResolverInterface $inner, CarrierRepositoryInterface $carrierRepository, ShippableCarrierValidatorInterface $shippableCarrierValidator ) { + $this->inner = $inner; $this->carrierRepository = $carrierRepository; $this->shippableCarrierValidator = $shippableCarrierValidator; } @@ -49,20 +56,19 @@ public function __construct( */ public function resolveCarriers(ShippableInterface $shippable, AddressInterface $address) { - /** - * @var CartInterface $shippable - */ - Assert::isInstanceOf($shippable, CartInterface::class); + if ($shippable instanceof StoreAwareInterface) { + $carriers = $this->carrierRepository->findForStore($shippable->getStore()); + $availableCarriers = []; - $carriers = $this->carrierRepository->findForStore($shippable->getStore()); - $availableCarriers = []; - - foreach ($carriers as $carrier) { - if ($this->shippableCarrierValidator->isCarrierValid($carrier, $shippable, $address)) { - $availableCarriers[] = $carrier; + foreach ($carriers as $carrier) { + if ($this->shippableCarrierValidator->isCarrierValid($carrier, $shippable, $address)) { + $availableCarriers[] = $carrier; + } } + + return $availableCarriers; } - return $availableCarriers; + return $this->inner->resolveCarriers($shippable, $address); } } diff --git a/src/CoreShop/Component/Core/Shipping/Rule/Action/AdditionAmountActionProcessor.php b/src/CoreShop/Component/Core/Shipping/Rule/Action/AdditionAmountActionProcessor.php index 2b614af16d..304b6b435e 100644 --- a/src/CoreShop/Component/Core/Shipping/Rule/Action/AdditionAmountActionProcessor.php +++ b/src/CoreShop/Component/Core/Shipping/Rule/Action/AdditionAmountActionProcessor.php @@ -13,8 +13,8 @@ namespace CoreShop\Component\Core\Shipping\Rule\Action; use CoreShop\Component\Address\Model\AddressInterface; -use CoreShop\Component\Core\Model\CartInterface; use CoreShop\Component\Currency\Converter\CurrencyConverterInterface; +use CoreShop\Component\Currency\Model\CurrencyAwareInterface; use CoreShop\Component\Currency\Model\CurrencyInterface; use CoreShop\Component\Currency\Repository\CurrencyRepositoryInterface; use CoreShop\Component\Shipping\Model\CarrierInterface; @@ -57,16 +57,16 @@ public function getPrice(CarrierInterface $carrier, ShippableInterface $shippabl */ public function getModification(CarrierInterface $carrier, ShippableInterface $shippable, AddressInterface $address, $price, array $configuration) { - /** - * @var CartInterface $shippable - */ - Assert::isInstanceOf($shippable, CartInterface::class); - $amount = $configuration['amount']; - $currency = $this->currencyRepository->find($configuration['currency']); - Assert::isInstanceOf($currency, CurrencyInterface::class); + if ($shippable instanceof CurrencyAwareInterface) { + $currency = $this->currencyRepository->find($configuration['currency']); + + Assert::isInstanceOf($currency, CurrencyInterface::class); + + return $this->moneyConverter->convert($amount, $currency->getIsoCode(), $shippable->getCurrency()->getIsoCode()); + } - return $this->moneyConverter->convert($amount, $currency->getIsoCode(), $shippable->getCurrency()->getIsoCode()); + return $amount; } } diff --git a/src/CoreShop/Component/Core/Shipping/Rule/Action/DiscountAmountActionProcessor.php b/src/CoreShop/Component/Core/Shipping/Rule/Action/DiscountAmountActionProcessor.php index 3f86c27cf8..66e20d237f 100644 --- a/src/CoreShop/Component/Core/Shipping/Rule/Action/DiscountAmountActionProcessor.php +++ b/src/CoreShop/Component/Core/Shipping/Rule/Action/DiscountAmountActionProcessor.php @@ -13,8 +13,8 @@ namespace CoreShop\Component\Core\Shipping\Rule\Action; use CoreShop\Component\Address\Model\AddressInterface; -use CoreShop\Component\Core\Model\CartInterface; use CoreShop\Component\Currency\Converter\CurrencyConverterInterface; +use CoreShop\Component\Currency\Model\CurrencyAwareInterface; use CoreShop\Component\Currency\Model\CurrencyInterface; use CoreShop\Component\Currency\Repository\CurrencyRepositoryInterface; use CoreShop\Component\Shipping\Model\CarrierInterface; @@ -57,16 +57,16 @@ public function getPrice(CarrierInterface $carrier, ShippableInterface $shippabl */ public function getModification(CarrierInterface $carrier, ShippableInterface $shippable, AddressInterface $address, $price, array $configuration) { - /** - * @var $shippable CartInterface - */ - Assert::isInstanceOf($shippable, CartInterface::class); - $amount = $configuration['amount']; - $currency = $this->currencyRepository->find($configuration['currency']); - Assert::isInstanceOf($currency, CurrencyInterface::class); + if ($shippable instanceof CurrencyAwareInterface) { + $currency = $this->currencyRepository->find($configuration['currency']); + + Assert::isInstanceOf($currency, CurrencyInterface::class); + + return -1 * $this->moneyConverter->convert($amount, $currency->getIsoCode(), $shippable->getCurrency()->getIsoCode()); + } - return -1 * $this->moneyConverter->convert($amount, $currency->getIsoCode(), $shippable->getCurrency()->getIsoCode()); + return $amount; } } diff --git a/src/CoreShop/Component/Core/Shipping/Rule/Action/PriceActionProcessor.php b/src/CoreShop/Component/Core/Shipping/Rule/Action/PriceActionProcessor.php index 832b3f4c10..3634ec9ffe 100644 --- a/src/CoreShop/Component/Core/Shipping/Rule/Action/PriceActionProcessor.php +++ b/src/CoreShop/Component/Core/Shipping/Rule/Action/PriceActionProcessor.php @@ -13,8 +13,8 @@ namespace CoreShop\Component\Core\Shipping\Rule\Action; use CoreShop\Component\Address\Model\AddressInterface; -use CoreShop\Component\Core\Model\CartInterface; use CoreShop\Component\Currency\Converter\CurrencyConverterInterface; +use CoreShop\Component\Currency\Model\CurrencyAwareInterface; use CoreShop\Component\Currency\Model\CurrencyInterface; use CoreShop\Component\Currency\Repository\CurrencyRepositoryInterface; use CoreShop\Component\Shipping\Model\CarrierInterface; @@ -49,17 +49,17 @@ public function __construct(CurrencyRepositoryInterface $currencyRepository, Cur */ public function getPrice(CarrierInterface $carrier, ShippableInterface $shippable, AddressInterface $address, array $configuration) { - /** - * @var $shippable CartInterface - */ - Assert::isInstanceOf($shippable, CartInterface::class); - $price = $configuration['price']; - $currency = $this->currencyRepository->find($configuration['currency']); - Assert::isInstanceOf($currency, CurrencyInterface::class); + if ($shippable instanceof CurrencyAwareInterface) { + $currency = $this->currencyRepository->find($configuration['currency']); + + Assert::isInstanceOf($currency, CurrencyInterface::class); + + return $this->moneyConverter->convert($price, $currency->getIsoCode(), $shippable->getCurrency()->getIsoCode()); + } - return $this->moneyConverter->convert($price, $currency->getIsoCode(), $shippable->getCurrency()->getIsoCode()); + return $price; } /** diff --git a/src/CoreShop/Component/Core/Shipping/Rule/Condition/CategoriesConditionChecker.php b/src/CoreShop/Component/Core/Shipping/Rule/Condition/CategoriesConditionChecker.php index 6f807b4ec2..34ee818639 100644 --- a/src/CoreShop/Component/Core/Shipping/Rule/Condition/CategoriesConditionChecker.php +++ b/src/CoreShop/Component/Core/Shipping/Rule/Condition/CategoriesConditionChecker.php @@ -21,7 +21,6 @@ use CoreShop\Component\Shipping\Model\CarrierInterface; use CoreShop\Component\Shipping\Model\ShippableInterface; use CoreShop\Component\Shipping\Rule\Condition\AbstractConditionChecker; -use Webmozart\Assert\Assert; final class CategoriesConditionChecker extends AbstractConditionChecker { @@ -42,10 +41,9 @@ public function __construct(CategoryRepositoryInterface $categoryRepository) */ public function isShippingRuleValid(CarrierInterface $carrier, ShippableInterface $shippable, AddressInterface $address, array $configuration) { - /** - * @var $shippable CartInterface - */ - Assert::isInstanceOf($shippable, CartInterface::class); + if (!$shippable instanceof CartInterface) { + return false; + } $cartItems = $shippable->getItems(); diff --git a/src/CoreShop/Component/Core/Shipping/Rule/Condition/CurrenciesConditionChecker.php b/src/CoreShop/Component/Core/Shipping/Rule/Condition/CurrenciesConditionChecker.php index 62cffa4a65..459cab5acb 100644 --- a/src/CoreShop/Component/Core/Shipping/Rule/Condition/CurrenciesConditionChecker.php +++ b/src/CoreShop/Component/Core/Shipping/Rule/Condition/CurrenciesConditionChecker.php @@ -13,11 +13,10 @@ namespace CoreShop\Component\Core\Shipping\Rule\Condition; use CoreShop\Component\Address\Model\AddressInterface; -use CoreShop\Component\Core\Model\CartInterface; +use CoreShop\Component\Currency\Model\CurrencyAwareInterface; use CoreShop\Component\Shipping\Model\CarrierInterface; use CoreShop\Component\Shipping\Model\ShippableInterface; use CoreShop\Component\Shipping\Rule\Condition\AbstractConditionChecker; -use Webmozart\Assert\Assert; final class CurrenciesConditionChecker extends AbstractConditionChecker { @@ -30,10 +29,9 @@ public function isShippingRuleValid( AddressInterface $address, array $configuration ) { - /** - * @var $shippable CartInterface - */ - Assert::isInstanceOf($shippable, CartInterface::class); + if (!$shippable instanceof CurrencyAwareInterface) { + return false; + } return in_array($shippable->getCurrency()->getId(), $configuration['currencies']); } diff --git a/src/CoreShop/Component/Core/Shipping/Rule/Condition/CustomerGroupsConditionChecker.php b/src/CoreShop/Component/Core/Shipping/Rule/Condition/CustomerGroupsConditionChecker.php index 1f21afd2d0..e4f01005b8 100644 --- a/src/CoreShop/Component/Core/Shipping/Rule/Condition/CustomerGroupsConditionChecker.php +++ b/src/CoreShop/Component/Core/Shipping/Rule/Condition/CustomerGroupsConditionChecker.php @@ -13,13 +13,12 @@ namespace CoreShop\Component\Core\Shipping\Rule\Condition; use CoreShop\Component\Address\Model\AddressInterface; -use CoreShop\Component\Core\Model\CartInterface; +use CoreShop\Component\Customer\Model\CustomerAwareInterface; use CoreShop\Component\Customer\Model\CustomerInterface; use CoreShop\Component\Resource\Model\ResourceInterface; use CoreShop\Component\Shipping\Model\CarrierInterface; use CoreShop\Component\Shipping\Model\ShippableInterface; use CoreShop\Component\Shipping\Rule\Condition\AbstractConditionChecker; -use Webmozart\Assert\Assert; final class CustomerGroupsConditionChecker extends AbstractConditionChecker { @@ -32,10 +31,9 @@ public function isShippingRuleValid( AddressInterface $address, array $configuration ) { - /** - * @var $shippable CartInterface - */ - Assert::isInstanceOf($shippable, CartInterface::class); + if (!$shippable instanceof CustomerAwareInterface) { + return false; + } if (!$shippable->getCustomer() instanceof CustomerInterface) { return false; diff --git a/src/CoreShop/Component/Core/Shipping/Rule/Condition/CustomersConditionChecker.php b/src/CoreShop/Component/Core/Shipping/Rule/Condition/CustomersConditionChecker.php index 100551ff52..59032a0a8d 100644 --- a/src/CoreShop/Component/Core/Shipping/Rule/Condition/CustomersConditionChecker.php +++ b/src/CoreShop/Component/Core/Shipping/Rule/Condition/CustomersConditionChecker.php @@ -13,12 +13,11 @@ namespace CoreShop\Component\Core\Shipping\Rule\Condition; use CoreShop\Component\Address\Model\AddressInterface; -use CoreShop\Component\Core\Model\CartInterface; +use CoreShop\Component\Customer\Model\CustomerAwareInterface; use CoreShop\Component\Customer\Model\CustomerInterface; use CoreShop\Component\Shipping\Model\CarrierInterface; use CoreShop\Component\Shipping\Model\ShippableInterface; use CoreShop\Component\Shipping\Rule\Condition\AbstractConditionChecker; -use Webmozart\Assert\Assert; final class CustomersConditionChecker extends AbstractConditionChecker { @@ -31,10 +30,9 @@ public function isShippingRuleValid( AddressInterface $address, array $configuration ) { - /** - * @var $shippable CartInterface - */ - Assert::isInstanceOf($shippable, CartInterface::class); + if (!$shippable instanceof CustomerAwareInterface) { + return false; + } if (!$shippable->getCustomer() instanceof CustomerInterface) { return false; diff --git a/src/CoreShop/Component/Core/Shipping/Rule/Condition/StoresConditionChecker.php b/src/CoreShop/Component/Core/Shipping/Rule/Condition/StoresConditionChecker.php index 83533f6a3c..4eb3573f9d 100644 --- a/src/CoreShop/Component/Core/Shipping/Rule/Condition/StoresConditionChecker.php +++ b/src/CoreShop/Component/Core/Shipping/Rule/Condition/StoresConditionChecker.php @@ -13,11 +13,10 @@ namespace CoreShop\Component\Core\Shipping\Rule\Condition; use CoreShop\Component\Address\Model\AddressInterface; -use CoreShop\Component\Core\Model\CartInterface; use CoreShop\Component\Shipping\Model\CarrierInterface; use CoreShop\Component\Shipping\Model\ShippableInterface; use CoreShop\Component\Shipping\Rule\Condition\AbstractConditionChecker; -use Webmozart\Assert\Assert; +use CoreShop\Component\Store\Model\StoreAwareInterface; final class StoresConditionChecker extends AbstractConditionChecker { @@ -30,10 +29,9 @@ public function isShippingRuleValid( AddressInterface $address, array $configuration ) { - /** - * @var $shippable CartInterface - */ - Assert::isInstanceOf($shippable, CartInterface::class); + if (!$shippable instanceof StoreAwareInterface) { + return false; + } return in_array($shippable->getStore()->getId(), $configuration['stores']); } diff --git a/src/CoreShop/Component/Customer/Model/CustomerAwareInterface.php b/src/CoreShop/Component/Customer/Model/CustomerAwareInterface.php new file mode 100644 index 0000000000..c75520d11f --- /dev/null +++ b/src/CoreShop/Component/Customer/Model/CustomerAwareInterface.php @@ -0,0 +1,26 @@ +getId(); foreach ($data->getClass()->getFieldDefinitions() as $key => $def) { - $getter = 'get'.ucfirst($key); + $getter = 'get' . ucfirst($key); if (!method_exists($data, $getter)) { continue; diff --git a/src/CoreShop/Component/Pimcore/DataObject/DataLoaderInterface.php b/src/CoreShop/Component/Pimcore/DataObject/DataLoaderInterface.php index 5c5f1761dc..ad23c3126e 100644 --- a/src/CoreShop/Component/Pimcore/DataObject/DataLoaderInterface.php +++ b/src/CoreShop/Component/Pimcore/DataObject/DataLoaderInterface.php @@ -19,6 +19,7 @@ interface DataLoaderInterface /** * @param DataObject\Concrete $data * @param array $loadedObjects + * * @return mixed */ public function getDataForObject(DataObject\Concrete $data, $loadedObjects = []);