TransWikia.com

I need to set the 'OR' condtion for last where clause but it is setting as AND how can change in magento 2.3

Magento Asked by Sabareesh on December 13, 2020

SQL need to change AND condtion to OR in below code

public function getOrders()
    {
        $po_number = "%"."A"."%";
        if (!($customerId = $this->_customerSession->getCustomerId())) {
            return false;
        }
        if (!$this->orders) {
            $this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
                '*'
            )->addFieldToFilter(
                'status',
                ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
            );
            $this->orders->getSelect()
            ->joinLeft(
                ["sop" => "amt_sales_order_payment"],
                'main_table.entity_id = sop.parent_id',
                ['po_number']
            )
            ->where('sop.po_number LIKE ?',$po_number);
            
            $this->orders->setOrder(
            'ext_order_id',
            'desc'
            );
            echo  $this->orders->getSelect()->__toString();
        }
        return $this->orders;
    }

I the po_number OR condtion need to apply how can i apply this.

Current Query

SELECT `main_table`.*, `sop`.`po_number` FROM `sales_order` AS `main_table` LEFT JOIN `sales_order_payment` AS `sop` ON main_table.entity_id = sop.parent_id WHERE (`main_table`.`customer_id` = '200') AND (`status` IN('canceled', 'closed', 'complete', 'fraud', 'holded', 'partially_shipped', 'payment_review', 'pending', 'processing', 'shipped')) AND (sop.po_number LIKE '%A%')

Expecting Query

SELECT `main_table`.*, `sop`.`po_number` FROM `sales_order` AS `main_table` LEFT JOIN `sales_order_payment` AS `sop` ON main_table.entity_id = sop.parent_id WHERE (`main_table`.`customer_id` = '200') AND (`status` IN('canceled', 'closed', 'complete', 'fraud', 'holded', 'partially_shipped', 'payment_review', 'pending', 'processing', 'shipped')) OR (sop.po_number LIKE '%A%')

One Answer

try replacing ->where('sop.po_number LIKE ?',$po_number); with ->orWhere('sop.po_number LIKE ?',$po_number);

Correct answer by Marius on December 13, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP