2019-09-10 06:48:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Product\Console\Commands;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
use Webkul\Product\Repositories\ProductFlatRepository;
|
|
|
|
|
|
|
|
|
|
class PriceUpdate extends Command
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name and signature of the console command.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $signature = 'product:price:update';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The console command description.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $description = 'Automatically updates product information (eg. min_price and max_price)';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new command instance.
|
|
|
|
|
*
|
2020-03-05 13:37:08 +00:00
|
|
|
* @param ]Webkul\Product\Repositories\ProductFlatRepository $productFlatRepository
|
2019-09-10 06:48:01 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2022-04-01 14:57:11 +00:00
|
|
|
public function __construct(protected ProductFlatRepository $productFlatRepository)
|
2019-09-10 06:48:01 +00:00
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the console command.
|
|
|
|
|
*
|
2020-03-05 13:37:08 +00:00
|
|
|
* @return void
|
2019-09-10 06:48:01 +00:00
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
$products = $this->productFlatRepository->findWhere([['special_price', '>', 0]]);
|
|
|
|
|
|
|
|
|
|
foreach ($products as $product) {
|
|
|
|
|
request()->request->set('channel', $product->channel);
|
|
|
|
|
|
|
|
|
|
$product->min_price = $product->getTypeInstance()->getMinimalPrice();
|
|
|
|
|
|
|
|
|
|
$product->max_price = $product->getTypeInstance()->getMaximamPrice();
|
|
|
|
|
|
|
|
|
|
$product->save();
|
|
|
|
|
|
|
|
|
|
if ($product->parent) {
|
|
|
|
|
$product->parent->min_price = $product->parent->getTypeInstance()->getMinimalPrice();
|
|
|
|
|
|
|
|
|
|
$product->parent->max_price = $product->parent->getTypeInstance()->getMaximamPrice();
|
|
|
|
|
|
|
|
|
|
$product->parent->save();
|
|
|
|
|
} else {
|
|
|
|
|
$bundleProducts = $this->productFlatRepository->getModel()
|
2020-02-28 10:25:53 +00:00
|
|
|
->addSelect('product_flat.*')
|
|
|
|
|
->distinct()
|
|
|
|
|
->leftJoin('products', 'product_flat.product_id', 'products.id')
|
|
|
|
|
->leftJoin('product_bundle_options', 'products.id', 'product_bundle_options.product_id')
|
|
|
|
|
->leftJoin('product_bundle_option_products', 'product_bundle_options.id', 'product_bundle_option_productsproduct_bundle_option_id')
|
|
|
|
|
->where('product_bundle_option_products.product_id', $product->product_id)
|
|
|
|
|
->get();
|
2019-09-10 06:48:01 +00:00
|
|
|
|
|
|
|
|
foreach ($bundleProducts as $bundleProduct) {
|
|
|
|
|
$bundleProduct->min_price = $bundleProduct->getTypeInstance()->getMinimalPrice();
|
|
|
|
|
|
|
|
|
|
$bundleProduct->max_price = $bundleProduct->getTypeInstance()->getMaximamPrice();
|
|
|
|
|
|
|
|
|
|
$bundleProduct->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|