I want to retrieve the name from product.template:
print self.env['product.template'].search([("id", "=", id), ]).name
How do I get translated name in ORM?
You can pass the language code in context to get specific product name in that language. Make sure that language has been loaded in your server before using it. I did some changes in your code to get the product name in German / Duetsch language.
print self.env['product.template'].with_context({'lang': 'de_DE'}).search([("id", "=", id)]).name
I hope this will help you. :)
Related
I want to test that warning messages are displayed correctly when form fields are returned as invalid. The best way to do this would be to access the array in validation.php to get the name of the language line that I want to use.
How can I do this?
The documentation for Laravel is very great. You can access language files in resources/lang/{locale}/ easily with the provided trans() function (Laravel 5):
$expected = 'The :attribute may only contain letters.';
$actual = trans('validation.alpha');
$this->assertEquals($expected,$actual);
Please provide your attempts in the question next time. Also have a look at the SO tour (you will be rewarded with a bronze badge afterwards!)
I have a content type called Author which is referred in another two content types called Novel and Book via Node Reference Module.So we can add author entity to both Book and Novel content types.
Both Novel and Book contain another field called Release Date.
Now I want to show a block which will display the name of book and name of novel in chronological order based upon the release date when user come to that corresponding Author Page.
Ex. Suppose A is an author who is author of BookA(Release Yr-2006), NovelB(Release Yr-2004),BookC(Release Year-2009). When user come to Author A page then he will be shown a block which will show the Books/Albums in chronological order like this:-
NovelB--BookA--BookC
Please suggest as how to achieve in Drupal 7.
You want to display the following field title (I assume the book name is the node title)
For the sorting you can use the sort option in views, it is pretty self-explaining. Choose the name of your release date field.
For the connection between author and books you will have to use a contextual filter (advanced).
Add the author-reference-field from your book/novel (the field you use to refer to the author). Then choose to use a default value (2nd option) and choose content id from url. Now your block will find all nodes that refer to the page with the current page-id. Since we chose to display the title fields, you should see a list.
Note that live preview does not work here, so you will have to go to the actual page to see the result.
UPDATE:
This works when you have re-used the same field for both content types. If you have uses more then one field you will have to use an OR operator to make the contextual filter work. Thanks to d34dman the following page was given to do just that.
Although for new implementations I would recommend using the same field (eg. reference_to_author) for all references from all content types.
Yah..I am able to solve this problem by adding custom code. I have used hook_views_query_alter method and then added join relationship and where clause as per requirement. Please refer to following article for more clarity..
http://www.midwesternmac.com/blogs/jeff-geerling/filtersearch-multiple-fields
Thanks for posting the reply and keeping my hope alive.
I have 9 websites in my magento installation, which again then have multiple languages etc. like below:
US - English
US - Spanish
US - French
UK - English
FR - French
I have created a php file with custom code which exports orders of websites. And those needs to be stored in separate folders based on country.
I want to run my export file url like http://example.com/xml/export.php?website=us
But to get the orders from a particular website, I need to set the Mage:app properly for that I have used below code:
Mage::app('base_uk', 'website');
But the above code is not working, and it is always fetching the orders from US store only, which is default for Mage:app().
How can I set my code to fetch orders form a specific website?
Please help, Thanks.
For Product collections there is such a thing as ->setStoreFilter($store_id). Since each $store_id is unique for any given website (i.e. if you know the $store_id, you know the $website_id), you might use this.
Sample code:
$orders = Mage::getModel('sales/order')
->getCollection()
->addAttributeToSelect("*")
->addStoreFilter($store_id)
My two cents: run that code for all $store_ids within the desired $website_id.
Note: I did not test this, just thinking with you. Could be that this function is not available for order collections. I still think you should then try to find a function that does filter orders by $store_id, since that is the Magento way to go!
Please can someone please show me real world example of when it would be advisable to override _setResourceModel to provide different name for collection.
I find it fascinating that magento have given the option of using a custom word for "_collection" but that there is absolutely no evidence of it ever being done.
You might want to have a different name for _collection if you are using multiple datastores
(for example: if you are using MySql and MongoDB).
Pesach
I have a category dedicated for exported goods , obviously , they will not be sold locally . so , how can I prevent customers who are from my country from ordering products that are meant only for exporting.. and showing an error message .. please help !
I would say that you will have to create a new product type. You'll need a new module (use Daniel's excellent kick-start extension: http://www.magentocommerce.com/magento-connect/Daniel+Nitz/extension/1108/modulecreator) and then have your model extend Mage_Catalog_Model_Product_Type_Simple.
Then, add a new attribute for your new product type to capture Allowed Countries, and implement the isSalable method in your Model to check for Allowed Countries.
This is not trivial, but it should be the right approach. The guys at Inchoo (who write a great blog) have a good tutorial on the process: link text and in fact they've provided the shell of the module.
Good luck!
JD