diff --git a/engine/Shopware/Core/sBasket.php b/engine/Shopware/Core/sBasket.php index f0ae1f75aba..b54105b4c5b 100644 --- a/engine/Shopware/Core/sBasket.php +++ b/engine/Shopware/Core/sBasket.php @@ -421,7 +421,7 @@ public function sInsertDiscount() $tax = $this->config->get('sDISCOUNTTAX'); } - if (!$tax) { + if (!$tax && $tax != 0) { $tax = 19; } diff --git a/tests/Functional/Bundle/StoreFrontBundle/Helper.php b/tests/Functional/Bundle/StoreFrontBundle/Helper.php index 44161f50c25..3f02dabb043 100644 --- a/tests/Functional/Bundle/StoreFrontBundle/Helper.php +++ b/tests/Functional/Bundle/StoreFrontBundle/Helper.php @@ -27,6 +27,8 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\DBAL\Connection; +use Doctrine\ORM\Exception\ORMException; +use Doctrine\ORM\OptimisticLockException; use Enlight_Components_Db_Adapter_Pdo_Mysql; use Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface; use Shopware\Bundle\StoreFrontBundle\Struct\Customer\Group as CustomerGroupStruct; @@ -45,11 +47,15 @@ use Shopware\Models\Article\Configurator\Option; use Shopware\Models\Article\Supplier; use Shopware\Models\Category\Category; +use Shopware\Models\Customer\Customer; +use Shopware\Models\Customer\Discount as CustomerDiscount; +use Shopware\Models\Customer\Group; use Shopware\Models\Customer\Group as CustomerGroup; use Shopware\Models\Price\Discount; use Shopware\Models\Price\Group as PriceGroup; use Shopware\Models\Shop\Currency; use Shopware\Models\Shop\Shop as ShopModel; +use Shopware\Models\Tax\Rule as TaxRule; use Shopware\Models\Tax\Tax as TaxModel; use Shopware\Tests\Functional\Bundle\StoreFrontBundle\Helper\ProgressHelper; use Shopware_Components_Config; @@ -361,6 +367,40 @@ public function createTax(array $data = []): TaxModel return $tax; } + /** + * @param array $data + * + * @throws ORMException + * @throws OptimisticLockException + */ + public function createTaxRule(array $data): TaxRule + { + $taxRule = new TaxRule(); + $taxRule->fromArray($data); + + $this->entityManager->persist($taxRule); + $this->entityManager->flush(); + + return $taxRule; + } + + /** + * @param array $data + * + * @throws OptimisticLockException + * @throws ORMException + */ + public function createCustomerGroupDiscount(array $data): CustomerDiscount + { + $customerDiscount = new CustomerDiscount(); + $customerDiscount->fromArray($data); + + $this->entityManager->persist($customerDiscount); + $this->entityManager->flush(); + + return $customerDiscount; + } + public function createCurrency(array $data = []): Currency { $currency = new Currency(); diff --git a/tests/Functional/Core/BasketTest.php b/tests/Functional/Core/BasketTest.php index a41de4350ce..4d00c07d399 100644 --- a/tests/Functional/Core/BasketTest.php +++ b/tests/Functional/Core/BasketTest.php @@ -40,6 +40,9 @@ use Shopware\Components\Random; use Shopware\Models\Article\Detail; use Shopware\Models\Customer\Customer; +use Shopware\Models\Customer\Discount as CustomerGroupDiscount; +use Shopware\Models\Customer\Group as CustomerGroup; +use Shopware\Models\Tax\Rule as TaxRule; use Shopware\Tests\Functional\Bundle\StoreFrontBundle\Helper; use Shopware\Tests\Functional\Helper\Utils; use Shopware\Tests\Functional\Traits\ContainerTrait; @@ -156,6 +159,44 @@ public function testsCheckBasketQuantitiesWithLowerQuantityThanAvailable(): void static::assertFalse($result['articles'][$inStockProduct['ordernumber']]['OutOfStock']); } + public function testInsertDiscountWithTaxFreeTaxRule(): void + { + $this->generateBasketSession(); + + $customerGroupRepo = $this->getContainer()->get('models')->getRepository(CustomerGroup::class); + $customerGroup = $customerGroupRepo->findOneBy(['key' => 'EK']); + static::assertInstanceOf(CustomerGroup::class, $customerGroup); + + $taxRule = $this->createTaxFreeTaxRule($customerGroup); + $customerGroupDiscount = $this->createCustomerGroupDiscount($customerGroup); + + $this->module->sAddArticle('SW10003'); + $this->module->sInsertDiscount(); + + $discount = $this->connection->fetchAssociative( + 'SELECT * FROM s_order_basket WHERE sessionID = :sessionId AND ordernumber = :ordernumber', + [ + 'sessionId' => $this->getSessionId(), + 'ordernumber' => 'sw-discount', + ] + ); + + static::assertIsArray($discount); + static::assertSame(0, (int) $discount['tax_rate']); + + // Housekeeping + $this->connection->delete( + 's_order_basket', + ['sessionID' => $this->getSessionId()] + ); + + $modelManager = $this->getContainer()->get('models'); + $modelManager->remove($taxRule); + $modelManager->remove($customerGroupDiscount); + + $modelManager->flush(); + } + public function testsCheckBasketQuantitiesWithHigherQuantityThanAvailable(): void { $this->generateBasketSession(); @@ -2677,4 +2718,27 @@ private function getSessionId(): string { return $this->session->get('sessionId'); } + + private function createTaxFreeTaxRule(CustomerGroup $group): TaxRule + { + $resourceHelper = new Helper($this->getContainer()); + + return $resourceHelper->createTaxRule([ + 'name' => 'PHPUNIT-TAX-FREE', + 'active' => true, + 'customerGroup' => $group, + 'groupId' => 1, + ]); + } + + private function createCustomerGroupDiscount(CustomerGroup $group): CustomerGroupDiscount + { + $resourceHelper = new Helper($this->getContainer()); + + return $resourceHelper->createCustomerGroupDiscount([ + 'group' => $group, + 'discount' => 1, + 'value' => 2, + ]); + } }