markguinn/silverstripe-shop-search

Call to a member function Nice() on a non-object

Closed this issue · 4 comments

I am getting this error Fatal error: Call to a member function Nice() on a non-object in G:\Nimbler\ovesco\shop_search\code\ShopSearch.php on line 341

https://github.com/markguinn/silverstripe-shop-search/blob/master/code/ShopSearch.php#L341

As $prod->getPrice() is being returned as a string instead of the casted currency.

Can we do this to fix it up so it returns as the currency object?

'price' => $prod->obj('Price')->Nice()

I cant see how it may break things unless you know how other have implemented this module?

That looks right. If you submit a PR I'll merge it.

NM. I just made the change. Product does have a getPrice method, but ProductVariation doesn't. Are you searching variations?

Thanks!!

No I am not using variations but it would cause an error for people who do. I had an old variation page type in my database when I was seeing if I wanted to use them so also know that variations cause an error on $prod->Link() as well.

I am not sure if you want to fix this now or leave a note or doc saying it is not 100% working with it or just let people figure it out on their own.

Yeah, it's really not intended to search anything that doesn't have a link. I tend to add a "SearchCopy" field to products that includes text from variations or child products, etc and is only visible to Solr (or mysql fulltext). That makes variations searchable without the issue of linking to them. Thanks for pointing this out.