Example #1
0
 /**
 * Update order with items
 *
 * Important: order metters. Each product-item must be directly before related services-items.
 * Example:
 *     // first product
      array(
 *         'product_id' => '1'
 *         'sku_id' => '1'
 *         ...
 *         'type'=>'product'
 *         ...
 *     )
 *     // services related to first product
 *     array(
 *         'product_id' => '1',
 *         'sku_id' => '1',
 *         ...
 *         'type'=>'service'
 *     ),
 *     array(
 *         'product_id' => '1',
 *         'sku_id' => '1',
 *         ...
 *         'type'=>'service'
 *     ),
 *     // second product
       array(
 *         'product_id' => '2'
 *         'sku_id' => '2'
 *         ...
 *         'type'=>'product'
 *         ...
 *     ),
 *     // services related to second product
 *     array(
 *         'product_id' => '2',
 *         'sku_id' => '2',
 *         ...
 *         'type'=>'service'
 *     ),
 *     array(
 *         'product_id' => '2',
 *         'sku_id' => '2',
 *         ...
 *         'type'=>'service'
 *     ),
 *
 * @param array $data
 * @param int $id If null than add new order
 * @return int $id
 */
 public function update($data, $id)
 {
     if (!$id && !empty($data['id'])) {
         $id = $data['id'];
     }
     if (isset($data['id'])) {
         unset($data['id']);
     }
     $items_model = new shopOrderItemsModel();
     if ($id) {
         $items_model->update($data['items'], $id);
         unset($data['items']);
         $diff = array_diff_assoc($data, $this->getById($id));
         if ($diff) {
             $this->updateById($id, $diff);
         }
     }
     return $id;
 }