Skip to main content
added 181 characters in body
Source Link
mickmackusa
  • 4.9k
  • 4
  • 20
  • 49
public function getNameAttribut($attr_id) { $db = JFactory::getDBO(); $lang = JSFactory::getLang(); try { $query = $db->getQuery(true) ->select($db->qn($lang->get("name")) . 'AS" name'AS name") ->from($db->qn('#__jshopping_attr'"#__jshopping_attr")) ->where('attr_id"attr_id = '" . (int)$attr_id); // assuming attr_id is an integer echo $query->dump(); // never show query to the public $db->setQuery($query); if (($result = $db->loadResult()) === null) { echo "Null Resultset - Possible Query Logic Error @ getNameAttribut()"; } return $result; } catch (Exception $e) { echo "Syntax Error", $e->getMessage(); // never show error messages to the public return false; } } 
public function getAllAttributes($result = 0, $categorys = null, $order = null, $orderDir = null) { if (!$order) { $order = 'A'a.attr_ordering'; } if ($orderDir != 'DESC') { $orderDir = 'ASC'; } $lang = JSFactory::getLang(); $db = JFactory::getDBO(); try { $query = $db->getQuery(true) ->select( array( 'A"a.attr_id'attr_id", 'A"a.'" . $db->qn($lang->get("name")) . '" AS name'name", 'A"a.attr_type'attr_type", 'A"a.attr_ordering'attr_ordering", 'A"a.independent'independent", 'A"a.allcats'allcats", 'A"a.cats'cats", 'G"G.'" . $db->qn($lang->get("name")) . '" AS groupname'groupname" ) ) ->from($db->qn('#__jshopping_attr'"#__jshopping_attr", 'A'"a")) ->leftJoin($db->qn('#__jshopping_attr_groups'"#__jshopping_attr_groups") . '" G ON '" . $db->qn('A"a.group'group") . '" = G.id'id") ->order($db->qn($order) . " " . $orderDir); //extract(js_add_trigger(get_defined_vars(), "before")); echo $query->dump(); // never show query to the public $db->setQuery($query); if ((!$result = $db->loadObjectList()) === null) { echo "Null Resultset - Possible Query Logic Error @ getAllAttributes()"; } return $result; } catch (Exception $e) { echo "Syntax Error", $e->getMessage(); // never show error messages to the public return false; } } 

I have not tested the above code blocks, so if anyone discovers a typo let me know and I'll fix it up.

p.s. It appears that your $lang value is not being rendered, since the column that is not found is called name_en-GB. I think the first thing to investigate is the $lang value.

public function getNameAttribut($attr_id) { $db = JFactory::getDBO(); $lang = JSFactory::getLang(); try { $query = $db->getQuery(true) ->select($db->qn($lang->get("name")) . 'AS name') ->from($db->qn('#__jshopping_attr')) ->where('attr_id = ' . (int)$attr_id); // assuming attr_id is an integer echo $query->dump(); // never show query to the public $db->setQuery($query); if (($result = $db->loadResult()) === null) { echo "Null Resultset - Possible Query Logic Error @ getNameAttribut()"; } return $result; } catch (Exception $e) { echo "Syntax Error", $e->getMessage(); // never show error messages to the public return false; } } 
public function getAllAttributes($result = 0, $categorys = null, $order = null, $orderDir = null) { if (!$order) { $order = 'A.attr_ordering'; } if ($orderDir != 'DESC') { $orderDir = 'ASC'; } $lang = JSFactory::getLang(); $db = JFactory::getDBO(); try { $query = $db->getQuery(true) ->select( array( 'A.attr_id', 'A.' . $db->qn($lang->get("name")) . ' AS name', 'A.attr_type', 'A.attr_ordering', 'A.independent', 'A.allcats', 'A.cats', 'G.' . $db->qn($lang->get("name")) . ' AS groupname' ) ) ->from($db->qn('#__jshopping_attr', 'A')) ->leftJoin($db->qn('#__jshopping_attr_groups') . ' G ON ' . $db->qn('A.group') . ' = G.id') ->order($db->qn($order) . " $orderDir); //extract(js_add_trigger(get_defined_vars(), "before")); echo $query->dump(); // never show query to the public $db->setQuery($query); if (($result = $db->loadObjectList()) === null) { echo "Null Resultset - Possible Query Logic Error @ getAllAttributes()"; } return $result; } catch (Exception $e) { echo "Syntax Error", $e->getMessage(); // never show error messages to the public return false; } } 

I have not tested the above code blocks, so if anyone discovers a typo let me know and I'll fix it up.

public function getNameAttribut($attr_id) { $db = JFactory::getDBO(); $lang = JSFactory::getLang(); try { $query = $db->getQuery(true) ->select($db->qn($lang->get("name")) . " AS name") ->from($db->qn("#__jshopping_attr")) ->where("attr_id = " . (int)$attr_id); // assuming attr_id is an integer echo $query->dump(); // never show query to the public $db->setQuery($query); if (($result = $db->loadResult()) === null) { echo "Null Resultset - Possible Query Logic Error @ getNameAttribut()"; } return $result; } catch (Exception $e) { echo "Syntax Error", $e->getMessage(); // never show error messages to the public return false; } } 
public function getAllAttributes($result = 0, $categorys = null, $order = null, $orderDir = null) { if (!$order) { $order = 'a.attr_ordering'; } if ($orderDir != 'DESC') { $orderDir = 'ASC'; } $lang = JSFactory::getLang(); $db = JFactory::getDBO(); try { $query = $db->getQuery(true) ->select( array( "a.attr_id", "a." . $db->qn($lang->get("name")) . " AS name", "a.attr_type", "a.attr_ordering", "a.independent", "a.allcats", "a.cats", "G." . $db->qn($lang->get("name")) . " AS groupname" ) ) ->from($db->qn("#__jshopping_attr", "a")) ->leftJoin($db->qn("#__jshopping_attr_groups") . " G ON " . $db->qn("a.group") . " = G.id") ->order($db->qn($order) . " " . $orderDir); //extract(js_add_trigger(get_defined_vars(), "before")); echo $query->dump(); // never show query to the public $db->setQuery($query); if (!$result = $db->loadObjectList()) { echo "Null Resultset - Possible Query Logic Error @ getAllAttributes()"; } return $result; } catch (Exception $e) { echo "Syntax Error", $e->getMessage(); // never show error messages to the public return false; } } 

I have not tested the above code blocks, so if anyone discovers a typo let me know and I'll fix it up.

p.s. It appears that your $lang value is not being rendered, since the column that is not found is called name_en-GB. I think the first thing to investigate is the $lang value.

Source Link
mickmackusa
  • 4.9k
  • 4
  • 20
  • 49

how do I efficiently debug this component?

Use try{}catch{} blocks and include $e->getMessage(), dump(), and resultset checks. Using Joomla query methods is also a good idea.

public function getNameAttribut($attr_id) { $db = JFactory::getDBO(); $lang = JSFactory::getLang(); try { $query = $db->getQuery(true) ->select($db->qn($lang->get("name")) . 'AS name') ->from($db->qn('#__jshopping_attr')) ->where('attr_id = ' . (int)$attr_id); // assuming attr_id is an integer echo $query->dump(); // never show query to the public $db->setQuery($query); if (($result = $db->loadResult()) === null) { echo "Null Resultset - Possible Query Logic Error @ getNameAttribut()"; } return $result; } catch (Exception $e) { echo "Syntax Error", $e->getMessage(); // never show error messages to the public return false; } } 

and

public function getAllAttributes($result = 0, $categorys = null, $order = null, $orderDir = null) { if (!$order) { $order = 'A.attr_ordering'; } if ($orderDir != 'DESC') { $orderDir = 'ASC'; } $lang = JSFactory::getLang(); $db = JFactory::getDBO(); try { $query = $db->getQuery(true) ->select( array( 'A.attr_id', 'A.' . $db->qn($lang->get("name")) . ' AS name', 'A.attr_type', 'A.attr_ordering', 'A.independent', 'A.allcats', 'A.cats', 'G.' . $db->qn($lang->get("name")) . ' AS groupname' ) ) ->from($db->qn('#__jshopping_attr', 'A')) ->leftJoin($db->qn('#__jshopping_attr_groups') . ' G ON ' . $db->qn('A.group') . ' = G.id') ->order($db->qn($order) . " $orderDir); //extract(js_add_trigger(get_defined_vars(), "before")); echo $query->dump(); // never show query to the public $db->setQuery($query); if (($result = $db->loadObjectList()) === null) { echo "Null Resultset - Possible Query Logic Error @ getAllAttributes()"; } return $result; } catch (Exception $e) { echo "Syntax Error", $e->getMessage(); // never show error messages to the public return false; } } 

I do not endorse the use of extract(). I have never had a good reason to use it in any of my projects. There is risk involved with its call, that it could overwrite global variables AND this generally floods the global variable pool. I don't know what it is meant to achieve in this code, but I would urge you to find another way.

I have not tested the above code blocks, so if anyone discovers a typo let me know and I'll fix it up.