How to apply condition for specific page in magento? - magento

I want to apply condition for specific page coming from url. It is neither a category page nor a custom cms page. Url is like localhost/project/index.php/news/blog.html. I want to apply condition for this 'news/blog.html' . News or blog is not a category and not any cms page. Can anybody help me?

It depends on the type of condition, you want to user over there. You can try with the following.
1. Try to put a observer in the relevant controller using the cheat sheet https://www.nicksays.co.uk/magento-events-cheat-sheet-1-5/
2. Directly try to edit model in the module of that page.
3. Try to put some code directly into the file.
Thanks,

Use the following code.
Mage::app()->getRequest()->getControllerName();
It will give controller name to your module. Put consition for this name and write your code. It will work for sure.

Related

where i can change the words of Newsletter in Magento2

i am very new of Magento2, I saw in the "page" that this form should be used to call out the newsletter form :
{{block class="Magento\Newsletter\Block\Subscribe"
name="static.newsletter"
template="Magento_Newsletter::subscribe.phtml"}}
But I would like to change the words of this form, or add more words there. I have already tried looking for in the system but didn't find it and I dont know where to change it. Does anyone can help ?
There are 2 approaches for changing words inside that form.
If you want to change this form for everywhere on your Magento system, you can override it inside your theme.
app/design/frontend/[Vendor]/[Theme]/Magento_Newsletter/templates/subscribe.phtml
If you want to change this form to a specific page, you can create your own template and assign it.

Calling Models in Magento Templates

I am currently working on integrating HTML cuts into Magento's template, however, I am just a little stumped on the structure of Magento itself. I want to list all of the categories inside a custom template in the 'navigation/left'.phtml file. The following accepted answer Magento: Display sub-category list seems to do what I need to do, however,I don't feel comfortable in calling a model inside of a view files as in MVC, which the accepted answer has done.
Is there a better way of putting this in another section of Magento, or perhaps a custom block which extends the Block_Catalog_Product_List class would be a better way of retrieving the categories?
Thanks
The simplest way to do it is to create a module with a helper inside it, that returns the data you need. Then in the template file call this:
$data = Mage::helper('myhelper')->getCategoryList();
//do your magic with $data
There is no point in overriding blocks unless there is no other solution.

magento catalogsearch search for all products (like a view all brands page )

For a project I need to make a kind of view all manufactures page, I am hoping to use catalogsearch but without any parameters. What I mean is the normal catalogsearch is ran and all shoes in all manufacture categories are returned.
The url that is normally passed is testshop.com//catalogsearch/result/index/?manufacturer=2522&q=shoe%20manufactures this works but when I try to pass testshop.com//catalogsearch/result/index/? (or along those lines) this does not work.
I have not started coding this yet as I am not sure where to begin so need a point in the right direction.
I am thinking of just finding the default category id and using this, but not sure if this is the best option to use.
Any advice or help will be great as always. Will post my finished code on here once complete as I think with magento help can be a bit limited.
Cheers
Jason
Maybe try getting the search Model pragmatically
Here is the code to get the Search model:
$search = Mage::getSingleton('catalogsearch/advanced');
To actually search put in the following:
$search = Mage::getSingleton('catalogsearch/advanced')->addFilters(array('name' => $term));
Then to get the results in an object, enter the following line:
$search->getProductCollection();
Hope this helps
I did it. It was a bit of a hack but works perfectly.
I noticed that if you make a search and remove all the filters you are left with a GET request that look something like this /catalogsearch/result/index/?q=Shoe+Brand . But the filters where not showing on the left hand side as a normal catalogsearch would.
So I found the default category id and added this to the GET request. The GET request now looked like this /catalogsearch/result/index/?cat=2&q=Shoe+Brand .
Although the GET request included q=Shoe+Brand it was not actually using this as search criteria.
This was now returning a catalogsearch page with the default category as a filter.
This was showing default category in the filter and breadcrumbs so I had to change the appropriate phtml files to check for this and display 'all brands' instead of 'default category'.
Hope this helps someone else
Jason

Issues with implementing a custom controller in magento

Basically I have to generate PDF of wishlist items(products) using the chunk of codes as specified in http://gorrc.blogspot.in/2012/05/magento-print-whishlist-to-pdf.html.
Now the problem is, I am not able to trace out where and how to call all the methods as specified in above link. Can anyone help me in this or provide any alternate solution, I mean some other ways for generating PDF of wishlist items. Any Help will be highly appreciated!
How you want to do it?
Say more about where you want do this action and i'll point the right direction.
This is controller, its end point of url request.
Method is called when you navigate to specified URL.

Magento: Rewriting URLs dynamically depending on conditions?

I have this problem:
I have a default route that looks like this: .../myapp/index.php/config/configuration/test/product_id/51
As you see, this leads to the ConfigurationController and in there to the testAction function. Thats fine and it should stay this way. What I want to change though is the "config part" of the URL.
So instead of
http://somedomain.de/myapp/index.php/config/configuration/test/product_id/51
I want
http://somedomain.de/myapp/index.php/furniture/configuration/test/product_id/51
to lead to the same location (ConfigurationController and in there to the testAction function). The part that is changed, is not static, its the attribute set name of the product. So instead of furniture it can be computer or something else. I can already get this from the product, So all I need is the rewrite stuff.
Ideas how to do that? THANKS!
In the module's config.xml you can change the frontend/routers/your_router/args/frontName which will allow you to use a different name (like furniture). If its an adminhtml controller, you have to use an adminhtml router but the rest is the same.
You can use a router, just like Magento does for CMS pages (explained in the second part of this article : http://alanstorm.com/magento_dispatch_admin_cms_default_routers)

Resources