Jump to content

Generate Product Lazy Array from Product Object


Recommended Posts

Hi guys, I'm searching a way to convert a Product Object to a ProductLazyArray.

I've tried this :

    /**
     * @param array $product
     * @return array
     * @throws ReflectionException
     */
    public static function getProductLazyArray(array $product){
        $context = Context::getContext();
        $presenter = new ProductPresenterFactory($context);
        return $presenter->getPresenter()->present(
            $presenter->getPresentationSettings(),
            $product,
            $context->language
        );
    }

And i called it that way :

Tools::getProductLazyArray((array) $productObject)

But obviously, as I can see in ProductLazyarry, the id of a product is get like that :

$product['id_product']

So it doesn't match a Product Object converted in array which is :

$productObject['id']

Then I understand that I better do sql query to get my row of the product in the db, but I don't really think that the most efficient way ?

If anybody else know an easy way to convert a product Object to ProductLazyArray, which is usable with product miniatures tpl.

I've already saw the possibility to fake a search and then generate a ProductListingLazyArray, but it doesn't match what I want, something efficient, quick and scalable and a ProductLazyArray.

I would be awfully suprised that there isn't any way to quickly convert a Product Object to a ProductLazyArray natively.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...