Fixed weight integration, added testcase, fixed weird readme code example

This commit is contained in:
Patrick Henninger
2019-04-16 12:10:06 +02:00
parent 4d302fb4a2
commit 279e820760
3 changed files with 22 additions and 7 deletions

View File

@@ -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);
}