Read More
Read More
Menu Close

    Associations in PrestaShop 1.7 Webservice

    In this blog, we are going to learn how to create associations in the PrestaShop Webservice and get data from the association table.

    So let’s understand how to achieve it:

    Sometimes, we need to give our module association table data in API then simply we will get it with the help of PrestaShop hook and some changes in our class file.

    In PrestaShop, we can add new resources using hook hookAddWebserviceResources and give permission to get data of these added resources from the PrestaShop Webservice section.

    public function hookAddWebserviceResources()
    {
        $resources = array(
            'wk_supplier_purchase_order_manual' => array('description' => 'PO order manual', 'class' => 'WkSupplierPurchaseOrderManual')
        );
        ksort($resources);
        return $resources;
    }

    Now we will go to the class file and define the value in the protected $webserviceParameters variable for associations.

    Searching for an experienced
    Prestashop Company ?
    Read More
    protected $webserviceParameters = array(
        'associations' => array(
            'items' => array(
                'resource' => 'wk_supplier_purchase_order_detail_manual',
                'fields' => array(
                    'id_wk_supplier_purchase_order_manual' => array('required' => true),
                    'quantity' => array('required' => true),
                    'product_name' => array('required' => true),
                    'supplier_code' => array('required' => true),
                )
            )
        )
    );

    In the above code, we have defined the association array and given the association table name as a resource and fields that we want from the association table.

    After doing the above changes, you will get the association table data in your API call.

    association_in_webservice

    That’s all about this blog. Hope it will help you.

    If you are facing any issues or doubts in the above process, please feel free to contact us through the comment section.

    We would be happy to help.

    Also, you can explore our PrestaShop Development Services & a large range of quality PrestaShop Modules.

    For any doubt contact us at [email protected].

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top