0

How can I fix this error in my code:

Parse error: syntax error, unexpected '​' (T_STRING), expecting ')' error

Code:

public function productDataToJson(Varien_Event_Observer $observer)
{
  $array = array();
  $category = Mage::registry('current_category');
  # $category = Mage::getModel('catalog/category')->load(41);
  $products = $category->getProductCollection()
      ->addAttributeToSelect('*'‌​);

  foreach ($products as $product) {
      $array[] = $product->getData();
  }

  $jsonData = Mage::helper('core')->jsonEncode($array);
  # save json file for each category
  file_put_contents('c_' . $category->getId() . '_node.json', $jsonData);
}
3
1

Code is OK ... but there seems to be a wrong encoded char.

Please type this manually again ->addAttributeToSelect('*');

Had similiar problem with your code yesterday ... so make sure all files are correctly encoded UTF8 w/o BOM

4
  • Thank you @sv3n, I solved this magento.stackexchange.com/questions/183027/… I solved here, If Anything wrong, please suggest. – onlyfordigitalworld Jul 12 '17 at 11:52
  • Not sure what you are doing ... :) Copy&Paste your code there phpcodechecker.com you'll get this error. Write this line manually (or at least ('*')) and it works. – sv3n Jul 12 '17 at 11:55
  • Hi @sv3n, I want all attribute lables instead of its id's in the json file, Please help ASAP. magento.stackexchange.com/questions/184505/… – onlyfordigitalworld Jul 20 '17 at 4:11
  • @SushantThorat I try to help if I can and when I've time for it. Some questions are fast to answer, others take some more investigation ... If I do not answer I've either no time or no good idea. I read you question ... and i'll maybe answer later. Please remember ... I'm not getting payed for it, so dont worry I or someone else doesnt answer in time. Regards. – sv3n Jul 20 '17 at 16:49
0

Try this :

public function productDataToJson(Varien_Event_Observer $observer)
{
  $array = array();
  $category = Mage::registry('current_category');
  # $category = Mage::getModel('catalog/category')->load(41);
  $products = $category->getProductCollection();
      //->addAttributeToSelect('*'‌​);

  foreach ($products as $product) {
      $array[] = $product->getData();
  }

  $jsonData = Mage::helper('core')->jsonEncode($array);
  # save json file for each category
  file_put_contents('c_' . $category->getId() . '_node.json', $jsonData);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.