예제 #1
0
 /**
  * Method to get an ojbect.
  *
  * @param   integer The id of the object to get.
  *
  * @return  mixed   Object on success, false on failure.
  */
 public function &getData($id = null)
 {
     if ($this->_item === null) {
         $this->_item = false;
         if (empty($id)) {
             $id = $this->getState('item.id');
         }
         // Get a level row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         if ($table->load($id)) {
             // Check published state.
             if ($published = $this->getState('filter.published')) {
                 if ($table->state != $published) {
                     return $this->_item;
                 }
             }
             // Convert the JTable to a clean JObject.
             $properties = $table->getProperties(1);
             $this->_item = JArrayHelper::toObject($properties, 'JObject');
             // Convert metadata field to JRegistry
             $registry = new JRegistry();
             $registry->loadString($this->_item->metadata);
             $this->_item->metadata = $registry;
             // Convert images field to array
             $registry = new JRegistry();
             $registry->loadString($this->_item->images);
             $this->_item->images = $registry->toArray();
             // Convert other_images field to array
             $registry = new JRegistry();
             $registry->loadString($this->_item->other_images);
             $this->_item->other_images = $registry->toArray();
             // Convert params field to registry
             $globalParams = JComponentHelper::getParams('com_dzproduct', true);
             $itemParams = new JRegistry();
             $itemParams->loadString($this->_item->params);
             $this->_item->params = $this->getState('params');
             // create an array of just the params set to 'use_item'
             $menuParamsArray = $this->getState('params')->toArray();
             $itemArray = array();
             foreach ($menuParamsArray as $key => $value) {
                 if ($value === 'use_item') {
                     // if the item has a value, use it
                     if ($itemParams->get($key) != '') {
                         // get the value from the item
                         $itemArray[$key] = $itemParams->get($key);
                     } else {
                         // otherwise, use the global value
                         $itemArray[$key] = $globalParams->get($key);
                     }
                 }
             }
             // merge the selected article params
             if (count($itemArray) > 0) {
                 $itemParams = new JRegistry();
                 $itemParams->loadArray($itemArray);
                 $this->_item->params->merge($itemParams);
             }
             // Load the field data for this item
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('f.name, f.dname, fd.value');
             $query->from('#__dzproduct_fields as f, #__dzproduct_field_data as fd, #__dzproduct_groupcat_relations as gr, #__dzproduct_groups as g');
             $query->where('f.id = fd.fieldid');
             $query->where('gr.groupid = g.id');
             $query->where('gr.catid = ' . (int) $this->_item->catid);
             $query->where('FIND_IN_SET(fd.fieldid, g.fields)');
             $query->where('fd.itemid = ' . (int) $this->_item->id);
             $db->setQuery($query);
             $this->_item->fielddata = $db->loadAssocList();
             foreach ($this->_item->fielddata as &$data) {
                 $data['dname'] = json_decode($data['dname'], true);
                 foreach ($data['dname'] as &$value) {
                     $value = urldecode($value);
                 }
             }
             // Load the category for this item
             $categories = JCategories::getInstance('dzproduct.items');
             $category = $categories->get($this->_item->catid);
             $category->link = DZProductHelperRoute::getCategoryRoute($category, $category->language);
             $this->_item->category = $category;
             // Prebuild order data
             $this->_item->data = json_encode(array('id' => $this->_item->id, 'title' => $this->_item->title, 'link' => JRoute::_(DZProductHelperRoute::getItemRoute($this->_item->id, $this->_item->catid)), 'image' => $this->_item->images['intro'], 'description' => $this->_item->short_desc, 'quantity' => 1, 'price' => $this->_item->saleoff ? $this->_item->saleoff : $this->_item->price));
         } elseif ($error = $table->getError()) {
             $this->setError($error);
         }
     }
     return $this->_item;
 }
예제 #2
0
 /**
  * Method to get category data for the current category
  *
  * @param   integer  An optional ID
  *
  * @return  object
  * @since   1.5
  */
 public function getCategory()
 {
     if (!is_object($this->_item)) {
         $categories = JCategories::getInstance('dzproduct.items');
         $this->_item = $categories->get($this->getState('filter.catid', 'root'));
         // Compute selected asset permissions.
         if (is_object($this->_item)) {
             // TODO: Why aren't we lazy loading the children and siblings?
             $this->_children = $this->_item->getChildren();
             $this->_parent = false;
             if ($this->_item->getParent()) {
                 $this->_parent = $this->_item->getParent();
             }
             $this->_rightsibling = $this->_item->getSibling();
             $this->_leftsibling = $this->_item->getSibling(false);
             // Compute links
             $this->_item->link = JRoute::_(DZProductHelperRoute::getCategoryRoute($this->_item, $this->_item->language));
             if (is_object($this->_parent)) {
                 $this->_parent->link = JRoute::_(DzproductHelperRoute::getCategoryRoute($this->_parent, $this->_parent->language));
             }
             if (count($this->_children)) {
                 foreach ($this->_children as &$child) {
                     $child->link = JRoute::_(DZProductHelperRoute::getCategoryRoute($child, $child->language));
                 }
             }
         } else {
             $this->_children = false;
             $this->_parent = false;
         }
         $registry = new JRegistry();
         $registry->loadString($this->_item->params);
         $this->_item->params = $registry->toArray();
     }
     return $this->_item;
 }