amsgames / laravel-shop

Laravel shop package
MIT License
479 stars 167 forks source link

problem with item name and item url #6

Closed ITwrx closed 8 years ago

ITwrx commented 8 years ago

first of all, let me say, this project looks like it is the exact feature set i was hoping for, especially the good common sense, model conversion feature. so thanks a lot!

I'm using laravel 5.1 i converted an existing model to use with laravel-shop. i can add it to the cart and view the cart but

<a href="{{ $item->shopUrl }}">{{ $item->displayName }}</a> 

only outputs

<a href="#"></a>

however, i notice that everything that comes directly from the items table is output sucessfully. the top of the converted model in question is:

 namespace App\Models;

use Amsgames\LaravelShop\Traits\ShopItemTrait;
use Illuminate\Database\Eloquent\Model;

class Paso extends Model {

    use ShopItemTrait;

    /**
     * Name of the route to generate the item url.
     *
     * @var string
     */
    protected $itemRouteName = 'paso_finos';

    /**
     * Name of the attributes to be included in the route params.
     *
     * @var string
     */
    protected $itemRouteParams = ['slug'];

the name attribute in my model's table is "name" and i also tried

protected $itemName = 'product_name';

in my model to no avail.

I can also add the cart to an order but it looks like paypal chokes on the lack of item name, so i'm hoping this fixes that too.

Any ideas?

Thanks in advance

amostajo commented 8 years ago

Sorry for this late answer.

Sounds like your cart/order items are not being related to your "Paso" class.

Please, check these 2 things:

ITwrx commented 8 years ago

That's exactly what the problem was. I completely forgot that i had had problems adding the whole object and was only adding the sku and price as a temp hack. Now the item url and name are being echo'd. Thanks a lot! i'm still getting

ErrorException in GatewayPayPalExpress.php line 142: Undefined property: stdClass::$name

but i'll get back on that with new issue if i can't find anything on my end over the next day or so. Thanks.

amostajo commented 8 years ago

Have you configured your PayPal settings?

https://github.com/amsgames/laravel-shop-gateway-paypal#configuration

ITwrx commented 8 years ago

yes, and i see this $name error must be preceeded by a paypal connection error. my paypal sandbox creds are good but i'm developing and testing from localhost so i'm guessing that's the underlying problem. Thanks

amostajo commented 8 years ago

I've done testing from localhost and it works fine. Make sure you have setup sandbox properly and that you developer account is correctly configured in PayPal's developer panel.

ITwrx commented 8 years ago

I misunderstood what was required with paypal settings. I had my sandbox biz creds instead of paypal developer app creds in laravel-shop-gateway-paypal config! Also, I didn't know i needed to create api app in paypal developer at all. now laravel-shop works great!

If you wanted to "dummy-proof+" the laravel-shop-gateway-paypal docs you could prepend the current authentication section with something like "first create an api app in your paypal developer account ..."

one question though, if you don't mind. paypal returns to my app's return url with "?order=12" appended to the url. how do i parse this as $orderId/{orderId} in my routes.php so i can show results of just this order? Or maybe there is a way to have it come back appended with "/12" (assuming 12 is order id)?

Thanks again. you've really taken the pain out of creating a custom shop w paypal.

amostajo commented 8 years ago

Thanks for the suggestion. Will add that "dummy-proof" message.

In regards to the callback. You can change the route name of the order page the shop will open in return, this is explained in the gateway's page; change this on config/shop.php.

You can easily setup your order's page with a wildcard to accomplish what you are looking for:

Route::get('order/{order}', ['as' => 'orderpage', 'uses' => 'OrderController@show']);

Then in your controller have something like:

public function show($order)
{
  $order = Order::find($order);

  // Do what ever you want here
  return view('order', ['order' => $order]);
}

Off topic: There is a new gateway that allows you to connect the shop to more payment services, like Stripe, 2checkout, Authorize.net.. etc: https://github.com/amostajo/laravel-shop-gateway-omnipay

ITwrx commented 8 years ago

everything works! i just needed to clear route cache and try again. thanks for your help.

RE: omnipay. Wow. that's cool. didn't know about that. thanks.