Closed KodeStar closed 2 years ago
The base product model doesn't have properties. You have two opportunities:
app\Models\Product.php
that uses the HasPropertyValues
trait. Mind that you need to tell the system that now this is your product model via registering it with concord:app/Providers/AppServiceProvider.php
:
<?php
namespace App\Providers;
use Vanilo\Product\Contracts\Cart as ProductContract;
use App\Models\Product;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app->get('concord')->registerModel(ProductContract::class, Product::class);
}
}
Side note: to get a product by slug, you can use the Product::findBySlug('slug')
method, reference
I am using the entire framework, so using Vanilo\Foundation\Models\Product
was the part I was missing, thanks for the link to the Models section, I didn't realise I needed to use a different model than was specified in the products section (it might be worth having a note in the docs specifying if you are using the entire framework use Vanilo\Foundation\Models\Product
instead of Vanilo\Product\Models\Product
.
I ended up just dropping my options as json into the excerpt field as I realised delving into it a bit more that what I was actually after was more like a MasterProduct that isn't available yet.
So I just added:
{
"options": [
{
"name": "3 - 4 week delivery",
"key": "3%20-%204%20week%20delivery",
"additional": 0
},
{
"name": "2 week delivery",
"key": "2%20week%20delivery",
"additional": 30
},
{
"name": "3 day delivery",
"key": "3%20day%20delivery",
"additional": 60
}
],
"key_features": [
"Custom subdomain - <span class=\"text-gray-400\">https://<span class=\"text-purple-800\">name</span>.lovingmemory.link</span>",
"Downloadable QR code that links to the site",
"Site created and managed for you"
]
}
Then I pull it out in the controller and pass it to the view.
https://vanilo.io/docs/3.x/properties has examples of how to retrieve a property and it's values, but nothing about how to do it from a product.
As in
But then what? I tried
$product->propertyValues
but that didn't work