public function add() { $micantidad = Input::get('micantidad'); $itemCode = Input::get('itemCode'); $ID = Session::get('UserId'); $client = Session::get('Client'); //$ID = Sap::getId(); //$client = Sap::getClientSoap(); $CurrencyRate = $client->call('getCurrencyRate', array('tipo' => 'USD', 'SID' => $ID)); $currency = $CurrencyRate['getCurrencyRateResult']; /* funcion para sacar el detalle de un producto */ $ItemList = $client->call('GetDetalle', array('SID' => $ID, 'producto' => $itemCode)); $productos = (string) $ItemList['GetDetalleResult']; $datos = utf8_encode($productos); $BOM = new \SimpleXMLElement($datos); //datos a mostrar en la interfaz $itemName = (string) $BOM->BO->Items->row->ItemName; $itemCode = (string) $BOM->BO->Items->row->ItemCode; if ($BOM->BO->Items_Prices->row[0]->Currency == "MXP") { $numero = (double) $BOM->BO->Items_Prices->row[1]->Price; $numero = number_format($numero, 2, '.', ','); $precio = $numero; } else { $number = (double) $BOM->BO->Items_Prices->row[1]->Price; $number = number_format($number, 2, '.', ','); $numero = $number * $currency; $numero = number_format($numero, 2, '.', ','); $precio = $numero; } $stock = $BOM->BO->Items->row->QuantityOnStock * 1; $articulos = array('ItemCode' => $itemCode, 'ItemName' => $itemName, 'cantidad' => $micantidad, 'precio' => $precio, 'stock' => $stock, 'cliente' => (string) Auth::user()->email, 'user_id' => Auth::user()->id); $carr = DB::table('carrito')->where('itemCode', $itemCode)->where('user_id', Auth::user()->id)->first(); if ($carr) { $cant = $carr->cantidad; DB::table('carrito')->where('itemCode', $itemCode)->where('user_id', Auth::user()->id)->update(['cantidad' => (int) $cant + (int) Request::get('number'), 'stock' => $stock]); } else { Carrito::create($articulos); } $articulos = DB::table('carrito')->where('user_id', '=', Auth::user()->id)->get(); $value = count($articulos); session(['cant' => $value]); Session::put('add', "Tu Producto ha sido Agregado al Carrito"); return redirect()->back(); }