getStock example

->method('load')
            ->willReturn(new StockDataCollection([$stock1$stock2]));

        $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'));
    }

    
'name' => 'test product',
                    '_uniqueIdentifier' => $id . '_' . Defaults::LANGUAGE_SYSTEM,
                ]),
            ]),
        ]);
        $product->setUniqueIdentifier($id);

        $result = iterator_to_array($entityPipe->in($config$product->jsonSerialize()));

        static::assertSame($product->getId()$result['id']);
        static::assertSame($product->getTranslations()->first()->getName()$result['translations']['DEFAULT']['name']);
        static::assertSame((string) $product->getStock()$result['stock']);
        static::assertSame($product->getProductNumber()$result['productNumber']);
        static::assertSame('1', $result['active']);

        $result = iterator_to_array($entityPipe->out($config$result));

        static::assertSame($product->getId()$result['id']);
        static::assertSame($product->getTranslations()->first()->getName()$result['translations'][Defaults::LANGUAGE_SYSTEM]['name']);
        static::assertSame($product->getStock()$result['stock']);
        static::assertSame($product->getProductNumber()$result['productNumber']);
        static::assertSame($product->getActive()$result['active']);
    }
}
$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]);
            }
'purchasePrices' => $purchasePrices ? json_encode($purchasePrices, \JSON_THROW_ON_ERROR) : null,
            'productNumber' => $product->getProductNumber(),
            'manufacturerId' => $product->getManufacturerId(),
            'taxId' => $product->getTaxId(),
            'tagIds' => $product->getTagIds(),
            'categoryIds' => $product->getCategoryTree(),
            'propertyIds' => $product->getPropertyIds(),
            'optionIds' => $product->getOptionIds(),
            'options' => $product->getVariation(),
            'streamIds' => $product->getStreamIds(),
            'parentId' => $product->getParentId(),
            'stock' => $product->getStock(),
        ];

        $lineItem->replacePayload($payload['purchasePrices' => true]);
    }

    private function getPriceDefinition(SalesChannelProductEntity $product, SalesChannelContext $context, int $quantity): QuantityPriceDefinition
    {
        $this->priceCalculator->calculate([$product]$context);

        if ($product->getCalculatedPrices()->count() === 0) {
            return $this->buildPriceDefinition($product->getCalculatedPrice()$quantity);
        }


    /** * @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 */
// if the line item has a restock time, add this days to the restock date             if ($restockTime) {
                $restockDate = $restockDate->add(new \DateInterval('P' . $restockTime . 'D'));
            }

            if ($item->getPrice() === null) {
                continue;
            }

            // if the item is completely in stock, use the delivery date             if ($item->getDeliveryInformation()->getStock() >= $item->getQuantity()) {
                $position = new DeliveryPosition($item->getId()clone $item$item->getQuantity()clone $item->getPrice()$deliveryDate);
            } else {
                // otherwise use the restock date as delivery date                 $position = new DeliveryPosition($item->getId()clone $item$item->getQuantity()clone $item->getPrice()$restockDate);
            }

            $positions->add($position);
        }
    }
}
$product->setAdditional($listProduct->getAdditional());
        $product->setCloseouts($listProduct->isCloseouts());
        $product->setEan($listProduct->getEan());
        $product->setHeight($listProduct->getHeight());
        $product->setKeywords($listProduct->getKeywords());
        $product->setLength($listProduct->getLength());
        $product->setLongDescription($listProduct->getLongDescription());
        $product->setMinStock($listProduct->getMinStock());
        $product->setReleaseDate($listProduct->getReleaseDate());
        $product->setShippingTime($listProduct->getShippingTime());
        $product->setShortDescription($listProduct->getShortDescription());
        $product->setStock($listProduct->getStock());
        $product->setWeight($listProduct->getWeight());
        $product->setWidth($listProduct->getWidth());
        $product->setPriceGroup($listProduct->getPriceGroup());
        $product->setCreatedAt($listProduct->getCreatedAt());
        $product->setUpdatedAt($listProduct->getUpdatedAt());
        $product->setPriceRules($listProduct->getPriceRules());
        $product->setCheapestPriceRule($listProduct->getCheapestPriceRule());
        $product->setManufacturerNumber($listProduct->getManufacturerNumber());
        $product->setMetaTitle($listProduct->getMetaTitle());
        $product->setTemplate($listProduct->getTemplate());
        $product->setHasConfigurator($listProduct->hasConfigurator());
        

        if ($this->stock === null) {
            throw new UnsupportedValueException(\gettype($this->stock), self::class);
        }

        $deliveryInformation = $lineItem->getDeliveryInformation();

        if (!$deliveryInformation instanceof DeliveryInformation) {
            return RuleComparison::isNegativeOperator($this->operator);
        }

        return RuleComparison::numeric($deliveryInformation->getStock()$this->stock, $this->operator);
    }

    /** * @param LineItem[] $lineItems */
    private function matchStockFromCollection(array $lineItems): bool
    {
        foreach ($lineItems as $lineItem) {
            if ($this->matchStock($lineItem)) {
                return true;
            }
        }
static::assertInstanceOf(ProductEntity::class$product);
        static::assertTrue($product->getAvailable());
        static::assertSame(5, $product->getAvailableStock());

        $this->orderProduct($id, 1);

        $product = $this->productRepository->search(new Criteria([$id])$context)->get($id);

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertTrue($product->getAvailable());
        static::assertSame(4, $product->getAvailableStock());
        static::assertSame(5, $product->getStock());
    }

    public function testAvailableAfterCancel(): void
    {
        $context = Context::createDefaultContext();
        $initialStock = 12;
        $orderQuantity = 8;

        $productId = $this->createProduct([
            'stock' => $initialStock,
        ]);
        
$data = [
            'articleID' => $product->getId(),
            'articleDetailsID' => $product->getVariantId(),
            'ordernumber' => $product->getNumber(),
            'highlight' => $product->highlight(),
            'description' => $product->getShortDescription(),
            'description_long' => $product->getLongDescription(),
            'esd' => $product->hasEsd(),
            'articleName' => $product->getName(),
            'taxID' => $product->getTax()->getId(),
            'tax' => $tax->getTax(),
            'instock' => $product->getStock(),
            'isAvailable' => $product->isAvailable(),
            'hasAvailableVariant' => $product->hasAvailableVariant(),
            'weight' => $product->getWeight(),
            'shippingtime' => $product->getShippingTime(),
            'pricegroupActive' => false,
            'pricegroupID' => null,
            'length' => $product->getLength(),
            'height' => $product->getHeight(),
            'width' => $product->getWidth(),
            'laststock' => $product->isCloseouts(),
            'additionaltext' => $product->getAdditional(),
            
$product = $this->productRepository->search(new Criteria([$id])$context)->get($id);

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertTrue($product->getAvailable());
        $this->assertStock(5, $product);
    }

    private function assertStock(int $expectedStock, ProductEntity $product): void
    {
        static::assertSame($expectedStock$product->getAvailableStock());
        static::assertSame($expectedStock$product->getStock());
    }

    private function createCustomer(): string
    {
        $customerId = Uuid::randomHex();
        $addressId = Uuid::randomHex();

        $customer = [
            'id' => $customerId,
            'number' => '1337',
            'salutationId' => $this->getValidSalutationId(),
            
$this->productMediaRepository,
            $this->productConfiguratorSettingRepository
        );
        $serializer->setRegistry($this->getContainer()->get(SerializerRegistry::class));

        $serialized = iterator_to_array($serializer->serialize(new Config([][][])$productDefinition$product));

        static::assertNotEmpty($serialized);

        static::assertSame($product->getId()$serialized['id']);
        static::assertSame($product->getTranslations()->first()->getName()$serialized['translations']['DEFAULT']['name']);
        static::assertSame((string) $product->getStock()$serialized['stock']);
        static::assertSame($product->getProductNumber()$serialized['productNumber']);
        static::assertSame('1', $serialized['active']);
        static::assertStringContainsString('shopware-logo.png', $serialized['cover']['media']['url']);
        static::assertStringContainsString('shopware-icon.png', $serialized['media']);
        static::assertStringContainsString('shopware-background.png', $serialized['media']);
        static::assertStringNotContainsString('shopware-logo.png', $serialized['media']);

        $deserialized = iterator_to_array($serializer->deserialize(new Config([][][])$productDefinition$serialized));

        static::assertSame($product->getId()$deserialized['id']);
        static::assertSame($product->getTranslations()->first()->getName()$deserialized['translations'][Defaults::LANGUAGE_SYSTEM]['name']);
        
Home | Imprint | This part of the site doesn't use cookies.