Ejemplo n.º 1
0
 private function createShoppingCart()
 {
     $shoppingCart = new ShoppingCart();
     $shoppingCart->addItem(new Product(123, 'item 1', 100, 1, 2, 15, 30));
     $shoppingCart->addItem(new Product(456, 'item 2', 100, 1, 2, 15, 30));
     $shoppingCart->addItem(new Product(789, 'item 3', 100, 1, 2, 15, 30));
     $this->weight = 3;
     $this->height = 6;
     $this->width = 15;
     $this->length = 30;
     return $shoppingCart;
 }
Ejemplo n.º 2
0
 private function calcPackageDimensions(ShoppingCart $shoppingCart)
 {
     foreach ($shoppingCart as $productId => $item) {
         $quantity = $shoppingCart->getItemQuantity($productId);
         $this->weight += $quantity * $item->getProductWeight();
         $this->height += $quantity * $item->getProductHeight();
         $currentWidth = $item->getProductWidth();
         $currentLength = $item->getProductLength();
         if ($currentWidth > $this->width) {
             $this->width = $currentWidth;
         }
         if ($currentLength > $this->length) {
             $this->length = $currentLength;
         }
     }
 }