示例#1
0
 /**
  * @param \App\Model\Product $product
  * @param $category
  * @return array
  * @throws \Exception
  */
 public function getPrevAndNextProducts($product, $category)
 {
     $productModel = new \App\Model\Product($this->pixie);
     $productModel->prepareForCategory($category);
     $productModel->prepare_relations();
     $productModel->query->fields('tbl_products.productID');
     /** @var Result $result */
     $result = $productModel->query->execute();
     $ids = $result->as_array();
     $prevItem = null;
     $nextItem = null;
     foreach ($ids as $key => $row) {
         if ($row->productID == $product->id()) {
             if ($ids[$key - 1] && $ids[$key - 1]->productID) {
                 $prevItem = $this->pixie->orm->get('product', $ids[$key - 1]->productID);
             }
             if ($ids[$key + 1] && $ids[$key + 1]->productID) {
                 $nextItem = $this->pixie->orm->get('product', $ids[$key + 1]->productID);
             }
             break;
         }
     }
     return [$prevItem, $nextItem];
 }
 /**
  * @param Product $product
  * @param int $quantity
  */
 public function removeProduct($product, $quantity = 1)
 {
     if ($quantity == 0) {
         return;
     }
     /** @var CartItems $item */
     foreach ($_SESSION['cart_service']['items'] as $key => $item) {
         // If product already exists, just increase quantity
         if ($item->product_id == $product->id()) {
             if ($quantity >= 0 && $item->qty > $quantity) {
                 $item->qty -= $quantity;
             } else {
                 unset($_SESSION['cart_service']['items'][$key]);
             }
             return;
         }
     }
 }