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%')
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP