Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable prices for products? #19

Open
adrienne opened this issue Aug 11, 2022 · 3 comments
Open

Variable prices for products? #19

adrienne opened this issue Aug 11, 2022 · 3 comments
Assignees
Labels

Comments

@adrienne
Copy link

Our site allows donations of arbitrary amounts. Is there a way to make the price of a product variable?

@adrienne
Copy link
Author

@fulopattila122 - help please!

@adrienne
Copy link
Author

(We are using specific modules rather than the whole framework, if that makes a difference to how we have to set things up.) Can we do this with Properties? The documentation on those is a little confusing as to how to set them up with only the Cart module.

@fulopattila122 fulopattila122 self-assigned this Aug 21, 2022
@fulopattila122
Copy link
Member

No, properties won't help here. I'm afraid right now, you can only do this by changing the price of the product on the fly. This can be even temporary, without actually saving the price of the product to the DB.

A naive example:

class CartController
{
    public function addItem(Request $request)
    {
        $product = Product::findBySku('DONATION');
        $product->price = $request->get('amount_to_donate');

        Cart::addItem($product);

        return redirect()->to('/cart');
    }
}

Nevertheless, I must admit that there should be an easier way provided by the cart module out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants