¿Cómo Wirte OR/and Query en magento2.?
Aug 17 2020
SELECCIONAR main_table. sku, main_table. order_id, main_table. parent_item_id, main_table. name, main_table. product_idDESDE sales_order_itemAS main_tableDONDE ( order_id= '3') Y ( parent_item_idES NULO) Y (( skuCOMO 'WSH06%') O ( skuCOMO 'MS10%') O ( skuCOMO 'MT08%'))
$sku = ['WSH06','MS10','MT08'];
$this->itemF ->create()->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('order_id')
->addAttributeToSelect('parent_item_id')
->addAttributeToSelect('name')
->addAttributeToSelect('product_id')
->addAttributeToFilter('order_id', array('eq' => $order_id))
->addAttributeToFilter('parent_item_id', array('null' => true));
foreach ($sku as $key => $value) {
$collectionData->addFieldToFilter('sku',array('like' => $value.'%'));
}
Respuestas
1 NiravPatel Aug 17 2020 at 18:02
si desea hacer o condicionar en la colección, debe seguir los pasos a continuación.
$sku = ['WSH06','MS10','MT08'];
$this->itemF ->create()->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('order_id')
->addAttributeToSelect('parent_item_id')
->addAttributeToSelect('name')
->addAttributeToSelect('product_id')
->addAttributeToFilter('order_id', array('eq' => $order_id))
->addAttributeToFilter('parent_item_id', array('null' => true));
$likeField = [];
$likeValue = []
foreach ($sku as $key => $value) {
$likeField[] = 'sku';
$likeValue[] = array('like' => $value.'%');
}
$collectionData->addFieldToFilter($likeField, $likeValue);
echo $collectionData->getSelect()->__toString();
necesita pasar el argumento de matriz en addFieldToFilter para aplicar o condicionar.
¡Espero que esto funcione para usted!
Gracias y saludos, Nirav Patel