Commit 1c1c654502868891aa9c78a4dd61f0bb154798f4
1 parent
a2a186db
---
Showing
2 changed files
with
30 additions
and
10 deletions
Show diff stats
common/modules/product/models/Product.php
@@ -226,6 +226,13 @@ class Product extends \yii\db\ActiveRecord | @@ -226,6 +226,13 @@ class Product extends \yii\db\ActiveRecord | ||
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
229 | + public function beforeDelete() { | ||
230 | + ProductImage::deleteAll(['product_id' => $this->product_id]); | ||
231 | + ProductCategory::deleteAll(['product_id' => $this->product_id]); | ||
232 | + ProductVariant::deleteAll(['product_id' => $this->product_id]); | ||
233 | + return true; | ||
234 | + } | ||
235 | + | ||
229 | public function imagesUpload() | 236 | public function imagesUpload() |
230 | { | 237 | { |
231 | if ($this->validate()) { | 238 | if ($this->validate()) { |
console/controllers/ImportController.php
@@ -24,6 +24,19 @@ class ImportController extends Controller { | @@ -24,6 +24,19 @@ class ImportController extends Controller { | ||
24 | return Controller::EXIT_CODE_NORMAL; | 24 | return Controller::EXIT_CODE_NORMAL; |
25 | } | 25 | } |
26 | 26 | ||
27 | + public function goClear() { | ||
28 | + foreach(Product::find()->all() as $product) { | ||
29 | + if (empty($product->variant)) { | ||
30 | + if (!$product->delete()) { | ||
31 | + $this->stdout("#$product->product_id '$product->name'\n"); | ||
32 | + exit; | ||
33 | + } else { | ||
34 | + $this->stdout("#$product->product_id '$product->name'\n"); | ||
35 | + } | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | + | ||
27 | public function goGo() { | 40 | public function goGo() { |
28 | $new_products = $linked_products = 0; | 41 | $new_products = $linked_products = 0; |
29 | foreach(RemoteProducts::find()->all() as $product) { | 42 | foreach(RemoteProducts::find()->all() as $product) { |
@@ -31,7 +44,7 @@ class ImportController extends Controller { | @@ -31,7 +44,7 @@ class ImportController extends Controller { | ||
31 | if (empty($product->remoteCategory) || empty($product->remoteCategory->category)) { | 44 | if (empty($product->remoteCategory) || empty($product->remoteCategory->category)) { |
32 | continue; | 45 | continue; |
33 | } | 46 | } |
34 | - if (!empty($product->product->product_id)) | 47 | + if (!empty($product->product)) |
35 | { | 48 | { |
36 | $linked_products++; | 49 | $linked_products++; |
37 | 50 | ||
@@ -103,19 +116,19 @@ class ImportController extends Controller { | @@ -103,19 +116,19 @@ class ImportController extends Controller { | ||
103 | $_productVariant->remote_id = $product->ID; | 116 | $_productVariant->remote_id = $product->ID; |
104 | $_productVariant->stock = $_productVariant->price > 0 ? null : 0; | 117 | $_productVariant->stock = $_productVariant->price > 0 ? null : 0; |
105 | 118 | ||
106 | - if (!$_product->save()) { | ||
107 | - print $this->stdout("Saved error for the {$_product->name} {$_product->product_id}?\n"); | ||
108 | - return Controller::EXIT_CODE_ERROR; | ||
109 | - } | ||
110 | - $_productVariant->product_id = $_product->product_id; | ||
111 | - if (!$_productVariant->save()) { | ||
112 | - print $this->stdout("Saved error for variant of the {$_product->name} {$_product->product_id}?\n"); | ||
113 | - return Controller::EXIT_CODE_ERROR; | 119 | + if ($_product->save()) { |
120 | + $_productVariant->product_id = $_product->product_id; | ||
121 | + if (!$_productVariant->save()) { | ||
122 | + print $this->stdout("Saved error for variant of the {$_product->name} {$_product->product_id}?\n"); | ||
123 | +// return Controller::EXIT_CODE_ERROR; | ||
124 | + } | ||
125 | + | ||
114 | } | 126 | } |
115 | } | 127 | } |
128 | + $product->delete(); | ||
116 | } | 129 | } |
117 | 130 | ||
118 | - $this->goStat(); | 131 | +// $this->goStat(); |
119 | } | 132 | } |
120 | 133 | ||
121 | public function goStat() { | 134 | public function goStat() { |