getUnit example

$ids = array_map(function DCategory $category) {
            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
    {
        
$context = $this->createMock(SalesChannelContext::class);

        $facade = new ItemFacade($item$stubs$helper$context);

        static::assertEquals('foo', $facade->getId());
        static::assertEquals('type', $facade->getType());
        static::assertEquals('reference', $facade->getReferencedId());
        static::assertEquals('label', $facade->getLabel());
        static::assertEquals(2, $facade->getQuantity());

        static::assertInstanceOf(PriceFacade::class$facade->getPrice());
        static::assertEquals(10, $facade->getPrice()->getUnit());
        static::assertEquals(10, $facade->getPrice()->getTotal());

        static::assertEquals('bar', $facade->getPayload()->offsetGet('foo'));
        // @phpstan-ignore-next-line         static::assertEquals('bar', $facade->getPayload()['foo']);
        static::assertEquals('nested', $facade->getPayload()->offsetGet('nested')['foo']);

        // @phpstan-ignore-next-line         static::assertEquals('nested', $facade->getPayload()['nested']['foo']);

        static::assertCount(0, $facade->getChildren());
    }
->getArrayResult();

            foreach ($prices as $key => $price) {
                unset($price['id']);
                $price['customerGroup'] = $this->getCustomerGroupRepository()->find($price['customerGroup']['id']);
                $price['article'] = $mainDetail->getArticle();
                $prices[$key] = $price;
            }
            $mainData['prices'] = $prices;
        }
        if ($mapping['basePrice']) {
            $mainData['unit'] = $mainDetail->getUnit();
            $mainData['purchaseUnit'] = $mainDetail->getPurchaseUnit();
            $mainData['referenceUnit'] = $mainDetail->getReferenceUnit();
            $mainData['packUnit'] = $mainDetail->getPackUnit();
        }
        if ($mapping['purchasePrice']) {
            $mainData['purchasePrice'] = $mainDetail->getPurchasePrice();
        }

        return $mainData;
    }

    
$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]);
            }
