mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-21 14:55:02 +00:00
Fixed weight integration, added testcase, fixed weird readme code example
This commit is contained in:
10
src/Cart.php
10
src/Cart.php
@@ -105,11 +105,12 @@ class Cart
|
||||
* @param mixed $name
|
||||
* @param int|float $qty
|
||||
* @param float $price
|
||||
* @param float $weight
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Gloudemans\Shoppingcart\CartItem
|
||||
*/
|
||||
public function add($id, $name = null, $qty = null, $price = null, array $options = [])
|
||||
public function add($id, $name = null, $qty = null, $price = null, $weight = null, array $options = [])
|
||||
{
|
||||
if ($this->isMulti($id)) {
|
||||
return array_map(function ($item) {
|
||||
@@ -117,7 +118,7 @@ class Cart
|
||||
}, $id);
|
||||
}
|
||||
|
||||
$cartItem = $this->createCartItem($id, $name, $qty, $price, $options);
|
||||
$cartItem = $this->createCartItem($id, $name, $qty, $price, $weight, $options);
|
||||
|
||||
return $this->addCartItem($cartItem);
|
||||
}
|
||||
@@ -696,11 +697,12 @@ class Cart
|
||||
* @param mixed $name
|
||||
* @param int|float $qty
|
||||
* @param float $price
|
||||
* @param float $weight
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Gloudemans\Shoppingcart\CartItem
|
||||
*/
|
||||
private function createCartItem($id, $name, $qty, $price, array $options)
|
||||
private function createCartItem($id, $name, $qty, $price, $weight, array $options)
|
||||
{
|
||||
if ($id instanceof Buyable) {
|
||||
$cartItem = CartItem::fromBuyable($id, $qty ?: []);
|
||||
@@ -710,7 +712,7 @@ class Cart
|
||||
$cartItem = CartItem::fromArray($id);
|
||||
$cartItem->setQuantity($id['qty']);
|
||||
} else {
|
||||
$cartItem = CartItem::fromAttributes($id, $name, $price, null, $options);
|
||||
$cartItem = CartItem::fromAttributes($id, $name, $price, $weight, $options);
|
||||
$cartItem->setQuantity($qty);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user