vanilophp / framework

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

Propose to add capability for Service-based product #68

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

Duplicate of vanilophp/cart#16