vanilophp / framework

The truly Laravel E-commerce Framework
https://vanilo.io
MIT License
810 stars 102 forks source link

Product Attributes? #7

Closed futdev closed 6 years ago

futdev commented 6 years ago

Is it possible within the OrderFactory to assign custom variables/attributes to the order? for example at the moment I've got the following:

$factory = app(OrderFactory::class);
$item = [
    'product' => 'product',
    'product_id'   => 3,
    'price' => $this->getPrice(Request::get('platform'), Request::get('amount')),
    'name' => 'Virtual Currency',
    'quantity'     => 1,
];
$factory->createFromDataArray([], [$item]);

Would it be possible to maybe add the ability for us to add dynamic elements to the $item such as something like so?

$factory = app(OrderFactory::class);
$item = [
    'product' => 'product',
    'product_id'   => 3,
    'price' => $this->getPrice(Request::get('platform'), Request::get('amount')),
    'name' => 'Virtual Currency',
    'quantity' => 1,
    'currency_volume' => '5000'
];
$factory->createFromDataArray([], [$item]);
fulopattila122 commented 6 years ago

Yes it's possible. Do you want currency_volume to be added only to the order_item or only to the product - or both?

futdev commented 6 years ago

order_item would be fine as I'm no longer using the product table since my products are dynamic in price based on order information, doing only order_item would be sufficient enough right?

fulopattila122 commented 6 years ago

It should work with your code, after you have created a migration that adds the currency_volume field to the order_items table. Please let me know if I was correct/wrong :)

futdev commented 6 years ago

Worked perfect! thanks!

futdev commented 6 years ago

Oh wait, appears that it doesn't insert into the column? maybe it's not a specified column within the model?

Potentially down to this? https://github.com/vanilophp/order/blob/master/src/Models/OrderItem.php#L21

fulopattila122 commented 6 years ago

Exactly. Will fix it shortly and get back to you.

futdev commented 6 years ago

@fulopattila122 Thanks very much! do you have Skype?

fulopattila122 commented 6 years ago

Run composer update vanilo/order. It should update the order component to v0.2.1, which has the desired behavior. Sorry, I don't really use Skype.

Note: wait ~ 3-5 minutes for packagist to pick up the new release.

futdev commented 6 years ago

I've only got "vanilo/framework": "^0.2" inside my composer.json? when running composer update vanilo/order I get Nothing to install or update, any ideas?

futdev commented 6 years ago

Fixed! ran composer update vanilo/framework --with-dependencies

Thanks for such quick response & action on this!

fulopattila122 commented 6 years ago

No problem! Feel free to open another issue whenever you get into trouble :) Usually I respond in the evenings/mornings (Europe/Berlin).

futdev commented 6 years ago

@fulopattila122 Just a quick one, did you know that both these models aren't in the packagist?

use Vanilo\Product\Model\Product;
use Vanilo\Order\Model\Order;

I'd much rather use the Models instead of the Factory as it looks much cleaner, any better instructions mate?

fulopattila122 commented 6 years ago

What do you mean they're not in packagist?

futdev commented 6 years ago

When trying to use both of them like so:

<?php

    namespace App\Http\Controllers;
    use Vanilo\Product\Model\Product;
    use Vanilo\Order\Model\Order;

    class myController {

        public function test() {
            $order = Order::create(['number' => 'PO123456']);
        }

    }

I get the following:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Class 'Vanilo\Order\Model\Order' not found
futdev commented 6 years ago

^ ignore, was a type in the use Vanilo\Order\Model\Order; should have been use Vanilo\Order\Models\Order;

P.S; just for reference I'd advise updating this within your README.md also mate

fulopattila122 commented 6 years ago

Sure, you can absolutely use the models directly. Factory is actually to simplify the creation for you.

johnnykiyaka commented 5 years ago

hallo guys.is it possible to change currency from usd to ksh??need help

fulopattila122 commented 5 years ago

hallo guys.is it possible to change currency from usd to ksh??need help

@johnnykiyaka please open a new issue next time for a new topic. Answer: https://vanilo.io/docs/0.5/configuration#configuring-the-framework