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 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); } }
public function createDummyContents($option_value, $design, $category) { $option = new Application_Model_Option(); $option->find($option_value->getOptionId()); $dummy_content_xml = $this->_getDummyXml($design, $category); if ($option->getCode() == "catalog") { foreach ($dummy_content_xml->catalog->children() as $categories) { $this->unsData(); //check si la category existe sur cette app $category_data = array("name" => $categories->name, "value_id" => $option_value->getId()); $category_id = $this->find($category_data)->getCategoryId(); if (!$category_id) { $this->setName((string) $categories->name)->setValueId($option_value->getId())->save(); $category_id = $this->getId(); } foreach ($categories->products->children() as $product) { $product_model = new Catalog_Model_Product(); if ($product->attributes()->subcategory) { $sub_category_model = new Catalog_Model_Category(); //check si la sous category existe sur cette app $subcategory_data = array("name" => $product->attributes()->subcategory, "value_id" => $option_value->getId()); $sub_category_model->find($subcategory_data); if (!$sub_category_model->getCategoryId()) { $sub_category_model->setName($product->attributes()->subcategory)->setValueId($option_value->getId())->setParentId($category_id)->save(); $product_model->setCategoryId($sub_category_model->getId()); } else { $sub_category_model->setParentId($category_id)->save(); $product_model->setCategoryId($sub_category_model->getId()); } } else { $product_model->setCategoryId($category_id); } foreach ($product->content->children() as $key => $value) { $product_model->addData((string) $key, (string) $value); } if ($product->formats) { $format_option = array(); foreach ($product->formats->children() as $format) { foreach ($format as $key => $val) { $format_option[$format->getName()][(string) $key] = (string) $val; } } $product_model->setOption($format_option); } $product_model->setValueId($option_value->getId())->save(); } } } }