Esempio n. 1
0
 public function savePaymentDetails($type, $order, $status, $statusDetail, $response = array())
 {
     // start - update number of stock for successful payment
     if ($status == 'Completed') {
         foreach ($order->products as $product) {
             if ($product->attributes_id) {
                 $get_attributes = \Product\Model_Attribute::find_one_by(array('product_id' => $product->product_id, 'attributes' => $product->attributes_id));
                 $get_attributes->set(array('stock_quantity' => $get_attributes->stock_quantity - $product->quantity));
                 $get_attributes->save();
             } else {
                 $get_attributes = \Product\Model_Attribute::find_one_by_product_id($product->product_id);
                 $get_attributes->set(array('stock_quantity' => $get_attributes->stock_quantity - $product->quantity));
                 $get_attributes->save();
             }
         }
     }
     // end - update number of stock for successful payment
     $exists = \Payment\Model_Payment::find_one_by_order_id($order->id);
     if ($exists) {
         $this->payment = $exists;
     }
     $this->payment->set(array('order_id' => $order->id, 'total_price' => $order->total_price + $order->shipping_price - $order->discount_amount, 'method' => $type, 'status' => $status, 'status_detail' => $statusDetail, 'response' => json_encode($response)));
     $this->savePayment();
 }