Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Apr 19, 2020
1 parent 02ddaa9 commit e734481
Showing 1 changed file with 11 additions and 35 deletions.
46 changes: 11 additions & 35 deletions src/ImportCsvShopContentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
*/
class ImportCsvShopContentHandler extends ImportCsvContentHandler
{
/**
* @var null Поставщик
*/
public $shop_supplier_id = null;

/**
* @var null Склад
Expand Down Expand Up @@ -85,7 +81,7 @@ public function getAvailableFields()
public function rules()
{
return ArrayHelper::merge(parent::rules(), [
[['shop_supplier_id', 'shop_store_id'], 'integer'],
[['shop_store_id'], 'integer'],
['is_save_source_data', 'boolean'],
['is_quantity_clean', 'boolean'],
]);
Expand All @@ -95,7 +91,6 @@ public function rules()
public function attributeLabels()
{
return ArrayHelper::merge(parent::attributeLabels(), [
'shop_supplier_id' => 'Поставщик',
'shop_store_id' => 'Поставка/Склад',
'is_save_source_data' => 'Сохранять исходные данные по товару?',
'is_quantity_clean' => 'Обнулить количество у товаров которых нет в файле?',
Expand All @@ -105,7 +100,6 @@ public function attributeLabels()
public function attributeHints()
{
return ArrayHelper::merge(parent::attributeHints(), [
'shop_supplier_id' => 'Если выран поставщик, то все товары будут привязаны к этому поставщику',
'shop_store_id' => 'Наличие будет указано на этом складе',
'is_save_source_data' => 'Если выбрано да, то все исходные данные по товару будут сохранены в специальное поле.',
]);
Expand All @@ -119,20 +113,10 @@ public function renderConfigForm(ActiveForm $form)
{
$this->renderCsvConfigForm($form);

echo $form->field($this, 'shop_supplier_id')->listBox(
ArrayHelper::merge(['' => ' - '], ArrayHelper::map(
ShopSupplier::find()->all(), 'id', 'asText'
)
),
[
'size' => 1,
'data-form-reload' => 'true',
]);

if ($this->shop_supplier_id) {
if (\Yii::$app->skeeks->site->shopStores) {
echo $form->field($this, 'shop_store_id')->listBox(
ArrayHelper::merge(['' => ' - '], ArrayHelper::map(
ShopStore::find()->where(['shop_supplier_id' => $this->shop_supplier_id])->all(), 'id', 'asText'
\Yii::$app->skeeks->site->shopStores, 'id', 'asText'
)),
[
'size' => 1,
Expand Down Expand Up @@ -304,9 +288,9 @@ protected function _initElement($number, $row, $contentId = null, $className = n
$elementQuery = ShopCmsContentElement::find()->joinWith('shopProduct as shopProduct')
->andWhere(['shopProduct.supplier_external_id' => $uniqueValue]);

if ($this->shop_supplier_id) {
/*if ($this->shop_supplier_id) {
$elementQuery->andWhere(['shopProduct.shop_supplier_id' => $this->shop_supplier_id]);
}
}*/

$element = $elementQuery->one();

Expand Down Expand Up @@ -424,9 +408,9 @@ public function import($number, $row)

if ($shopProductIsUpdate) {

if ($this->shop_supplier_id) {
/*if ($this->shop_supplier_id) {
$element->shopProduct->shop_supplier_id = $this->shop_supplier_id;
}
}*/

if (!$element->shopProduct->save()) {
throw new Exception('Свойство магазина не сохранено: '.Json::encode($element->shopProduct->errors));
Expand All @@ -435,7 +419,7 @@ public function import($number, $row)
}


//$this->_initImages($element, $row);
$this->_initImages($element, $row);

$result->data = $this->matching;
$result->message = ($isUpdate === true ? "Элемент обновлен" : 'Элемент создан');
Expand Down Expand Up @@ -499,22 +483,14 @@ public function getShopStore()
public function beforeExecute()
{
//Если задан склад и нужно удалять наличие которых нет в файле
if ($this->shop_supplier_id && $this->shop_store_id && $this->is_quantity_clean) {

/*$query = $this->shopStore
->getShopStoreProducts()
->select(['shop_product_id'])
;
if ($updated = ShopStoreProduct::updateAll(['quantity' => 0], ['in', 'shop_product_id', $query])) {
$this->getResult()->stdout("Обнулено: ".$updated);
}*/
/*if ($this->shop_supplier_id && $this->shop_store_id && $this->is_quantity_clean) {
if ($updated = ShopStoreProduct::updateAll(['quantity' => 0], ['shop_store_id' => $this->shop_store_id])) {
$this->getResult()->stdout("Обнулено: ".$updated);
}
}
}*/

return true;
}
Expand Down

0 comments on commit e734481

Please sign in to comment.