From 1c1c654502868891aa9c78a4dd61f0bb154798f4 Mon Sep 17 00:00:00 2001 From: Karnovsky A Date: Tue, 24 May 2016 14:29:26 +0300 Subject: [PATCH] --- --- common/modules/product/models/Product.php | 7 +++++++ console/controllers/ImportController.php | 33 +++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index cf6d9d0..4daa4c0 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -226,6 +226,13 @@ class Product extends \yii\db\ActiveRecord } } + public function beforeDelete() { + ProductImage::deleteAll(['product_id' => $this->product_id]); + ProductCategory::deleteAll(['product_id' => $this->product_id]); + ProductVariant::deleteAll(['product_id' => $this->product_id]); + return true; + } + public function imagesUpload() { if ($this->validate()) { diff --git a/console/controllers/ImportController.php b/console/controllers/ImportController.php index 9de5e10..e1126ee 100644 --- a/console/controllers/ImportController.php +++ b/console/controllers/ImportController.php @@ -24,6 +24,19 @@ class ImportController extends Controller { return Controller::EXIT_CODE_NORMAL; } + public function goClear() { + foreach(Product::find()->all() as $product) { + if (empty($product->variant)) { + if (!$product->delete()) { + $this->stdout("#$product->product_id '$product->name'\n"); + exit; + } else { + $this->stdout("#$product->product_id '$product->name'\n"); + } + } + } + } + public function goGo() { $new_products = $linked_products = 0; foreach(RemoteProducts::find()->all() as $product) { @@ -31,7 +44,7 @@ class ImportController extends Controller { if (empty($product->remoteCategory) || empty($product->remoteCategory->category)) { continue; } - if (!empty($product->product->product_id)) + if (!empty($product->product)) { $linked_products++; @@ -103,19 +116,19 @@ class ImportController extends Controller { $_productVariant->remote_id = $product->ID; $_productVariant->stock = $_productVariant->price > 0 ? null : 0; - if (!$_product->save()) { - print $this->stdout("Saved error for the {$_product->name} {$_product->product_id}?\n"); - return Controller::EXIT_CODE_ERROR; - } - $_productVariant->product_id = $_product->product_id; - if (!$_productVariant->save()) { - print $this->stdout("Saved error for variant of the {$_product->name} {$_product->product_id}?\n"); - return Controller::EXIT_CODE_ERROR; + if ($_product->save()) { + $_productVariant->product_id = $_product->product_id; + if (!$_productVariant->save()) { + print $this->stdout("Saved error for variant of the {$_product->name} {$_product->product_id}?\n"); +// return Controller::EXIT_CODE_ERROR; + } + } } + $product->delete(); } - $this->goStat(); +// $this->goStat(); } public function goStat() { -- libgit2 0.21.4