How to get current CMS page name - magento

I am doing via observer to get CMS name which I create.
config.xml
<events>
<adminhtml_cms_page_edit_tab_content_prepare_form>
<observers>
<my_module_edit_tab_content>
<type>singleton</type>
<class>My_Module_Model_Observer</class>
<method>changeContent</method>
</my_module_edit_tab_content>
</observers>
</adminhtml_cms_page_edit_tab_content_prepare_form>
</events>
observer.php
public function changeContent($observer) {
}

You can get CMS page Title like this
<?php
echo Mage::getSingleton('cms/page')->getTitle();
?>

How to get current CMS page name
need to use event
<cms_page_prepare_save>
<observers>
<sky_slack_page_edit_tab_content>
<type>singleton</type>
<class>NameSpace_ModuleName_Model_Observer</class>
<method>addCMS</method>
</sky_slack_page_edit_tab_content>
</observers>
</cms_page_prepare_save>
and in observer
<?php
public function addCMS($observer) {
$cmsName = $observer->getEvent()->getPage()->getTitle();
}
?>

To get the URL key / identifier of any CMS page in Magento, use the following bit of code.
<?php
$cmsPageUrlKey = Mage::getSingleton('cms/page')->getIdentifier();
?>
This will return the path that comes after the website’s URL. For example, the URL identifier for the About Us page might be about-us and not the full URL like http://www.yourwebsite.com/about-us/. If you want the full URL including your website address, then you should use the following piece of code.
<?php
$cmsPageUrl = Mage::getUrl() . Mage::getSingleton('cms/page')->getIdentifier();
?>

I think you're looking for the CMS page Title. If you're on the CMS page, use:
<?php
$current_title = Mage::getSingleton(‘cms/page’)->getTitle();
?>
If you have the identifier, use:
<?php
Mage::getModel(’cms/page’)->getResource()->getCmsPageTitleByIdentifier(’YOUR_IDE‌​NTIFIER’);
?>
(from https://magento.stackexchange.com/questions/102302/get-cms-page-description)

Related

Magento, save orders in other Database

i'd like to save orders in an other database after sending the customer E-Mail (before the observer.php). Where is the right file to get all orders? Maybe /app/code/core/Mage/Core/Model/Email/Template.php?!
Thank you for your help & sorry for my bad english.
you need to write an observer for this you have to create an extension.
define the following in the extension's config.xml
<events>
<sales_order_place_after>
<observers>
<store_sales_order_observer>
<type>singleton</type>
<class>companyname_package_model_observer</class>
<method>save_new_order</method>
</store_sales_order_observer>
</observers>
</sales_order_place_after>
</events>
In the observer's model class file please write down the method
<?php
class companyname_Package_Model_Observer
public function save_new_order(Varien_Event_Observer $observer){
// all code for storeing goes here
}
}
?>
Let me know if you have any query

how to make magento filter works like category

