getMinPurchase example

/** * Calculates the cheapest price considering the variant min purchase */
    private function calculateCheapestAvailablePrice(
        ListProduct $product,
        PriceRule $priceRule,
        ShopContextInterface $context
    ): Price {
        if ($priceRule->getUnit() instanceof Unit) {
            $priceRule->setPrice(
                $priceRule->getUnit()->getMinPurchase() * $priceRule->getPrice()
            );
            $priceRule->getUnit()->setPurchaseUnit(
                $priceRule->getUnit()->getMinPurchase() * $priceRule->getUnit()->getPurchaseUnit()
            );
            $priceRule->setPseudoPrice(
                $priceRule->getUnit()->getMinPurchase() * $priceRule->getPseudoPrice()
            );

            $priceRule->setRegulationPrice(
                $priceRule->getUnit()->getMinPurchase() * $priceRule->getRegulationPrice()
            );
        }


    /** * @return bool */
    public function isAvailable()
    {
        if (!$this->isCloseouts()) {
            return true;
        }

        return $this->getStock() >= $this->getUnit()->getMinPurchase();
    }

    /** * @param float $weight */
    public function setWeight($weight)
    {
        $this->weight = $weight;
    }

    /** * @return float */
$event = new SalesChannelEntityLoadedEvent(
            $this->createMock(SalesChannelProductDefinition::class),
            [$p1$p2],
            $this->createMock(SalesChannelContext::class)
        );

        $subscriber->salesChannelLoaded($event);

        static::assertEquals(10, $p1->getStock());
        static::assertFalse($p1->getAvailable());
        static::assertEquals(5, $p1->getMinPurchase());
        static::assertTrue($p1->hasExtension('stock_data'));
        static::assertSame($stock1$p1->getExtension('stock_data'));

        static::assertEquals(12, $p2->getStock());
        static::assertTrue($p2->getAvailable());
        static::assertNull($p2->getMinPurchase());
        static::assertTrue($p2->hasExtension('stock_data'));
        static::assertSame($stock2$p2->getExtension('stock_data'));
    }

    public function testStockDataIsAppliedFromStorageWithPartialEntities(): void
    {
// only needed one time to check max quantity             $refs[$productId] = $lineItem;
        }

        foreach ($quantities as $productId => $quantity) {
            $lineItem = $refs[$productId];
            $quantityInformation = $lineItem->getQuantityInformation();
            if ($quantityInformation === null) {
                continue;
            }

            $minPurchase = $quantityInformation->getMinPurchase();
            $available = $quantityInformation->getMaxPurchase() ?? 0;
            $steps = $quantityInformation->getPurchaseSteps() ?? 1;

            if ($available >= $quantity) {
                continue;
            }

            $maxAvailable = (int) (floor(($available - $minPurchase) / $steps) * $steps + $minPurchase);

            $cart->addErrors(
                new ProductStockReachedError($productId(string) $lineItem->getLabel()$maxAvailable, false),
            );
$availability = $this->listingVariationLoader->getAvailability($products$variantConfiguration$variantFacet);
        }

        $manualPositions = $this->manualPositionLoader->get($productIds);

        $result = [];
        foreach ($products as $listProduct) {
            $product = Product::createFromListProduct($listProduct);
            $number = $product->getNumber();
            $id = $product->getId();

            $product->setHasStock($product->getStock() >= $product->getUnit()->getMinPurchase());

            if ($variantFacet && $variantConfiguration) {
                $this->addVariantSearchDetails($product$configurations$variantFacet$variantConfiguration$combinations$listingPrices$availability);
            } elseif (!$product->isMainVariant()) {
                continue;
            } elseif (!$listProduct->isAvailable()) {
                $product->setHasAvailableVariant(false);
            }

            if (isset($average[$number])) {
                $product->setVoteAverage($average[$number]);
            }
return $this->eventManager->filter('Legacy_Struct_Converter_Convert_Media', $data[
            'media' => $media,
        ]);
    }

    /** * @return array */
    public function convertUnitStruct(Unit $unit)
    {
        $data = [
            'minpurchase' => $unit->getMinPurchase(),
            'maxpurchase' => $unit->getMaxPurchase() ?: $this->config->get('maxPurchase'),
            'purchasesteps' => $unit->getPurchaseStep() ?: 1,
            'purchaseunit' => $unit->getPurchaseUnit(),
            'referenceunit' => $unit->getReferenceUnit(),
            'packunit' => $unit->getPackUnit(),
            'unitID' => $unit->getId(),
            'sUnit' => [
                'unit' => $unit->getUnit(),
                'description' => $unit->getName(),
            ],
            'unit_attributes' => $unit->getAttributes(),
        ];
return $category->getId();
        }$product->getCategories());

        return \in_array($context->getShop()->getCategory()->getId()$ids);
    }

    private function allowBuyInListing(ListProduct $product): bool
    {
        return !$product->hasConfigurator()
            && $product->isAvailable()
            && $product->getUnit()
            && $product->getUnit()->getMinPurchase() <= 1
            && !$product->displayFromPrice();
    }

    /** * @param ListProduct[] $products * * @return array<int> */
    private function getManufacturerCoverIds(array $products): array
    {
        $ids = array_map(function DListProduct $product) {
            
private function validateStock(LineItem $item, Cart $cart, LineItemCollection $scope, CartBehavior $behavior): void
    {
        if ($behavior->hasPermission(self::SKIP_PRODUCT_STOCK_VALIDATION)) {
            return;
        }

        $minPurchase = 1;
        $steps = 1;
        $available = $item->getQuantity();

        if ($item->getQuantityInformation() !== null) {
            $minPurchase = $item->getQuantityInformation()->getMinPurchase();
            $available = $item->getQuantityInformation()->getMaxPurchase() ?? 0;
            $steps = $item->getQuantityInformation()->getPurchaseSteps() ?? 1;
        }

        if ($available < $minPurchase) {
            $scope->remove($item->getId());

            $cart->addErrors(
                new ProductOutOfStockError((string) $item->getReferencedId()(string) $item->getLabel())
            );

            

    protected function getMappingData($mainDetail$mapping)
    {
        $mainData = [];
        if ($mapping['settings']) {
            $mainData['supplierNumber'] = $mainDetail->getSupplierNumber();
            $mainData['weight'] = $mainDetail->getWeight();
            $mainData['stockMin'] = $mainDetail->getStockMin();
            $mainData['ean'] = $mainDetail->getEan();
            $mainData['minPurchase'] = $mainDetail->getMinPurchase();
            $mainData['purchaseSteps'] = $mainDetail->getPurchaseSteps();
            $mainData['maxPurchase'] = $mainDetail->getMaxPurchase();
            $mainData['releaseDate'] = $mainDetail->getReleaseDate();
            $mainData['shippingTime'] = $mainDetail->getShippingTime();
            $mainData['shippingFree'] = $mainDetail->getShippingFree();
            $mainData['width'] = $mainDetail->getWidth();
            $mainData['height'] = $mainDetail->getHeight();
            $mainData['len'] = $mainDetail->getLen();
            $mainData['lastStock'] = $mainDetail->getLastStock();
        }
        if ($mapping['stock']) {
            
Home | Imprint | This part of the site doesn't use cookies.