/** * 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; }
public function getItems() { $items = parent::getItems(); foreach ($items as &$item) { $item->link = JRoute::_(DZProductHelperRoute::getItemRoute($item->id, $item->catid)); $registry = new JRegistry(); $registry->loadString($item->images); $item->images = $registry->toArray(); $registry = new JRegistry(); $registry->loadString($item->other_images); $item->other_images = $registry->toArray(); $registry = new JRegistry(); $registry->loadString($item->params); $item->params = $registry->toArray(); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select("f.id, f.dname, f.type, d.value")->from("#__dzproduct_fields as f")->join("INNER", "#__dzproduct_groups as g ON FIND_IN_SET(f.id, g.fields)")->join("INNER", "#__dzproduct_groupcat_relations as r ON g.id = r.groupid AND r.catid = " . $item->catid)->join("LEFT", "#__dzproduct_field_data as d ON f.id = d.fieldid AND d.itemid = " . $item->id); $db->setQuery($query); $item->fields = $db->loadAssocList(); foreach ($item->fields as &$field) { $registry = new JRegistry($field['dname']); $field['dname'] = $registry->toArray(); } // Build data attribute for cart button $item->data = json_encode(array('id' => $item->id, 'title' => $item->title, 'link' => $item->link, 'image' => $item->images['intro'], 'description' => $item->short_desc, 'quantity' => 1, 'price' => $item->saleoff ? $item->saleoff : $item->price)); } return $items; }