LaravelShoppingcart icon indicating copy to clipboard operation
LaravelShoppingcart copied to clipboard

I HAVE A LITTLE SHOPPINGCART PROBLEM ON INVALID PRICE

Open shipment12 opened this issue 5 years ago • 2 comments

In my CartContoller i have this code

public function store(Request $request) {

        Cart::add($request->id, $request->name, 1, $request->price)
        
        ->associate(App\Product);
        return redirect()->route('cart.index')->with('success_message', 'Item Added to cart successfully');
        
    
   
}

and in my Model i have this code:

public function presentPrice(){

    return  $ .  number_format($this->price, 2);
    
}

but i am getting error message. Please supply a valid price.

someone help me out here

shipment12 avatar Mar 13 '19 05:03 shipment12

hello, please:

1- create the Helper in your App Directory and make this function

function presentPrice($price)
{
    $price2 = str_replace (',', '.', str_replace ('.', '', $price)) / 100;
    ;
    return number_format($price2, 2,',', '.');
}

2- reference for your composer.json on file

"autoload": {
        "files": [
            "app/helpers.php"
        ],

3 - composer dump-autoload

4 - In your views references your objects into functions presentPrice( ): {{ presentPrice($product->price) }}

5 - my language is pt_BR, adapte to language points.

deyvsonaguiar avatar Jan 23 '20 15:01 deyvsonaguiar

Check your price value in the controller, probably it is not passed correctly.

Mohammad-Yasin-Noori avatar Oct 27 '20 07:10 Mohammad-Yasin-Noori