AnswerBun.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!

Related Questions

Add option to product in the cart progrmatically in magento 2

2  Asked on September 12, 2020 by anantchopra2007

 

Magento 2 Access-Control-Allow-Origin

2  Asked on September 9, 2020 by borche-glafche

   

Magento 2: what is the catalog_attributes.xml file?

2  Asked on September 7, 2020 by raphael-at-digital-pianism

       

magento 2 – modify db_schema.xml field length

1  Asked on September 4, 2020 by sairaj-gadekar

 

Magento 2.3.2 Upgrade to 2.4

2  Asked on September 4, 2020 by hatim

 

Magento 2: Make sales without stock

1  Asked on August 9, 2020 by hudson-alves-triunfante

     

Magento 2 : print_r or var_dump is not working

4  Asked on July 30, 2020 by zed-blackbeard

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir