JohnDoeTester / yii-shop

Automatically exported from code.google.com/p/yii-shop
0 stars 0 forks source link

Updating a product raises an error #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When clicking on [Save] in theh products form (?r=shop/products/update&id=1), 
the following error is shown:

Invalid argument supplied for foreach()

C:\xampp\htdocs\test\yii-webshop\protected\modules\shop\models\Products.php(60)

48         return $specs === null ? array() : $specs;
49     }
50 
51     public function setSpecification($spec, $value) {
52         $specs = json_decode($this->specifications, true);
53 
54         $specs[$spec] = $value;
55 
56         return $this->specifications = json_encode($specs);
57     }
58 
59     public function setSpecifications($specs) {
60         foreach($specs as $k => $v)
61             $this->setSpecification($k, $v);
62     }
63 
64     public function setVariations($variations) {
65         $db = Yii::app()->db;
66         $db->createCommand()->delete('shop_product_variation',
67                 'product_id = :product_id', array(
68                     ':product_id' => $this->product_id));
69 
70         foreach($variations as $key => $value) {
71             if(isset($value['title']) && $value['title'] != '')
72                 $db->createCommand()->insert('shop_product_variation', array(

Stack Trace
#0  
+
–
 C:\xampp\htdocs\test\yii-webshop\protected\modules\shop\controllers\ProductsController.php(43): Products->setSpecifications(null)

38         $this->performAjaxValidation($model);
39 
40         if(isset($_POST['Products']))
41         {
42             $model->attributes=$_POST['Products'];
43             $model->setSpecifications($_POST['Specifications']);
44             $model->setVariations($_POST['Variations']);
45 
46             if($model->save())
47                 $this->redirect(array('products/admin'));
48         }

#1  
+
–
 C:\Frameworks\yii\web\actions\CInlineAction.php(74): ProductsController->actionUpdate()

69                     throw new CHttpException(400, $this->errorMessage);
70             }
71             $method->invokeArgs($controller,$params);
72         }
73         else
74             $controller->$methodName();
75     }
76 }

#2  
+
–
 C:\Frameworks\yii\web\CController.php(300): CInlineAction->run()

295     {
296         $priorAction=$this->_action;
297         $this->_action=$action;
298         if($this->beforeAction($action))
299         {
300             $action->run();
301             $this->afterAction($action);
302         }
303         $this->_action=$priorAction;
304     }
305 

#3  
+
–
 C:\Frameworks\yii\web\CController.php(278): CController->runAction(CInlineAction)

273      * @see runAction
274      */
275     public function runActionWithFilters($action,$filters)
276     {
277         if(empty($filters))
278             $this->runAction($action);
279         else
280         {
281             $priorAction=$this->_action;
282             $this->_action=$action;
283             CFilterChain::create($this,$action,$filters)->run();

#4  
+
–
 C:\Frameworks\yii\web\CController.php(257): CController->runActionWithFilters(CInlineAction, array())

252         {
253             if(($parent=$this->getModule())===null)
254                 $parent=Yii::app();
255             if($parent->beforeControllerAction($this,$action))
256             {
257                 $this->runActionWithFilters($action,$this->filters());
258                 $parent->afterControllerAction($this,$action);
259             }
260         }
261         else
262             $this->missingAction($actionID);

#5  
+
–
 C:\Frameworks\yii\web\CWebApplication.php(328): CController->run("update")

323         {
324             list($controller,$actionID)=$ca;
325             $oldController=$this->_controller;
326             $this->_controller=$controller;
327             $controller->init();
328             $controller->run($actionID);
329             $this->_controller=$oldController;
330         }
331         else
332             throw new CHttpException(404,Yii::t('yii','Unable to resolve 
the request "{route}".',
333                 
array('{route}'=>$route===''?$this->defaultController:$route)));

#6  
+
–
 C:\Frameworks\yii\web\CWebApplication.php(121): CWebApplication->runController("shop/products/update")

116             foreach(array_splice($this->catchAllRequest,1) as $name=>$value)
117                 $_GET[$name]=$value;
118         }
119         else
120             $route=$this->getUrlManager()->parseUrl($this->getRequest());
121         $this->runController($route);
122     }
123 
124     /**
125      * Registers the core application components.
126      * This method overrides the parent implementation by registering 
additional core components.

#7  
+
–
 C:\Frameworks\yii\base\CApplication.php(155): CWebApplication->processRequest()

150      */
151     public function run()
152     {
153         if($this->hasEventHandler('onBeginRequest'))
154             $this->onBeginRequest(new CEvent($this));
155         $this->processRequest();
156         if($this->hasEventHandler('onEndRequest'))
157             $this->onEndRequest(new CEvent($this));
158     }
159 
160     /**

#8  
+
–
 C:\xampp\htdocs\test\yii-webshop\index.php(13): CApplication->run()

08 defined('YII_DEBUG') or define('YII_DEBUG',true);
09 // specify how many levels of call stack should be shown in each log message
10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
11 
12 require_once($yii);
13 Yii::createWebApplication($config)->run();

Original issue reported on code.google.com by juppwer...@gmail.com on 28 Feb 2011 at 2:12

GoogleCodeExporter commented 9 years ago
also a known bug, will fix that. thx again for reporting :)

Original comment by thyseus on 28 Feb 2011 at 5:06

GoogleCodeExporter commented 9 years ago

Original comment by thyseus on 28 Feb 2011 at 8:44