/**
  * Updates product category count
  * @param $args
  * @throws ShopException
  */
 public function updateProductCategoryCount($args)
 {
     $shopInfo = new ShopInfo($args->module_srl);
     // Get number of products in category
     $args->status = "enabled";
     if ($shopInfo->getOutOfStockProducts() == 'N') {
         $args->in_stock = "Y";
     }
     $count_output = executeQuery('shop.getProductsInCategoryCount', $args);
     if (!$count_output->toBool()) {
         throw new ShopException($count_output->getMessage(), $count_output->getError());
     }
     // Update product count
     $update_args = new stdClass();
     $update_args->category_srl = $args->category_srl;
     $update_args->product_count = $count_output->data->product_count;
     $output = executeQuery('shop.updateCategory', $update_args);
     if (!$output->toBool()) {
         throw new ShopException($output->getMessage(), $output->getError());
     }
 }
Example #2
0
 /**
  * verify if product is available
  * @param bool $shopSettingsCheck
  * @return bool
  * @throws ShopException
  */
 public function isAvailable($shopSettingsCheck = true)
 {
     if (!$this->isPersisted()) {
         throw new ShopException('Product not persisted');
     }
     if ($shopSettingsCheck) {
         $shopInfo = new ShopInfo($this->module_srl);
         $shopSettingsCheck = $shopInfo->getOutOfStockProducts() == 'Y';
     }
     return $this->status != 'disabled' && (!$shopSettingsCheck || $shopSettingsCheck && $this->in_stock == 'Y');
 }
Example #3
0
 /**
  * Check if product is available
  *
  * TODO When accesing availability like this: $cart_product->available
  * the default value for $checkIfInStock=true is used; This in not always correct! To investigate
  *
  * @internal param bool $checkIfInStock
  * @return bool
  */
 public function isAvailable()
 {
     $shopInfo = new ShopInfo($this->product->module_srl);
     $checkIfInStock = $shopInfo->getOutOfStockProducts() == 'Y';
     if ($this->product->isPersisted()) {
         return $this->product->isAvailable($checkIfInStock);
     }
     return FALSE;
 }
Example #4
0
 /**
  * @param null $n number of products to return
  * @param false $onlyAvailables wether or not to return only available products
  *
  * @return mixed Cart products
  * @throws Exception
  */
 public function getProducts($n = null, $onlyAvailables = false, $ignoreCache = false)
 {
     if (!$this->cart_srl) {
         throw new ShopException('Cart is not persisted');
     }
     //an entity-unique cache key for the current method and parameters combination
     $cacheKey = 'getProducts|' . ($n ? $n : "_") . (string) ($onlyAvailables ? 'av' : 'all');
     if ($ignoreCache || !($products = self::$cache[$cacheKey])) {
         $products = array();
         $shopInfo = new ShopInfo($this->module_srl);
         $checkIfInStock = $shopInfo->getOutOfStockProducts() == 'Y';
         $params = array('cart_srl' => $this->cart_srl);
         if ($n) {
             $params['list_count'] = $n;
         }
         $output = $this->query('getCartAllProducts', $params, true);
         $stds = $output->data;
         foreach ($stds as $i => $data) {
             $cartProduct = new CartProduct($data);
             $simpleProduct = $cartProduct->getProduct();
             if ($simpleProduct->isPersisted()) {
                 if (!$simpleProduct->isAvailable($checkIfInStock) && $onlyAvailables) {
                     continue;
                 }
             } else {
                 if ($onlyAvailables || !$cartProduct->cart_product_srl) {
                     continue;
                 }
             }
             $products[$i] = $cartProduct;
         }
         self::$cache[$cacheKey] = $products;
     }
     //if limit did not work:
     if ($n && $n < count($products)) {
         return array_slice($products, 0, $n);
     }
     return $products;
 }