getTaxId example

 $context);

        $this->import($context, ProductDefinition::ENTITY_NAME, '/fixtures/products_with_own_identifier.csv', 'products.csv');

        $criteria = new Criteria([$productIds[0]]);
        $criteria->addAssociation('categories');

        $product = $this->productRepository->search($criteria$context)->first();

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertNotSame($name$product->getName());
        static::assertSame(Uuid::fromStringToHex('tax19')$product->getTaxId());
        static::assertSame(Uuid::fromStringToHex('manufacturer1')$product->getManufacturerId());

        static::assertInstanceOf(CategoryCollection::class$categories = $product->getCategories());
        static::assertCount(3, $categories);
        static::assertTrue($categories->has($category1Id));
        static::assertTrue($categories->has($category2Id));
        static::assertTrue($categories->has($category3Id));
    }

    public function testProductsWithCategoryPaths(): void
    {
        
static::assertInstanceOf(Price::class$parent->getCurrencyPrice(Defaults::CURRENCY));
        static::assertEquals(50, $parent->getCurrencyPrice(Defaults::CURRENCY)->getGross());

        /** @var ProductEntity $red */
        $red = $products->get($redId);

        // check red product contains full inheritance of parent         static::assertInstanceOf(ProductEntity::class$red);

        // has no own tax         static::assertNull($red->getTax());
        static::assertNull($red->getTaxId());
        static::assertNull($red->getCurrencyPrice(Defaults::CURRENCY));

        /** @var ProductEntity $green */
        $green = $products->get($greenId);

        static::assertInstanceOf(ProductEntity::class$green);
        static::assertInstanceOf(TaxEntity::class$green->getTax());
        static::assertEquals($greenTax$green->getTaxId());
        static::assertInstanceOf(Price::class$green->getCurrencyPrice(Defaults::CURRENCY));
        static::assertEquals(100, $green->getCurrencyPrice(Defaults::CURRENCY)->getGross());

        
public function filterByParentId(string $id): self
    {
        return $this->filter(fn (ProductEntity $product) => $product->getParentId() === $id);
    }

    /** * @return list<string> */
    public function getTaxIds(): array
    {
        /** @var list<string> $ids */
        $ids = $this->fmap(fn (ProductEntity $product) => $product->getTaxId());

        return $ids;
    }

    public function filterByTaxId(string $id): self
    {
        return $this->filter(fn (ProductEntity $product) => $product->getTaxId() === $id);
    }

    /** * @return list<string> */
$product = $products->get($ids[0]);

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertInstanceOf(TaxEntity::class$product->getTax());
        static::assertSame('without id', $product->getTax()->getName());
        static::assertSame(19.0, $product->getTax()->getTaxRate());

        $product = $products->get($ids[1]);
        static::assertInstanceOf(ProductEntity::class$product);
        static::assertInstanceOf(TaxEntity::class$product->getTax());
        static::assertSame($tax$product->getTaxId());
        static::assertSame($tax$product->getTax()->getId());
        static::assertSame('with id', $product->getTax()->getName());
        static::assertSame(18.0, $product->getTax()->getTaxRate());

        $product = $products->get($ids[2]);
        static::assertInstanceOf(ProductEntity::class$product);
        static::assertInstanceOf(TaxEntity::class$product->getTax());
        static::assertSame($tax$product->getTaxId());
        static::assertSame($tax$product->getTax()->getId());
        static::assertSame('with id', $product->getTax()->getName());
        static::assertSame(18.0, $product->getTax()->getTaxRate());

        
$payload = [
            'isCloseout' => $product->getIsCloseout(),
            'customFields' => $product->getCustomFields(),
            'createdAt' => $product->getCreatedAt() ? $product->getCreatedAt()->format(Defaults::STORAGE_DATE_TIME_FORMAT) : null,
            'releaseDate' => $product->getReleaseDate() ? $product->getReleaseDate()->format(Defaults::STORAGE_DATE_TIME_FORMAT) : null,
            'isNew' => $product->isNew(),
            'markAsTopseller' => $product->getMarkAsTopseller(),
            '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]);
    }
Home | Imprint | This part of the site doesn't use cookies.