/**
 * @param $message
   // пример использования в контроллере:
   // $err = array('test1','test2'); // складываем ошибки в массив // можно доделать с использовать _addError как в контроллере orders/cart если запрос через ajax
   // Yii::app()->user->setFlash('messages_red', $err);
   // $this->addFlashMessage($model->getErrors(),'red'); // до кучи берем ошибки модели
   // Если была/были впереди ошибка/ошибки, показываем все
 */
 public function addFlashMessage($message, $style = 'success')
 {
     $currentMessages = Yii::app()->user->getFlash('error');
     if (!is_array($currentMessages)) {
         $currentMessages = array($currentMessages);
     }
     $map = new CMap($currentMessages);
     if (is_array($message)) {
         foreach ($message as $mes) {
             if (is_array($mes)) {
                 $map->mergeWith($mes);
             } else {
                 $map->mergeWith(array($mes));
             }
         }
     } else {
         $map->mergeWith(array($message));
     }
     $messages = $map->toArray();
     Yii::app()->user->setFlash($style, $messages);
 }
Exemple #2
0
 public function testToArray()
 {
     $map = new CMap(array('key' => 'value'));
     $this->assertEquals(array('key' => 'value'), $map->toArray());
 }
 public function actionGetGroceryRate()
 {
     $inquiry = new InquiryForm('api-rate-grocery');
     $req = Yii::app()->request;
     $inquiryMap = new CMap();
     $inquiryMap->add('receiver_postal', $req->getQuery('receiver_postal'));
     $inquiryMap->add('service_code', $req->getQuery('service_code'));
     $inquiry->setAttributes($inquiryMap->toArray());
     if (!$inquiry->validate()) {
         echo CJSON::encode($this->statusError($inquiry->getErrors()));
         Yii::app()->end();
     }
     $service_code = ProductService::model()->findByAttributes(array('code' => strtoupper($inquiry->service_code)));
     if (!$service_code instanceof ProductService) {
         echo CJSON::encode($this->statusError('No Service Available'));
         Yii::app()->end();
     } else {
         if ($service_code->code != 'LSX' && $service_code->code != 'HRX') {
             echo CJSON::encode($this->statusError('This service is not available'));
             Yii::app()->end();
         }
     }
     $routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
     if ($routing instanceof IntraCityRouting) {
         $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
         if (!$area) {
             echo CJSON::encode($this->statusError('No Available Service'));
             Yii::app()->end();
         }
         $rates = RateCity::getCityRate(ProductService::ProductCityCourier, $routing->code, 5);
         $rate = array();
         foreach ($rates as $key) {
             if ($key['service_code'] == $inquiry->service_code) {
                 $rate = $key;
             }
         }
         $product = 'City Courier';
         echo CJSON::encode($this->statusSuccess(array('service_type' => $product, 'rate' => $rate)));
         Yii::app()->end();
     } else {
         $result = array('status' => 'success', 'result' => $data);
     }
     echo CJSON::encode($result);
     Yii::app()->end();
 }
 /**
  * Save model attributes
  * @param ShopProduct $model
  * @return boolean
  */
 protected function processAttributes(ShopProduct $model)
 {
     $attributes = new CMap(Yii::app()->request->getPost('ShopAttribute', array()));
     if (empty($attributes)) {
         return false;
     }
     $deleteModel = ShopProduct::model()->findByPk($model->id);
     $deleteModel->deleteEavAttributes(array(), true);
     // Delete empty values
     foreach ($attributes as $key => $val) {
         if (is_string($val) && $val === '') {
             $attributes->remove($key);
         }
     }
     return $model->setEavAttributes($attributes->toArray(), true);
 }
Exemple #5
0
    /**
	 * Save model attributes
	 * @param Products $model
	 * @return boolean
	 */
	protected function processAttributes($attributes)
	{
		$attributes = new CMap($attributes);

		if(empty($attributes))
			return false;

		$this->deleteEavAttributes(array(), true);

		// Delete empty values
		foreach($attributes as $key=>$val)
		{
			if(is_string($val) && $val === '')
				$attributes->remove($key);
		}

		return $this->setEavAttributes($attributes->toArray(), true);
	}