ProductProxy example

public function getDecorated(): AbstractProductPriceCalculator
    {
        return $this->decorated;
    }

    public function calculate(iterable $products, SalesChannelContext $context): void
    {
        $this->decorated->calculate($products$context);

        $proxies = [];
        foreach ($products as $product) {
            $proxies[$product->get('id')] = new ProductProxy($product$context$this->priceStubs);
        }

        $this->scriptExecutor->execute(new ProductPricingHook($proxies$context));
    }
}
$stubs = $this->getContainer()->get(ScriptPriceStubs::class);

        $p1 = $products->get($ids->get('p1'));
        $p2 = $products->get($ids->get('p2'));
        $p3 = $products->get($ids->get('p3.1'));

        static::assertInstanceOf(Entity::class$p1);
        static::assertInstanceOf(Entity::class$p2);
        static::assertInstanceOf(Entity::class$p3);

        $proxies = [
            $ids->get('p1') => new ProductProxy($p1$salesChannelContext$stubs),
            $ids->get('p2') => new ProductProxy($p2$salesChannelContext$stubs),
            $ids->get('p3.1') => new ProductProxy($p3$salesChannelContext$stubs),
        ];

        $salesChannelContext->considerInheritance();
        $hook = new ProductPricingHookExtension($proxies$salesChannelContext$ids);

        // allows easy debugging         $traces = new ScriptTraces();

        $loader = $this->createMock(ScriptLoader::class);
        
new CalculatedCheapestPrice(8, 8, new CalculatedTaxCollection()new TaxRuleCollection())
        );

        $product->setCalculatedPrices(new PriceCollection([
            new CalculatedPrice(9, 9, new CalculatedTaxCollection()new TaxRuleCollection()),
        ]));

        $context = $this->createMock(SalesChannelContext::class);

        $stubs = $this->createMock(ScriptPriceStubs::class);

        $proxy = new ProductProxy($product$context$stubs);

        // @phpstan-ignore-next-line > Access to an undefined property occurs here but the proxy by pass the access to the entity.get() function         static::assertInstanceOf(PriceFacade::class$proxy->calculatedPrice, 'Proxy should return a facade for the calculated price');
        // @phpstan-ignore-next-line > Access to an undefined property occurs here but the proxy by pass the access to the entity.get() function         static::assertInstanceOf(PriceCollectionFacade::class$proxy->calculatedPrices, 'Proxy should return a facade for the calculated prices');
        // @phpstan-ignore-next-line > Access to an undefined property occurs here but the proxy by pass the access to the entity.get() function         static::assertInstanceOf(PriceFacade::class$proxy->calculatedCheapestPrice, 'Proxy should return a facade for the calculated cheapest price');
        // @phpstan-ignore-next-line > Access to an undefined property occurs here but the proxy by pass the access to the entity.get() function         static::assertEquals('foo', $proxy->name, 'Proxy should return the same value as the original object');

        static::assertArrayHasKey('stock', $proxy, 'Proxy should be able to check if a property exists');
    }
Home | Imprint | This part of the site doesn't use cookies.