public function getManufacturers(): ProductManufacturerCollection
    {
        return new ProductManufacturerCollection(
            $this->fmap(fn (ProductEntity $product) => $product->getManufacturer())
        );
    }

    public function getUnits(): UnitCollection
    {
        return new UnitCollection(
            $this->fmap(fn (ProductEntity $product) => $product->getUnit())
        );
    }

    /** * @return list<string> */
    public function getPriceIds(): array
    {
        $ids = [[]];

        foreach ($this->getIterator() as $element) {
            
public function setRule(?PriceRule $rule = null)
    {
        $this->rule = $rule;
    }

    /** * @return Unit|null */
    public function getUnit()
    {
        return $this->rule->getUnit();
    }

    /** * @return Group */
    public function getCustomerGroup()
    {
        return $this->rule->getCustomerGroup();
    }

    /** * @return int */
protected $max;

    /** * @var string */
    protected $unit;

    public static function createFromEntity(DeliveryTimeEntity $entity): self
    {
        $self = new self();
        $self->setName((string) $entity->getTranslation('name'));
        $self->setUnit($entity->getUnit());
        $self->setMax($entity->getMax());
        $self->setMin($entity->getMin());

        return $self;
    }

    public function getName(): string
    {
        return $this->name;
    }

    


            if ($this->ids->has($key)) {
                $key = $this->ids->get($key);
            }
            static::assertTrue($scope->has($key)sprintf('Can not find item %s', $key));
            $item = $scope->get($key);

            if ($expected instanceof CalculatedPrice) {
                static::assertInstanceOf(ItemFacade::class$item);
                static::assertInstanceOf(PriceFacade::class$item->getPrice());
                static::assertEquals($expected->getUnitPrice()$item->getPrice()->getUnit());
                static::assertEquals($expected->getTotalPrice()$item->getPrice()->getTotal());

                continue;
            }

            $price = $expected['price'];
            static::assertInstanceOf(ItemFacade::class$item);
            static::assertInstanceOf(PriceFacade::class$item->getPrice());
            static::assertEquals($price->getUnitPrice()$item->getPrice()->getUnit()print_r($item->getItem(), true));
            static::assertEquals($price->getTotalPrice()$item->getPrice()->getTotal());

            
\DateTimeInterface $latest
    ) {
        $earliest = new \DateTimeImmutable($earliest->format(Defaults::STORAGE_DATE_TIME_FORMAT));
        $latest = new \DateTimeImmutable($latest->format(Defaults::STORAGE_DATE_TIME_FORMAT));

        $this->earliest = $earliest->setTime(16, 0);
        $this->latest = $latest->setTime(16, 0);
    }

    public static function createFromDeliveryTime(DeliveryTime $deliveryTime): self
    {
        return match ($deliveryTime->getUnit()) {
            DeliveryTimeEntity::DELIVERY_TIME_HOUR => new self(
                self::create('PT' . $deliveryTime->getMin() . 'H'),
                self::create('PT' . $deliveryTime->getMax() . 'H')
            ),
            DeliveryTimeEntity::DELIVERY_TIME_DAY => new self(
                self::create('P' . $deliveryTime->getMin() . 'D'),
                self::create('P' . $deliveryTime->getMax() . 'D')
            ),
            DeliveryTimeEntity::DELIVERY_TIME_WEEK => new self(
                self::create('P' . $deliveryTime->getMin() . 'W'),
                self::create('P' . $deliveryTime->getMax() . 'W')
            ),
$variant = $this->getManager()->getRepository(ProductVariant::class)
            ->findOneBy(['number' => $data['articleNumber']]);

        // Load ean, unit and pack unit (translate if needed)         if ($variant instanceof ProductVariant) {
            $mainVariant = $variant->getArticle()->getMainDetail();
            $data['ean'] = $variant->getEan();
            if (!\is_string($data['ean']) && $mainVariant instanceof ProductVariant) {
                $data['ean'] = $mainVariant->getEan();
            }
            $unit = $variant->getUnit();
            if (!$unit instanceof Unit && $mainVariant instanceof ProductVariant) {
                $unit = $mainVariant->getUnit();
            }
            $data['unit'] = $unit instanceof Unit ? $unit->getName() : null;
            $data['packunit'] = $variant->getPackUnit();
            if (!\is_string($data['packunit']) && $mainVariant instanceof ProductVariant) {
                $data['packunit'] = $mainVariant->getPackUnit();
            }

            $languageData = Shopware()->Db()->fetchRow(
                'SELECT s_core_shops.default, s_order.language AS languageId FROM s_core_shops INNER JOIN s_order ON s_order.language = s_core_shops.id WHERE s_order.id = :orderId LIMIT 1',


    /** * @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 */

class StructHelper
{
    public function assignProductData(ListProduct $listProduct, ListProduct $product)
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be removed with 5.7. Will be removed without replacement.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        $product->setShippingFree($listProduct->isShippingFree());
        $product->setMainVariantId($listProduct->getMainVariantId());
        $product->setAllowsNotification($listProduct->allowsNotification());
        $product->setHighlight($listProduct->highlight());
        $product->setUnit($listProduct->getUnit());
        $product->setTax($listProduct->getTax());
        $product->setPrices($listProduct->getPrices());
        $product->setManufacturer($listProduct->getManufacturer());
        $product->setCover($listProduct->getCover());
        $product->setCheapestPrice($listProduct->getCheapestPrice());
        $product->setName($listProduct->getName());
        $product->setAdditional($listProduct->getAdditional());
        $product->setCloseouts($listProduct->isCloseouts());
        $product->setEan($listProduct->getEan());
        $product->setHeight($listProduct->getHeight());
        $product->setKeywords($listProduct->getKeywords());
        


        $price = $this->rampUpPriceFacade($ids$currencyKey$taxState);

        $update = new PriceCollection([
            new Price(Defaults::CURRENCY, 2, 5, false),
            new Price($ids->get('usd'), 1, 4, false),
        ]);

        $price->change($update);

        static::assertEquals($unit$price->getUnit());
        static::assertEquals($tax$price->getTaxes()->getAmount());
    }

    public function testChangeWithPriceFacade(): void
    {
        $ids = new IdsCollection([
            'default' => Defaults::CURRENCY,
            'usd' => Uuid::randomHex(),
        ]);

        $price = $this->rampUpPriceFacade($ids, 'default', CartPrice::TAX_STATE_GROSS);

        


        $price = $this->rampUpPriceFacade($ids$currencyKey$taxState);

        $update = new PriceCollection([
            new Price(Defaults::CURRENCY, 2, 5, false),
            new Price($ids->get('usd'), 1, 4, false),
        ]);

        $price->change($update);

        static::assertEquals($unit$price->getUnit());
        static::assertEquals($tax$price->getTaxes()->getAmount());
    }

    /** * @dataProvider providerDiscount */
    public function testDiscount(string $taxState, float $unit, float $tax): void
    {
        $ids = new IdsCollection(['default' => Defaults::CURRENCY]);

        $price = $this->rampUpPriceFacade($ids, 'default', $taxState);

        
// Reset unit data         $data['minpurchase'] = null;
        $data['maxpurchase'] = $this->config->get('maxPurchase');
        $data['purchasesteps'] = 1;
        $data['purchaseunit'] = null;
        $data['referenceunit'] = null;
        $data['packunit'] = null;
        $data['unitID'] = null;
        $data['sUnit'] = ['unit' => '', 'description' => ''];
        $data['unit_attributes'] = [];

        if ($price->getUnit() instanceof Unit) {
            $data = array_merge($data$this->convertUnitStruct($price->getUnit()));
        }

        return $this->eventManager->filter('Legacy_Struct_Converter_Convert_Product_Price', $data[
            'price' => $price,
        ]);
    }

    /** * Converts the passed ProductStream struct to an array structure. * * @return array */
Home | Imprint | This part of the site doesn't use cookies.