public function loadProductInTransaction($newTrans, $userId, $role, $productId)
 {
     $product = Products::find($productId);
     if ($role == 1) {
         $cost = $product->member;
     } else {
         $cost = $product->non_member;
     }
     $pay_bonus = $product->pay_bonus;
     $detail = new SalesTransactionDetails();
     $detail->transaction_id = $newTrans->id;
     $detail->date = time();
     $detail->purchased_by = $userId;
     $detail->amount = $cost;
     $detail->product_id = $productId;
     $detail->pay_bonus = $pay_bonus;
     $detail->shipping = $product->shipping_handling;
     $detail->save();
     $this->updateTransaction($newTrans, $detail);
     return $newTrans;
 }
예제 #2
0
 public function updateSalesDetails($salesTransaction, $items, $roles)
 {
     foreach ($items as $item) {
         $salesDetails = new SalesTransactionDetails();
         $salesDetails->transaction_id = $salesTransaction->id;
         $salesDetails->date = $salesTransaction->date;
         $salesDetails->purchased_by = $salesTransaction->purchased_by;
         $price = $roles[1] == 'yes' ? $item->member : $item->non_member;
         $salesDetails->amount = $price;
         $salesDetails->product_id = $item->id;
         $salesDetails->pay_bonus = $item->pay_bonus;
         $salesDetails->shipping = $item->cost_shipping;
         $salesDetails->save();
     }
 }