示例#1
0
 private function deletePurchaselitemsByPurchase($orderid){
     $conditions = array('purchase_id=?', $orderid);
     $result = \Purchaseproduct::find('all', array('conditions' => $conditions));
     $stck = 0;
     foreach($result as $data){
         $stck = $data->quantity;
         $prdid = $data->product_id;
         $data->delete();
         if($this->enablestock){
             $prd = \Product::find($prdid);
             if($prd){
                 $newstock= $prd->stock - $stck;
                 $attributes = array(
                     "stock" => $newstock,
                     "stockvalue" => $newstock * $prd->unit_cp);
                 $prd->update_attributes($attributes);
             }
         }
     }
 }