使用 corcel 检索简单产品和 product_variation
retrieve simple products and product_variation with corcel
在 larvel 中,我正在使用 corcel and with the help of this comment 我试图仅检索简单产品和可变产品的变体。
$type = array('product_variation','product');
$status = 'publish';
$posts =
\Corcel\Model\Post::
type($type)->
whereHas('taxonomies', function($q) {
$q->where('taxonomy', 'product_type')
->whereHas('term', function($q) {
$q->where('slug', 'simple');
})
// since variations have no product_type taxonomy, then
->orwhere('taxonomy','<>', 'product_type');
})->
status($status)->
latest()->
limit(500)->
get();
return $posts;
但它只有returnsproduct_variation(s),而且没有简单的产品。谁能解释一下我做错了什么?
我遇到了同样的问题,我意识到我可以使用 doesntHave
$posts = \Corcel\Model\Post::status('publish')
->whereIn('post_type', ['product_variation','product'] )
->doesntHave('taxonomies')
->orWhereHas('taxonomies', function ($query) {
$query->whereIn('taxonomy',['product_type'])
->whereHas('term', function($q) {
$q->where('slug', 'simple');
});
})
->latest()
->limit(50)
->get();
return $posts;
在 larvel 中,我正在使用 corcel and with the help of this comment 我试图仅检索简单产品和可变产品的变体。
$type = array('product_variation','product');
$status = 'publish';
$posts =
\Corcel\Model\Post::
type($type)->
whereHas('taxonomies', function($q) {
$q->where('taxonomy', 'product_type')
->whereHas('term', function($q) {
$q->where('slug', 'simple');
})
// since variations have no product_type taxonomy, then
->orwhere('taxonomy','<>', 'product_type');
})->
status($status)->
latest()->
limit(500)->
get();
return $posts;
但它只有returnsproduct_variation(s),而且没有简单的产品。谁能解释一下我做错了什么?
我遇到了同样的问题,我意识到我可以使用 doesntHave
$posts = \Corcel\Model\Post::status('publish')
->whereIn('post_type', ['product_variation','product'] )
->doesntHave('taxonomies')
->orWhereHas('taxonomies', function ($query) {
$query->whereIn('taxonomy',['product_type'])
->whereHas('term', function($q) {
$q->where('slug', 'simple');
});
})
->latest()
->limit(50)
->get();
return $posts;