Cannot use object of type Product as array prestashop 1.7 - smarty

i have problem, when i change the declination on my product page on prestashop 1.7.1.1
when i looked for the error it look this error image
any one can help me please, im using prestashop 1.7.1.1

I had the same error: "Cannot use object of type Product as array".
In Prestashop 1.7: "Objects are no longer passed to Smarty. We only use arrays now." (http://build.prestashop.com/news/module-development-changes-in-17/#general-information)
In my case, it was a module 'productcomments'. He overwrites the "product" index and changes "array" to "object".

It may be easy to solve.
The message says you are trying to use an object like an array
Imagine you want to fetch the id from the variable:
For arrays
$product['id']
But for objects
$product->id
So search in the template for the incorrect use of the product variable and fix it.

Related

Magento Dataflow (Advanced) Profile, default values

I want to create an import from a CSV but i can't modify the CSV file.
So i need to define default values for a couple required fields in Magento (like "type" ( > Simple Product ) etc.
I'm looking at https://stackoverflow.com/a/7319214/2252078 to make a custom Adapter and that inject the missing required values in the array before saving.
But i already get an error that says:
Method "parse" not defined in adapter spaanproductions_basics/convert_adapter_product
So i can't even begin with my custom code.
Maybe someone has a beter idea how to create some default values, or how to fix this issue.
Magento version: 1.9.1.1
Thanks in advance.
Kind regards,
Sonny
Not sure what the problem is, your code does seem to be valid. You could try http://pastebin.com/vxewc0Zt . OR temporarily rename your app/code/local/Spaanproductions/Basics/Model/Covert/Adapter/Product.php to verify wetter the right class is actually being loaded although I highly doubt that's the problem
-- Edit (See comments) --
try changing spaanproductions_basics/convert_adapter_product to basics/convert_adapter_product your models are defined under basics, not under spaanproductions"
At the first you have to export products as a csv file to catch the structure and then modify that as you need.
Take a look at this answer, it could be useful:
Update Magento products with multiple images

Add new attribute to existing hash

I am retrieving results using Mongoid, but I want to add a new attribute to each of the records returned in an instance variable using the key. How would I go about doing this?
In PHP I would do this by looping through the array and inserting it based on the key of the object. I am unable to figure out how this can be done in Ruby when I receive the message: Model ABC can't be converted into an Integer.
Update: I ended up adding a method in the model to achieve what I was trying to do.
I'll try to point you in the right direction.
If you have an array of records and what to loop through it, use Array#each: http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-each
You can write attributes easily: http://rdoc.info/github/mongoid/mongoid/Mongoid/Attributes#write_attribute-instance_method
Hope that helps

Magento product load - difference between loadByAttribute and load methods

today I'm fighting with Magento again :) and I found a difference between
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $product_sku);
and
$product = Mage::getModel('catalog/product')->load($product_id);
Can anyone exaplain me a difference between these two approaches? I found that when I'm loading a product by sku then when I 'try to re-save it with changed data then I get error exception 'Varien_Exception' with message 'Invalid method Varien_Object::save in app\code\core\Mage\CatalogInventory\Model\Observer.php(153): Varien_Object->__call('save', Array) that's true because once you try to load by sku then another observer sets product's stock item as Varien_Object, that looks like pitfall or I just dont understand it enough, but
I do daily Magento development from its beginnig so I know a lot about system and this is new for me. Thanks in advance, Jaro.
Interesting. While both methods will net you a single product model instance with fully loaded EAV data (provided the third parameter of loadByAttribute() is not passed or is *), the observers which add stock-related data are different for products vs. product collections, yet both stock information objects are added to the product data key "stock_item". It's debatable, but this feels like a bug. I would think that Mage_CatalogInventory_Model_Observer::saveInventoryData() or Mage_CatalogInventory_Model_Observer::_prepareItemForSave() would handle this.
You could resolve this issue by setting the product stock item fully on your product instance using the stock_item object.
loadByAttribute is a serious misnomer in my opinion because it doesn't actually trigger a load(); rather it uses getResourceCollection():
public function loadByAttribute($attribute, $value, $additionalAttributes = '*')
{
$collection = $this->getResourceCollection()
->addAttributeToSelect($additionalAttributes)
->addAttributeToFilter($attribute, $value)
->setPage(1,1);
Because it doesn't trigger the observer events associated with load() it means the resulting product object doesn't include the full set of product data you might want. In my case I needed the "description" attribute and it wasn't included.
There are several ways to resolve this:
Use a different method to load by SKU:
$product = Mage::getModel("catalog/product");
$product->load($product->getIdBySku("whatever"));
Force the desired attribute data to be included in the default product resource data by visiting Magento Admin > Catalog > Attributes > Edit attribute > "Used in Product Listing" = "Yes" and then reindexing. You should then be able to use the attribute data (in the frontend, at least) using loadByAttribute().
See also https://magento.stackexchange.com/a/197286/18855

Getting Popular Searches In Magento

I want to display the top 10 searches on my Magento store. Magento already stores searches made on the store under Admin > Catalog > Search Terms, so it's just a matter of getting it into my view. Does anyone know which helper or function I can access to get this list?
You have a setPopularQueryFilter method in the class Mage_CatalogSearch_Model_Mysql4_Query_Collection, after that you only have to set a limit I guess :)
Without trying, it should be something like that :
$searchCollectino=Mage::getModel('catalogsearch/query')->getCollection()
->setPopularQueryFilter()
->setPageSize($limit);
If anyone needs the Magento 2 solution:
inject the class \Magento\Search\Model\Query in your constructor and then retrieve the collection like so:
$collection = $this->query->getSuggestCollection()
This will return a collection of most popular search terms sorted by the popularity.

get magento module config data in Observer

I created a module with an observer for the sales module with event hook ‘sales_order_shipment_save_after’ ,
My module has the following files
Company/Modulename/etc/config.xml
Company/Modulename/etc/system.xml
Company/Modulename/Model/Observer.php
there are four fields in the modules admin configuration fields
I want to get those saved data in the Observer class.
using $this->getConfigData(’password’); gives a
Call to undefined method
error
Any suggestions?
Magento uses a static method on the global Mage application object to get configuration values
$config = Mage::getStoreConfig('section_name/group/field'); //value
$config = Mage::getStoreConfig('section_name/group'); //array
An amendment to Alan's completely correct answer.
Along with path as first parameter, getStoreConfig also accepts storeid as second parameter(optional).
Well, this is useful when you want to retrieve store-wise values.
Alan has mentioned this point in his own tutorial. I guess, he has not mentioned here just because OP has not mentioned this requirement in his question.
Please refer this
In a shipment module I can use $this->getConfigData for fields in system.xml, but in another kind of modules sometimes not, e.g. extends Mage_Core_Model_Abstract, than I must use getStoreConfig. So the answer is you don't have to use always getStoreConfig. But I don't know why ...
Answer: getConfigData is just defined in a shipment class and uses getStoreConfig too. A little confusing that some functions are extra defined and unneeded in fact ...

Resources