function admin_edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(sprintf(__('Invalid %s', true), 'shop promotion')); $this->redirect(array('action' => 'index')); } $this->ShopPromotion->recursive = -1; $promotion = $this->ShopPromotion->read(null, $id); $aros = $this->ShopPromotion->productAros(); if (!empty($aros)) { $promotion[$this->ShopPromotion->alias]['aroProduct'] = set::extract('{n}.Aro.id', $aros); } if (!empty($this->data)) { if ($this->ShopPromotion->save($this->data)) { if (!empty($this->data['ShopPromotion']['aroProduct'])) { //debug($this->ShopProduct->Aro->Permission->alias); //// unset old $aros //// foreach ($aros as $aro) { if (!empty($aro[$this->ShopProduct->Aro->alias]['alias'])) { $aro = $aro[$this->ShopProduct->Aro->alias]['alias']; } else { $aro = $aro[$this->ShopProduct->Aro->alias]; } $this->Acl->inherit($aro, $this->ShopPromotion); } //// set new $aros //// $aros = $this->ShopProduct->Aro->find('all', array('conditions' => array('id' => $this->data['ShopPromotion']['aroProduct']))); foreach ($aros as $aro) { if (!empty($aro[$this->ShopProduct->Aro->alias]['alias'])) { $aro = $aro[$this->ShopProduct->Aro->alias]['alias']; } else { $aro = $aro[$this->ShopProduct->Aro->alias]; } $this->Acl->allow($aro, $this->ShopPromotion); } } $this->Session->setFlash(sprintf(__('The %s has been saved', true), 'shop promotion')); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(sprintf(__('The %s could not be saved. Please, try again.', true), 'shop promotion')); } } if (empty($this->data)) { $this->data = $promotion; //debug($this->data); } $this->ShopPromotion->ShopCoupon->recursive = -1; $coupons['all'] = $this->ShopPromotion->ShopCoupon->find('count', array('conditions' => array('shop_promotion_id' => $promotion['ShopPromotion']['id']))); $coupons['used'] = $coupons['all'] - $this->ShopPromotion->ShopCoupon->find('count', array('conditions' => array('shop_promotion_id' => $promotion['ShopPromotion']['id'], 'or' => array('ShopCoupon.status not' => 'used', 'ShopCoupon.status' => null)))); $coupons['reserved'] = $coupons['all'] - $this->ShopPromotion->ShopCoupon->find('count', array('conditions' => array('shop_promotion_id' => $promotion['ShopPromotion']['id'], 'or' => array('ShopCoupon.status not' => array('used', 'reserved'), 'ShopCoupon.status' => null)))); $this->set('coupons', $coupons); $products = $this->ShopProduct->generateAroList(); $this->set('products', $products); $this->set($this->_promoMethodList()); $actions = $this->ShopPromotion->ShopAction->find('list', array('conditions' => array('status' => 'checkPromo'))); $this->set('actions', $actions); $this->set('promotion', $promotion); }