I would like to have the categories in magento made use of the attributes/filter.
Let say I have an attribute "CupAttr" which is a NOT used in layered navigation. Then I create a category called CupCat, and it uses the "CupAttr" to pull products to display them within the CupCat category.
is that possible? The reason why i want to do this is I want to minimize the maintenance of categorizing products.
Thanks
EDITED:
Amit's solution works perfectly, but that bring in another issue. the products showing in the list is different from the products can be filtered from the layered navigation.
I actually need to select all products for any category (because i won't add any products to any category, they are all blank), then i start filter the products for that specific category by attribute.
thanks again.
In this case,you can use magento event/observer.
Hook an observer on event catalog_block_product_list_collection.
Then using addAttributeToFilter('CupAttrAttibiteCode'); filter the collection by CupAttr.
config.xml code:
<?xml version="1.0"?>
<config>
<global>
<models>
<xyzcatalog>
<class>Xyz_Catalog_Model</class>
</xyzcatalog>
</models>
<events>
<catalog_block_product_list_collection> <!-- event -->
<observers>
<xyz_catalog_block_product_list_collection>
<type>singleton</type>
<class>Xyz_Catalog_Model_Observer</class>
<method>apply_CupAttr_filter</method>
</xyz_catalog_block_product_list_collection>
</observers>
</catalog_block_product_list_collection>
</events>
</global>
</config>
Observer code location:
Create the directory structure - app/code/local/Xyz/Catalog/Model/Observer.php
First "CupAttr" which is used in prouct listing for use this attribute to filtering
<?php
class Xyz_Catalog_Model__Observer
{
public function __construct()
{
}
public function apply_CupAttr_filter($observer){
//apply filter when category is CupCat
if(Mage::registry('current_category') &&(Mage::registry('current_category')->getId()=='CupCatCatrgoryId') ):
$collection=$observer->getEvent()->getCollection();
$collection->addAttributeToFilter('CupAttrAttibiteCode','FilterExpression');
endif;
return $this;
}
}

redirect customer on custom page from Indexcontroller

I want to redirect customer even if he is not logged in, on my custom page where customer need to add quote and details of product. He will redirect on this page when he click on ‘Add to Compare’ link from product view page and after submitting form he will stay over there as it is with successful message.
Please note that,this thing I have to done from preDispatch function of Index Controller.
Thank you.
You need to add code in config.xml
<frontend>
<events>
<controller_action_predispatch>
<observers>
<controller_action_before>
<class>dispatcher/observer</class>
<method>controllerActionPreDispatch</method>
</controller_action_before>
</observers>
</controller_action_predispatch>
</events>
</frontend>
Add code in model/observer.php file
public function controllerActionPreDispatch($observer)
{
//we compare action name to see if that's action for which we want to add our own event
if($observer->getEvent()->getControllerAction()->getFullActionName() == 'yourmodule Action Name')
{
Mage::app()->getResponse()->setRedirect(Mage::getUrl("customer/account"));
}
}

Add Top Links on condition basis in magento

I am little bit stuck with adding top links in my custom phtml.I removed the links block in my xml <remove name="top.links"/> , now after some condtion become true i want to add this block again.When i use this code for top menu it works but not for links
$block = Mage::getSingleton('core/layout');
echo $block->createBlock('catalog/navigation')->setTemplate('catalog/navigation/top.phtml')->toHtml();
This works and disply top menu.But the below code doesn't show anything.
$block = Mage::getSingleton('core/layout');
echo $block->createBlock('page/template_links')->setTemplate('page/template/links.phtml')->toHtml();
Any help ???
After using observer i solve my problem for time being.I think this is alternate way.In my config i define oberser like :
<frontend>
<events>
<controller_action_layout_generate_xml_before>
<observers>
<Mymodule>
<class>Mymodule_Model_Observer</class>
<method>addmyblock</method>
</Mymodule>
</observers>
</controller_action_layout_generate_xml_before>
</events>
</frontend>
while in oberser simply check and remove block :
<?php
class Mymodule_Model_Observer
{
public function addmyblock(Varien_Event_Observer $observer)
{
if(Mage::getStoreConfig("mymodule/general/enable")==1)
{
$layout = $observer->getLayout();
$layout->getUpdate()->addUpdate('<remove name="top.search"/>
<remove name="top.links"/>');
$layout->generateXml();
}
}
}.
Also i removed the code from xml <remove name="top.links"/>.So the code only remove block when the condition become true.

magento event listener

I don't want to apply the discount coupon on the products already discounted i.e on products having special price . So i created a event listen as :
<?xml version="1.0" ?>
<config>
<modules>
<Tweett_Fashionn>
<version>0.1.0</version>
</Tweett_Fashionn>
</modules>
<global>
<events>
<salesrule_validator_process>
<observers>
<Tweett_Fashionn_Hook>
<type>singleton</type>
<class>Tweett_Fashionn_Model_Observer</class>
<method>specialpricediscount</method>
</Tweett_Fashionn_Hook>
</observers>
</salesrule_validator_process>
</events>
</global>
and the observer file as
<?php
class Tweett_Fashionn_Model_Observer extends Varien_Event_Observer{
public function __construct(){
echo "<p style='color:red'>Hello World .. </p>";
}
public function specialpricediscount($observer){
$item=$observer['item'];
$_product = Mage::getSingleton('catalog/product')->load($item->getProductId());
if($_product->getSpecialPrice()>0 ){
$result = $observer['result'];
$result->setDiscountAmount(0);
}
}
}
?>
but it dont even print the hello world when i click on apply coupon button ..plz help
You're missing the ending from your config.xml? You may have just not pasted it in.
Have you made sure your module is enabled?
Take a look at this free extension it can help you debug extensions - http://www.magentocommerce.com/magento-connect/magneto-debug-8676.html
I had same issue.I think following is correct way :
<salesrule_validator_process>
<observers>
<Namespace_Modulename> // your namespace_modulename
<type>model</type> //change singleton to model
<class>Tweett_Fashionn_Model_Observer</class>
<method>specialpricediscount</method>
</Namespace_Modulename>
</observers>
</salesrule_validator_process>
May this will help you.

Resources