vanilophp / cart

Cart Module for Vanilo (or any Laravel app)
https://vanilo.io
MIT License
50 stars 17 forks source link

Propose to add functionality for ordering Service-based Products #16

Closed beaconsbay closed 4 years ago

beaconsbay commented 4 years ago

Why add this ?

The current addItem() combines quantity for same product, that works perfectly well for normal physical products. However, when it comes to service-based products with customisations, it is often different for each item.

e.g. A sticker printing company sells 10x10cm label sticker as a product but every order and item is considered unique because the print design is different. It wouldn't make sense to add millions of product since there's practically no limit to people's designs.

This would add the functionality of Cart::addServiceItem() where it allows the cart to store individual entries. So the customer can order 10x10cm label with multiple designs.

This applies to service oriented (built-to-order) industries / businesses:

The codes

Vanilo\Cart\CartManager.php

/**
 * @inheritDoc
 */
public function addServiceItem(Buyable $product, $qty = 1, $params = []): CartItem
{
    $cart = $this->findOrCreateCart();

    return $cart->addServiceItem($product, $qty, $params);
}

Vanilo\Cart\Models\Cart.php

/**
 * @inheritDoc
 */
public function addServiceItem(Buyable $product, $qty = 1, $params = []): \Vanilo\Cart\Contracts\CartItem
{
    $item = $this->items()->create(
        array_merge(
            $this->getDefaultCartItemAttributes($product, $qty),
            $this->getExtraProductMergeAttributes($product),
            $params['attributes'] ?? []
        )
    );

    $this->load('items');

    return $item;
}
fulopattila122 commented 4 years ago

Please take a look at issue #12, I think that will solve your problem.

Let me know if it worked :bow:

fulopattila122 commented 4 years ago

Did the solution described at #12 work for your case?