How to get Valid From and Valid To to the Yves Product List / Detail Page ?

KFrw
KFrw Developer Posts: 7 🧑🏻‍🚀 - Cadet

What is the easiest way to display the valid from and valid to of a product?

My current solution is to add

ProductPageDataExpanderPluginInterface,

ProductConcretePageMapExpanderPluginInterface

and ProductAbstractMapExpanderPluginInterface plugins.

Inject the

\Spryker\Zed\ProductValidity\Business\ProductValidityFacade::expandProductConcreteTransfersWithValidity

Facade

create a fake ProductConcreteTransfer, add the ID

then get from the transfer the validity

And add this to the page Search data so it can be displayed on the PLP.

But that seems a bit compliacted. So I hope I am missing something here. :)

And I not really understand why the product data is an array that is gathered by direct DB Queries and not provided by the product client.

Cheers Karsten

Answers

  • KFrw
    KFrw Developer Posts: 7 🧑🏻‍🚀 - Cadet
    edited May 21

    I now do this ofc with DI and Factory 😘

    public function expandProductPageData(
        array $productData,
        ProductPageSearchTransfer $productAbstractPageSearchTransfer,
    ): void {
        $productFacade = $this->getFactory()->getIpsProductFacade();
        $productValidityFacade = $this->getFactory()->getValidityFacade();
    
        $productConcreteTransfer = new ProductConcreteTransfer();
    
        $productConcretes = $productFacade->getConcreteProductsByAbstractProductId($productData['fk_product_abstract']);
        if (count($productConcretes) !== 1) {
            return;
        }
        $productConcreteTransfer->setIdProductConcrete($productConcretes[0]->getIdProductConcrete());
        $productValidityTransfers = $productValidityFacade->expandProductConcreteTransfersWithValidity([$productConcreteTransfer]);
    
        if (count($productValidityTransfers) !== 1) {
            return;
        }
    
        $productAbstractPageSearchTransfer->setValidFrom($productValidityTransfers[0]->getValidFrom());
        $productAbstractPageSearchTransfer->setValidTo($productValidityTransfers[0]->getValidTo());
    }