Ejemplo n.º 1
0
 public function isAvailable()
 {
     // create cart object out of item properties
     $item = new JObject();
     $item->user_id = $this->user_id;
     $item->product_id = (int) $this->product_id;
     $item->product_qty = !empty($this->product_quantity) ? $this->product_quantity : '1';
     $item->product_attributes = $this->product_attributes;
     $item->vendor_id = $this->vendor_id;
     $item->cartitem_params = $this->wishlistitem_params;
     DSCTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
     $product = DSCTable::getInstance('Products', 'TiendaTable');
     $product->load(array('product_id' => $this->product_id));
     if (empty($product->product_enabled) || empty($product->product_id)) {
         $this->setError(JText::_('COM_TIENDA_INVALID_PRODUCT'));
         return false;
     }
     if ($product->product_notforsale) {
         $this->setError(JText::_('COM_TIENDA_PRODUCT_NOT_FOR_SALE'));
         return false;
     }
     Tienda::load('TiendaHelperProduct', 'helpers.product');
     $product_helper = new TiendaHelperProduct();
     $availableQuantity = $product_helper->getAvailableQuantity($item->product_id, $item->product_attributes);
     if ($availableQuantity->product_check_inventory && $item->product_qty > $availableQuantity->quantity) {
         $this->setError(JText::sprintf("COM_TIENDA_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $item->product_qty));
         return false;
     }
     $results = array();
     $dispatcher = JDispatcher::getInstance();
     $results = $dispatcher->trigger("onIsWishlistItemAvailable", array(&$item));
     for ($i = 0; $i < count($results); $i++) {
         $result = $results[$i];
         if (!empty($result->error)) {
             $this->setError($result->message);
             return false;
         }
     }
     return true;
 }