public function sortcategoriesAction() { if ($rows = $this->getRequest()->getParam('category') or $rows = $this->getRequest()->getParam('row')) { $html = array(); try { if (!$this->getCurrentOptionValue()) { throw new Exception($this->_('An error occurred while saving')); } $category = new Catalog_Model_Category(); $categories = $category->findByValueId($this->getCurrentOptionValue()->getId()); $category_ids = array(); foreach ($categories as $category) { $category_ids[] = $category->getId(); } foreach ($rows as $row) { if (!in_array($row, $category_ids)) { throw new Exception($this->_("An error occurred while saving. One of your categories could not be identified.")); } } $category->updatePosition($rows); $html = array('success' => 1); } catch (Exception $e) { $html = array('message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function viewAction() { $option = $this->getCurrentOptionValue(); $this->loadPartials($this->getFullActionName('_') . '_l' . $this->_layout_id, false); $category = new Catalog_Model_Category(); $categories = $category->findByValueId($option->getId(), null, true, true); $this->getLayout()->getPartial('content')->setCategories($categories); $html = array('html' => $this->getLayout()->render(), 'title' => $this->getCurrentOptionValue()->getTabbarName()); if ($url = $option->getBackgroundImageUrl()) { $html['background_image_url'] = $url; } $html['use_homepage_background_image'] = (int) $option->getUseHomepageBackgroundImage() && !$option->getHasBackgroundImage(); $this->getLayout()->setHtml(Zend_Json::encode($html)); }
public function findallAction() { if ($value_id = $this->getRequest()->getParam("value_id")) { try { $category = new Catalog_Model_Category(); $categories = $category->findByValueId($value_id, null, true, true); $data = array("categories" => array()); foreach ($categories as $category) { $products = array(); foreach ($category->getProducts() as $product) { $products[] = $this->_productToJson($product, $value_id); } usort($products, array($this, "_sortProducts")); $category_data = array("id" => $category->getId(), "name" => $category->getName()); $children = $category->getChildren(); if ($children->count()) { foreach ($category->getChildren() as $child) { $child_products = array(); foreach ($child->getProducts() as $product) { $child_products[] = $products[] = $this->_productToJson($product, $value_id); } usort($child_products, array($this, "_sortProducts")); $category_data["children"][] = array("id" => $child->getId(), "name" => $child->getName(), "collection" => $child_products); } array_unshift($category_data["children"], array("id" => $child->getId(), "name" => $this->_("%s - All", $category->getName()), "collection" => $products)); } else { $category_data["collection"] = $products; } $data["categories"][] = $category_data; } $data["page_title"] = $this->getCurrentOptionValue()->getTabbarName(); $data["header_right_button"]["picto_url"] = $this->_getColorizedImage($this->_getImage('pictos/more.png', true), $this->getApplication()->getBlock('subheader')->getColor()); } catch (Exception $e) { $data = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($data); } }