magento2에서 OR / 및 쿼리를 작성하는 방법.?
SELECT main_table
. sku
, main_table
. order_id
, main_table
. parent_item_id
, main_table
. name
, main_table
. product_id
FROM sales_order_item
AS main_table
WHERE ( order_id
= '3') AND ( parent_item_id
IS NULL) AND (( sku
LIKE 'WSH06 %') OR ( sku
LIKE 'MS10 %') OR ( sku
LIKE '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.'%'));
}
답변
1 NiravPatel
컬렉션을 만들거나 조건을 지정하려면 아래 단계를 따라야합니다.
$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();
적용하거나 조건을 지정하려면 addFieldToFilter에 배열 인수를 전달해야합니다.
이것이 당신을 위해 일하기를 바랍니다!
감사합니다. Nirav Patel