Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete "product" data returned by _getCollection in FieldCore.php #281

Open
sarahted opened this issue Nov 22, 2024 · 3 comments
Open

Comments

@sarahted
Copy link

I’ve encountered an issue with the data returned by the _getCollection method in modules/prettyblocks/classes/prettyblocks/core/FieldCore.php. When attempting to retrieve "product" data, the returned data is incomplete. This seems to occur because the method does not use the appropriate product presenter. As a result, several expected fields are missing from the product data.

Anyway to help with that ?

Thank you

@PrestaSafe
Copy link
Owner

Hi, can you show me the code of your selector field please ?
This field return a PrestaShopCollection.

Thanks.

@sarahted
Copy link
Author

sarahted commented Nov 25, 2024

Hi !
Thanks for your answer.

Here is my implementation of the block

class ProductCarouselBlock implements BlockInterface
{
    private $module;

    public function __construct($module)
    {
        $this->module = $module;
    }

    public function registerBlocks(): array
    {
        $logo = \HelperBuilder::pathFormattedToUrl('$/modules/'.$this->module->name.'/icons/fond-4-petites-vignettes-1-grande-vignette.svg');
        return [
            'name' => $this->module->l('Product Carousel', 'productcarousel'),
            'description' => $this->module->l('Display Product Carousel', 'productcarousel'),
            'code' => 'productcarousel',
            'tab' => 'general',
            'icon' => 'DocumentIcon',
            'icon_path' => $logo,
            'insert_default_values' => true,
            'need_reload' => false,
            'templates' => [
                'default' => 'module:' . $this->module->name . '/views/templates/blocks/product-carousel-block.tpl',
            ],
            'config' => [
                'fields' => [

                ],
            ],
            'repeater' => [
                'name' => $this->module->l('Items', 'productcarousel'),
                'nameFrom' => 'title',
                'groups' => [
                    'product' => [
                        'type' => 'selector',
                        'label' => $this->module->l('Choose a product', 'productcarousel'),
                        'collection' => 'Product',
                        'default' => '',
                        'selector' => '{id} - {name}',
                    ]
                ]
            ]


        ];
    }
}

I am missing some information with collection returned like : has_discount, main_variants and others..
I think it is due to use of ObjectPresenter instead of ProductPresenter

        $objectPresenter = new ObjectPresenter();

        return $objectPresenter->present($object);
  in `_getCollection` in `modules/prettyblocks/classes/prettyblocks/core/FieldCore.php`

This hook isn't executed

Hook::exec('actionPresentProduct',
            ['presentedProduct' => &$productLazyArray]
        );

@PrestaSafe
Copy link
Owner

Hi, thanks for you issue, i'll make some tests this week.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants