getDiscounts example

'DELETE',
            $this->resourceUri . '/' . $promotionId . '/discounts/' . $discountId
        );

        $response = $this->api->getResponse();

        static::assertEquals(204, $response->getStatusCode()$response->getContent());

        /** @var PromotionEntity $promotion */
        $promotion = $this->getPromotionFromDB($promotionId);

        static::assertCount(0, $promotion->getDiscounts());
    }

    /** * This test verifies that we can update our discount with * new values. We change the type and value and then load it from * the database and see if it has been correctly updated. * * @group promotions * * @throws InconsistentCriteriaIdsException */
    
return null;
        }

        $id = $productPriceGroup->getId();
        if (!isset($priceGroups[$id])) {
            return null;
        }

        $priceGroup = $priceGroups[$id];

        $highest = null;
        foreach ($priceGroup->getDiscounts() as $discount) {
            if ($discount->getQuantity() > $quantity && !$this->config->get('useLastGraduationForCheapestPrice')) {
                continue;
            }

            if (!$highest) {
                $highest = $discount;
                continue;
            }

            if ($highest->getPercent() < $discount->getPercent()) {
                $highest = $discount;
            }

    private function buildDiscountLineItems(string $code, PromotionEntity $promotion, Cart $cart, SalesChannelContext $context): array
    {
        $collection = $promotion->getDiscounts();

        if (!$collection instanceof PromotionDiscountCollection) {
            return [];
        }

        $lineItems = [];

        foreach ($collection->getElements() as $discount) {
            $itemIds = $this->getAllLineItemIds($cart);

            // add a new discount line item for this discount
return $result;
    }

    /** * Helper function to save discounts for a given group. * * @param Group $group */
    private function saveDiscounts(array $discounts$group)
    {
        $oldDiscounts = $group->getDiscounts();
        foreach ($oldDiscounts as $oldDiscount) {
            if (!\in_array($oldDiscount$discounts)) {
                $this->getManager()->remove($oldDiscount);
            }
        }
        $this->getManager()->flush();
        /** @var Discount $discount */
        foreach ($discounts as $discount) {
            $discount->setGroup($group);
            $this->getManager()->persist($discount);
        }
    }
throw new RuntimeException(sprintf('Model object is not an instance of expected class "%s"', Tax::class));
                }
                $this->saveTaxRules($data$model);

                return;

            case 'customerGroup':
                if (isset($data['discounts'])) {
                    if (!$model instanceof CustomerGroup) {
                        throw new RuntimeException(sprintf('Model object is not an instance of expected class "%s"', CustomerGroup::class));
                    }
                    $model->getDiscounts()->clear();
                    $manager->flush();
                    $discounts = [];
                    foreach ($data['discounts'] as $discountData) {
                        $discount = new Discount();
                        $discount->setDiscount($discountData['discount']);
                        $discount->setValue($discountData['value']);
                        $discount->setGroup($model);
                        $discounts[] = $discount;
                    }

                    $data['discounts'] = $discounts;
                }
->orderBy('priceGroupDiscount.groupID')
            ->addOrderBy('priceGroupDiscount.discountstart')
            ->setParameter(':customerGroup', $customerGroup->getId());

        $data = $query->execute()->fetchAll(PDO::FETCH_GROUP);

        $priceGroups = [];

        foreach ($data as $row) {
            $priceGroup = $this->priceHydrator->hydratePriceGroup($row);

            foreach ($priceGroup->getDiscounts() as $discount) {
                $discount->setCustomerGroup($customerGroup);
            }

            $priceGroups[$priceGroup->getId()] = $priceGroup;
        }

        return $priceGroups;
    }
}
return null;
        }

        $id = $productPriceGroup->getId();
        if (!isset($priceGroups[$id])) {
            return null;
        }

        $priceGroup = $priceGroups[$id];

        $highest = null;
        foreach ($priceGroup->getDiscounts() as $discount) {
            if ($discount->getQuantity() > $quantity && !$this->config->get('useLastGraduationForCheapestPrice')) {
                continue;
            }

            if (!$highest) {
                $highest = $discount;
                continue;
            }

            if ($highest->getPercent() < $discount->getPercent()) {
                $highest = $discount;
            }
$priceGroup = $priceGroups[$priceGroupId];

            $firstGraduation = array_shift($prices[$product->getNumber()]);
            if (!$firstGraduation instanceof PriceRule) {
                continue;
            }

            $prices[$product->getNumber()] = $this->buildDiscountGraduations(
                $firstGraduation,
                $context->getCurrentCustomerGroup(),
                $priceGroup->getDiscounts()
            );
        }

        return $prices;
    }

    /** * Helper function which builds the graduated prices * of a product for the passed price group discount array. * * This function is used to override the normal graduated prices * with a definition of the product price group discounts. * * @param PriceDiscount[] $discounts * * @return array<PriceRule> */
$ruleId = 'cb34dc6f20b6479aa975e1290f442e65';
        $this->createRule($ruleId);

        $progress = $this->import($context, PromotionDiscountDefinition::ENTITY_NAME, '/fixtures/promotion_discounts.csv', 'promotion_discounts.csv');

        static::assertImportExportSucceeded($progress$this->getInvalidLogContent($progress->getInvalidRecordsLogId()));

        /** @var PromotionEntity $promotion */
        $promotion = $this->getContainer()->get('promotion.repository')->search((new Criteria([$promotionId]))->addAssociation('discounts.discountRules')$context)->first();

        static::assertInstanceOf(PromotionDiscountCollection::class$discounts = $promotion->getDiscounts());
        static::assertCount(2, $discounts);

        $firstDiscount = $discounts->first();
        static::assertInstanceOf(PromotionDiscountEntity::class$firstDiscount);
        static::assertEquals('cart', $firstDiscount->getScope());
        static::assertEquals('absolute', $firstDiscount->getType());
        static::assertEquals(5, $firstDiscount->getValue());
        static::assertFalse($firstDiscount->isConsiderAdvancedRules());
        static::assertNull($firstDiscount->getMaxValue());
        static::assertEquals('PRICE_ASC', $firstDiscount->getSorterKey());
        static::assertEquals('ALL', $firstDiscount->getApplierKey());
        
Home | Imprint | This part of the site doesn't use cookies.