Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Jul 15, 2024
1 parent f028c75 commit 1c70ec7
Showing 1 changed file with 93 additions and 1 deletion.
94 changes: 93 additions & 1 deletion src/controllers/AdminCmsContentElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,47 @@ public function actions()
},
],


"joins" => [
'class' => BackendModelAction::class,
'name' => "Объединение",
'icon' => 'fa fa-list',
'priority' => 190,

'accessCallback' => function (BackendModelAction $action) {

/**
* @var $model ShopCmsContentElement
*/
$model = $action->model;

if (!$model) {
return false;
}

if (!$model->shopProduct) {
return false;
}

if ($model->shopProduct->offers_pid) {
return false;
}

if ($model->main_cce_id) {
return false;
}


/**
* @var $site \skeeks\cms\shop\models\CmsSite
*/
$site = $model->cmsSite;

return \Yii::$app->user->can($this->permissionName."/update", ['model' => $model]);

},
],

"relations" => [
'class' => BackendModelAction::class,
'name' => "Так же покупают",
Expand Down Expand Up @@ -268,6 +309,7 @@ public function actions()
},
],


"connect-to-main" => [

'class' => BackendModelUpdateAction::class,
Expand Down Expand Up @@ -1824,7 +1866,7 @@ public function initGridData($action, $content)
'items' => [
'dimentions' => 'Габариты',
'weight' => 'Вес',
'brand' => 'Бренд',
'brand' => 'Бренд',
]
//

Expand Down Expand Up @@ -2928,6 +2970,56 @@ public function actionRelationsDettach()
return $rr;
}

/**
* @return RequestResponse
* @throws \Throwable
* @throws \yii\db\StaleObjectException
*/
public function actionJoinsDettach()
{
$rr = new RequestResponse();
if ($rr->isRequestAjaxPost()) {
$product_id = (int)\Yii::$app->request->post('product_id');

if ($product_id) {
$sp = ShopProduct::findOne($product_id);
$spModel = $sp->shopProductModel;
if (!$spModel) {
return $rr;
}

$t = \Yii::$app->db->beginTransaction();

try {

$sp->shop_product_model_id = null;
if (!$sp->save(false, ['shop_product_model_id'])) {
throw new \yii\base\Exception(print_r($sp->errors, true));
}

if ($spModel->getShopProducts()->count() <= 1) {
$spModel->delete();
}



$t->commit();

$rr->success = true;

} catch (\Exception $exception) {
$t->rollBack();
throw $exception;
}


}

}

return $rr;
}

/**
*
*/
Expand Down

0 comments on commit 1c70ec7

Please sign in to comment.