Question

I'm trying to add an extension attribute to my order entity.

I've follewed this link : https://www.rakeshjesadiya.com/extension-attribute-in-order-data-magento-2/

But I can see my extension attribute in my backend order entity.

Also, for the /sales/order/history, i've this :

    public function getOrders()
{
    if (!($customerId = $this->_customerSession->getCustomerId())) {
        return false;
    }
    if (!$this->orders) {
        $this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
            '*'
        )->addFieldToFilter(
            'status',
            ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
        )->addFieldToFilter('my_attribute', array("eq" => "Some value"))
            ->addFieldToFilter("category_ids", array("nin" => 9))
            ->setOrder(
            'created_at',
            'desc'
        );
    }
    return $this->orders;
}

But I have this error :

Column not found: 1054 Unknown column 'my_attribute' in 'where clause', query was: SELECT COUNT(*) FROM sales_order AS main_table WHERE (main_table.customer_id = '70') AND (status IN('canceled', 'closed', 'complete', 'fraud', 'fraud', 'holded', 'payment_review', 'pending', 'processing')) AND (my_attribute = 'Some value') AND (category_ids NOT IN(9)) [] []

I need this because I need to hide orders where the orders contain certains category of product, if you know how to to this it woul be great !

Était-ce utile?

La solution

Extension attributes are not custom attributes. You have to personally handle their persistence (create a column|table for them in the database and save|load them).

More about this in the Official docs and an example here Magento Official Github Example documented here

Another comprehensive tutorial can be found here

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top