public $stickers_ids = [];
public function rules()
{
return [
['stickers_ids', 'each', 'rule' => [
'exist', 'targetClass' => ShopStickers::class, 'targetAttribute' => 'id'
]
],
];
}
public function saveStickers()
{
ShopProductsStickers::deleteAll(['product_id' => $this->id]);
if (is_array($this->stickers_ids)) {
foreach($this->stickers_ids as $stickers_id) {
$pc = new ShopProductsStickers();
$pc->product_id = $this->id;
$pc->sticker_id = $stickers_id;
$pc->save();
}
}
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
$confirm = ArrayHelper::merge(['' => 'Все'], Orders::getConfirmStatuses());
$orderStatuses = ShopOrdersStatuses::find()->all();
$statusList = [];
foreach ($orderStatuses as $orderStatus) {
$statusList[$orderStatus->group->name][$orderStatus->id] = $orderStatus->name;
}
$statusList = ArrayHelper::merge(['' => 'Все'], ArrayHelper::map($orderStatuses, 'id', 'name'));
$payments = ShopPaymentTypes::find()->all();
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
'orderStatuses' => $statusList,
'statuses' => $confirm,
'payments' => $payments,
]);
}
foreach ($orderStatuses as $orderStatus) {
print_r($statusList[$orderStatus->group->name]);
$statusList[$orderStatus->group->name][$orderStatus->id] = $orderStatus->name ;
}
foreach ($orderStatuses as $orderStatus) {
print_r($orderStatus->group->name); //или print_r($orderStatus->id); или $orderStatus->name
$statusList[$orderStatus->group->name][$orderStatus->id] = $orderStatus->name ;
}