|
@@ 403-415 (lines=13) @@
|
| 400 |
|
* @param \October\Rain\Database\Builder $query |
| 401 |
|
* @return \October\Rain\Database\Builder |
| 402 |
|
*/ |
| 403 |
|
public function scopeJoinInventory(Builder $query) |
| 404 |
|
{ |
| 405 |
|
$alias = 'inventories'; |
| 406 |
|
$grammar = $query->getQuery()->getGrammar(); |
| 407 |
|
|
| 408 |
|
$subquery = Inventory::addSelect('bedard_shop_inventories.product_id') |
| 409 |
|
->selectRaw('SUM('.$grammar->wrap('bedard_shop_inventories.quantity').') as '.$grammar->wrap('inventory')) |
| 410 |
|
->groupBy('bedard_shop_inventories.product_id'); |
| 411 |
|
|
| 412 |
|
return $query |
| 413 |
|
->addSelect($alias.'.inventory') |
| 414 |
|
->joinSubquery($subquery, $alias, 'bedard_shop_products.id', '=', $alias.'.product_id', 'leftJoin'); |
| 415 |
|
} |
| 416 |
|
|
| 417 |
|
/** |
| 418 |
|
* Left joins a subquery containing the product price. |
|
@@ 423-436 (lines=14) @@
|
| 420 |
|
* @param \October\Rain\Database\Builder $query |
| 421 |
|
* @return \October\Rain\Database\Builder |
| 422 |
|
*/ |
| 423 |
|
public function scopeJoinPrice(Builder $query) |
| 424 |
|
{ |
| 425 |
|
$alias = 'prices'; |
| 426 |
|
$grammar = $query->getQuery()->getGrammar(); |
| 427 |
|
|
| 428 |
|
$subquery = Price::isActive() |
| 429 |
|
->addselect('bedard_shop_prices.product_id') |
| 430 |
|
->selectRaw('MIN('.$grammar->wrap('bedard_shop_prices.price').') as '.$grammar->wrap('price')) |
| 431 |
|
->groupBy('bedard_shop_prices.product_id'); |
| 432 |
|
|
| 433 |
|
return $query |
| 434 |
|
->addSelect($alias.'.price') |
| 435 |
|
->joinSubquery($subquery, $alias, 'bedard_shop_products.id', '=', $alias.'.product_id'); |
| 436 |
|
} |
| 437 |
|
|
| 438 |
|
/** |
| 439 |
|
* This exists to makes statuses sortable by assigning them a value. |