Guest User

Untitled

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public function savePhotoGiftDetails($data = array()){
  2.  
  3. $status = false;
  4.  
  5. App::import('Model','PhotogiftDetail');
  6. $this->PhotobookDetail = new PhotobookDetail;
  7.  
  8. foreach( $data['PhotogiftDetail'] as $key => $detail ) {
  9. if( $detail['price'] == '' )
  10. unset($data['PhotogiftDetail'][$key]);
  11. }
  12.  
  13. unset($key, $detail);
  14.  
  15. $valid_product = $this->validates(array('Product'=> $data['Product']));
  16.  
  17. if($valid_product) {
  18.  
  19. $status = $this->save(array('Product' => $data['Product']));
  20. $saveDetail = false;
  21.  
  22. if($status && !empty($data['PhotogiftDetail'])) {
  23.  
  24. $details = array();
  25. $i = 0;
  26.  
  27. foreach($data['PhotogiftDetail'] as $detail):
  28.  
  29. $details[$i]['PhotogiftDetail']['product_id'] = $this->id;
  30. $details[$i]['PhotogiftDetail']['price'] = $detail['price'];
  31. $details[$i]['PhotogiftDetail']['description'] = $detail['description'];
  32.  
  33. $i++;
  34.  
  35. endforeach;
  36.  
  37. $status = $this->PhotogiftDetail->saveAll($details);
  38.  
  39. } else
  40. return $status;
  41. }
  42.  
  43. return $status;
  44.  
  45. }
Add Comment
Please, Sign In to add comment