1

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%')

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.