|
40 | 40 | use Shopware\Components\Random; |
41 | 41 | use Shopware\Models\Article\Detail; |
42 | 42 | use Shopware\Models\Customer\Customer; |
| 43 | +use Shopware\Models\Customer\Discount as CustomerGroupDiscount; |
| 44 | +use Shopware\Models\Customer\Group as CustomerGroup; |
| 45 | +use Shopware\Models\Tax\Rule as TaxRule; |
43 | 46 | use Shopware\Tests\Functional\Bundle\StoreFrontBundle\Helper; |
44 | 47 | use Shopware\Tests\Functional\Helper\Utils; |
45 | 48 | use Shopware\Tests\Functional\Traits\ContainerTrait; |
@@ -156,6 +159,44 @@ public function testsCheckBasketQuantitiesWithLowerQuantityThanAvailable(): void |
156 | 159 | static::assertFalse($result['articles'][$inStockProduct['ordernumber']]['OutOfStock']); |
157 | 160 | } |
158 | 161 |
|
| 162 | + public function testInsertDiscountWithTaxFreeTaxRule(): void |
| 163 | + { |
| 164 | + $this->generateBasketSession(); |
| 165 | + |
| 166 | + $customerGroupRepo = $this->getContainer()->get('models')->getRepository(CustomerGroup::class); |
| 167 | + $customerGroup = $customerGroupRepo->findOneBy(['key' => 'EK']); |
| 168 | + static::assertInstanceOf(CustomerGroup::class, $customerGroup); |
| 169 | + |
| 170 | + $taxRule = $this->createTaxFreeTaxRule($customerGroup); |
| 171 | + $customerGroupDiscount = $this->createCustomerGroupDiscount($customerGroup); |
| 172 | + |
| 173 | + $this->module->sAddArticle('SW10003'); |
| 174 | + $this->module->sInsertDiscount(); |
| 175 | + |
| 176 | + $discount = $this->connection->fetchAssociative( |
| 177 | + 'SELECT * FROM s_order_basket WHERE sessionID = :sessionId AND ordernumber = :ordernumber', |
| 178 | + [ |
| 179 | + 'sessionId' => $this->getSessionId(), |
| 180 | + 'ordernumber' => 'sw-discount', |
| 181 | + ] |
| 182 | + ); |
| 183 | + |
| 184 | + static::assertIsArray($discount); |
| 185 | + static::assertSame(0, (int) $discount['tax_rate']); |
| 186 | + |
| 187 | + // Housekeeping |
| 188 | + $this->connection->delete( |
| 189 | + 's_order_basket', |
| 190 | + ['sessionID' => $this->getSessionId()] |
| 191 | + ); |
| 192 | + |
| 193 | + $modelManager = $this->getContainer()->get('models'); |
| 194 | + $modelManager->remove($taxRule); |
| 195 | + $modelManager->remove($customerGroupDiscount); |
| 196 | + |
| 197 | + $modelManager->flush(); |
| 198 | + } |
| 199 | + |
159 | 200 | public function testsCheckBasketQuantitiesWithHigherQuantityThanAvailable(): void |
160 | 201 | { |
161 | 202 | $this->generateBasketSession(); |
@@ -2677,4 +2718,27 @@ private function getSessionId(): string |
2677 | 2718 | { |
2678 | 2719 | return $this->session->get('sessionId'); |
2679 | 2720 | } |
| 2721 | + |
| 2722 | + private function createTaxFreeTaxRule(CustomerGroup $group): TaxRule |
| 2723 | + { |
| 2724 | + $resourceHelper = new Helper($this->getContainer()); |
| 2725 | + |
| 2726 | + return $resourceHelper->createTaxRule([ |
| 2727 | + 'name' => 'PHPUNIT-TAX-FREE', |
| 2728 | + 'active' => true, |
| 2729 | + 'customerGroup' => $group, |
| 2730 | + 'groupId' => 1, |
| 2731 | + ]); |
| 2732 | + } |
| 2733 | + |
| 2734 | + private function createCustomerGroupDiscount(CustomerGroup $group): CustomerGroupDiscount |
| 2735 | + { |
| 2736 | + $resourceHelper = new Helper($this->getContainer()); |
| 2737 | + |
| 2738 | + return $resourceHelper->createCustomerGroupDiscount([ |
| 2739 | + 'group' => $group, |
| 2740 | + 'discount' => 1, |
| 2741 | + 'value' => 2, |
| 2742 | + ]); |
| 2743 | + } |
2680 | 2744 | } |
0 commit comments