public function getSubCategories($parentId, $language = 'nl') { $db = Zend_Registry::get('db'); $select = $db->select()->from(array('c' => 'Category'), array('*'))->join(array('t' => 'CategoryTsl'), 'c.category_id = t.category_id')->where('t.language LIKE "' . $language . '"')->where('c.parent_id = ' . $parentId . ' AND c.category_id != 0'); $stmt = $db->query($select); $result = $stmt->fetchAll(); $categories = array(); foreach ($result as $category) { $categoryObj = new SxCms_Product_Category(); $categoryObj->setId($category['category_id'])->setLanguage($category['language'])->setTitle($category['title'])->setDescription($category['description']); $categories[$category['category_id']] = $categoryObj; } return $categories; }
public function getAllProducts($categoryId = null, $language = 'nl') { $db = Zend_Registry::get('db'); $select = $db->select()->from(array('p' => 'Product'), array('*'))->joinLeft(array('t' => 'ProductTsl'), 'p.product_id = t.product_id')->where('t.language LIKE "' . $language . '"'); if ($categoryId !== null) { $select->where('p.category_id = ?', $categoryId); } $stmt = $db->query($select); $result = $stmt->fetchAll(); $products = array(); foreach ($result as $product) { $category = new SxCms_Product_Category(); $category->setId($product['category_id'])->setLanguage($_SESSION['System']['lng']); $category->loadState(); $productObj = new SxCms_Product(); $productObj->setId($product['product_id'])->setLanguage($product['language'])->setTitle($product['title'])->setDescription($product['description'])->setSummary($product['summary'])->setPrice($product['price'])->setCategory($category); $products[$product['product_id']] = $productObj; } return $products; }
/** * Loads product state from datastorage * * @return SxCms_Product */ public function loadState() { $db = Zend_Registry::get('db'); $select = $db->select()->from(array('p' => 'Product'), array('p.*'))->join(array('t' => 'ProductTsl'), 'p.product_id = t.product_id', array('t.*'))->where('p.product_id = ?', $this->id)->where('t.language = ?', $this->getLanguage()); $result = $db->fetchAll($select); foreach ($result as $product) { $this->setId($product['product_id'])->setTitle($product['title'])->setDescription($product['description'])->setSummary($product['summary'])->setPrice($product['price']); $category = new SxCms_Product_Category(); $category->setId($product['category_id'])->setLanguage($this->getLanguage()); $category->loadState(); $this->setCategory($category); } return $this; }