getPercent example

if (!$price instanceof PriceRule) {
                continue;
            }

            $discount = $this->getHighestQuantityDiscount($product$context$price->getFrom());

            if (!$discount) {
                continue;
            }
            $price->setPrice(
                $price->getPrice() / 100 * (100 - $discount->getPercent())
            );
        }

        return $prices;
    }

    /** * Helper function which iterates the products and builds a price array which indexed * with the product order number. * * @param BaseProduct[] $products * @param PriceRule[] $priceRules * * @return array<string, PriceRule> */

    public function testConstructor(): void
    {
        $points = 2;
        $count = 3;
        $percent = 1.0;

        $element = new MatrixElement($points$count$percent);

        static::assertEquals($points$element->getPoints());
        static::assertEquals($count$element->getCount());
        static::assertEquals($percent$element->getPercent());
    }

    /** * test point getter and setter * * @group reviews */
    public function testPointsGetterSetter(): void
    {
        $expected = 2;
        $this->element->setPoints($expected);

        
$previous = null;
        if ($firstDiscount->getQuantity() > 1) {
            $firstGraduation = clone $reference;
            $previous = $firstGraduation;

            $prices[] = $firstGraduation;
        }

        foreach ($discounts as $discount) {
            $rule = clone $reference;

            $percent = (100 - $discount->getPercent()) / 100;

            $price = $reference->getPrice() * $percent;

            $pseudo = $reference->getPseudoPrice();

            $rule->setPrice($price);

            $rule->setPseudoPrice($pseudo);

            $rule->setFrom($discount->getQuantity());

            
private function calculatePriceGroupDiscounts(ListProduct $product, PriceRule $price, ShopContextInterface $context): PriceRule
    {
        if (!$product->isPriceGroupActive()) {
            return $price;
        }

        $discount = $this->getHighestQuantityDiscount($product$context$price->getFrom());

        if (!$discount instanceof PriceDiscount) {
            return $price;
        }
        $price->setPrice($price->getPrice() / 100 * (100 - $discount->getPercent()));

        return $price;
    }

    /** * Returns the highest price group discount for the provided product. * * The price groups are stored in the provided context object. * If the product has no configured price group or the price group has no discount defined for the * current customer group, the function returns null. */
    
static::assertCount(5, $matrix->getMatrix());

        /** @var MatrixElement[] $matrixElements */
        $matrixElements = $matrix->getMatrix();

        for ($i = 1; $i <= $matrix->getMaxPoints(); ++$i) {
            $matrixElement = $matrixElements[$i];
            $expected = round($ratingCounts[$i] * 100 / $totalReviews, 4);
            static::assertEquals($i$matrixElement->getPoints()sprintf('The rating with %d points has errors!', $i));
            static::assertEquals($ratingCounts[$i]$matrixElement->getCount()sprintf('The count of reviews with %d points has errors!', $i));
            static::assertEquals($expectedround($matrixElement->getPercent(), 4)sprintf('Calculation of percentage with %d points has errors!', $i));
        }
    }

    /** * function tests that every MatrixElement struct is generated correctly by matrix constructor using float values * * @group reviews */
    public function testMatrixElementsWithFloatValues(): void
    {
        $ratingCounts = [1 => 2, 2 => 3, 3 => 3, 4 => 4, 5 => 12];
        
Home | Imprint | This part of the site doesn't use cookies.