I can't get my controller to fire. So I must be doing something wrong, but I can't figure it out and I am hoping someone can steer me in the right direction. Below is my config.xml file.
<?xml version="1.0"?>
<config>
<modules>
<Unleaded_GiftRegistry>
<version>0.1.0</version>
</Unleaded_GiftRegistry>
</modules>
<frontend>
<routers>
<giftregistry>
<args>
<modules>
<giftregistry before="Enterprise_GiftRegistry">Unleaded_GiftRegistry</giftregistry>
</modules>
</args>
</giftregistry>
</routers>
</frontend>
</config>
Here is my controller:
<?php
include_once("Enterpise/GiftRegistry/controllers/IndexController.php");
class Unleaded_GiftRegistry_IndexController extends Enterprise_GiftRegistry_IndexController
{
Mage::log("Some useful debugging information");
/**
* Add product items to customer active gift registry action
*/
public function giftregistryAction()
{
if ($item = $this->getRequest()->getParam('product')) {
try {
$entity = Mage::getModel('enterprise_giftregistry/entity')
->load($this->getRequest()->getParam('entity'));
if ($entity && $entity->getId()) {
$entity->addItem((int)$item);
$this->_getSession()->addSuccess(
Mage::helper('enterprise_giftregistry')->__('The item have been added to gift registry.')
);
}
} catch (Mage_Core_Exception $e) {
if ($e->getCode() == Enterprise_GiftRegistry_Model_Entity::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) {
$product = Mage::getModel('catalog/product')->load((int)$item);
$query['options'] = Enterprise_GiftRegistry_Block_Product_View::FLAG;
$query['entity'] = $this->getRequest()->getParam('entity');
$this->_redirectUrl($product->getUrlModel()->getUrl($product, array('_query' => $query)));
return;
}
$this->_getSession()->addError($e->getMessage());
$this->_redirect('giftregistry');
return;
} catch (Exception $e) {
$this->_getSession()->addError($this->__('Failed to add item to gift registry.'));
}
}
$this->_redirect('giftregistry');
}
}
Thank you for your help in advance.
I think you need to change your config to be
<frontend>
<routers>
<giftregistry>
<args>
<modules>
<Unleaded_GiftRegistry before="Enterprise_GiftRegistry">Unleaded_GiftRegistry</Unleaded_GiftRegistry>
</modules>
</args>
</giftregistry>
</routers>
</frontend>
Notice that I have replaced "giftregistry" in the grandchild node with "Unleaded_GiftRegistry".
Also, your Mage::log() instruction will never be hit since it is outside of an Action.
Try using ConfigViewer or CommerceBug from #AlanStorm to check whether your rewrites are being parsed correctly by Magento's Config.
HTH,
JD
Related
Ive made a custom module in magento. The Admin panel recognises it but not the store.. Ive checked many posts and sources but nothing solves my problem
Code In the app/etc/modules/Firstmagetest_All.xml:
<?xml version = "1.0"?>
<config>
<modules>
<Firstmagetest_Test>
<active>true</active>
<codePool>local</codePool>
</Firstmagetest_Test>
</modules>
</config>
Code in app/code/local/FirstMageTest/Test/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Firstmagetest_Test>
<version>1.0.0</version>
</Firstmagetest_Test>
</modules>
<frontend>
<routers>
<firstmage_test>
<use>standard</use>
<args>
<module>Firstmagetest_Test</module>
<frontName>test</frontName>
</args>
</firstmage_test>
</routers>
</frontend>
</config>
[html]
Code in app/code/local/FirstMageTest/Test/controllers/IndexController.php
<?php
class Firstmagetest_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction ()
{
echo 'test index';
}
public function mamethodeAction ()
{
echo 'test mymethod';
}
}
?>
I am creating a new module which will record all the data from contact us page.
and all the data information will show in admin panel.
I have following code in my config.xml
<?xml version="1.0"?>
<config>
<modules>
<Vampi_Contactsform>
<version>1.0.0</version>
</Vampi_Contactsform>
</modules>
<global>
<models>
<vampi_contactsform>
<class>Vampi_Contactsform_Model</class>
<resourceModel>vampi_contactsform_mysql4</resourceModel>
</vampi_contactsform>
</models>
<resources>
<vampi_setup>
<setup>
<module>Vampi_Contactsform</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</vampi_setup>
<vampi_write>
<connection>
<use>core_write</use>
</connection>
</vampi_write>
<vampi_read>
<connection>
<use>core_read</use>
</connection>
</vampi_read>
</resources>
<blocks>
<vampi_contactsform>
<class>Vampi_Contactsform_Block</class>
</vampi_contactsform>
</blocks>
<helpers>
<vampi_contactsform>
<class>Vampi_Contactsform_Helper</class>
</vampi_contactsform>
</helpers>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<vampi_contactsform before="Mage_Adminhtml">Vampi_Contactsform_Adminhtml</vampi_contactsform>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<frontend>
<routers>
<contactsform>
<args>
<modules>
<vampi_contactsform before="Mage_Contactsform">Vampi_Contactsform</vampi_contactsform>
</modules>
</args>
</contactsform>
</routers>
</frontend>
and my app\code\community\Vampi\Contactsform\controllers\Adminhtml\contactsformController.php contains
<?php
class Vampi_Contactsform_Adminhtml_ContactsformController extends Mage_Adminhtml_Controller_Action{
public function indexAction()
{
$this->_title($this->__('Sales'))->_title($this->__('Contact Enquiries'));
$this->loadLayout();
$this->_setActiveMenu('report/contactsform');
$this->_addContent($this->getLayout()->createBlock('vampi_contactsform/adminhtml_contactsform_list'));
$this->renderLayout();
}
public function deleteAction() {
$orderIds = $this->getRequest()->getPost('order_ids', array());
$countNonCancelOrder = 0;
foreach ($orderIds as $orderId) {
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$contact_form = Mage::getSingleton("core/resource")->getTableName('contact_form');
$db->delete($contact_form, "id = $orderId");
$countNonCancelOrder++;
}
if ($countNonCancelOrder) {
$this->_getSession()->addError($this->__('%s enquiry(s) deleted', $countNonCancelOrder));
}
$this->_redirect('*/*/');
}
public function gridAction()
{
$this->loadLayout();
$this->getResponse()->setBody(
$this->getLayout()->createBlock('vampi_contactsform/adminhtml_contactsform_list_grid')->toHtml()
);
}
}
Please help
this is giving 404 Error while opening page from Magento admin panel.
Thanks
Thecontroller is generated based on the admin session.
And you cannot share the admin and frontend sessions, that's why when making the call from the frontend 404 not found.
Anyway, it's not a good practice to make calls to frontend actions from the backend.
You should have 2 separate controllers, one for backend and one for frontend.
In order not to duplicate the code, you can put everything inside a method in a helper and just call that method in both controllers.
Can't give you a ready answer on a platter, but if you follow this article you should be good. Pay attention to the Debugging section on the bottom. It should help you figure out what the issue is.
Sorry guys, that was my silly mistake naming the controller.
I have renamed contactsformController.php to ContactsformController.php
I have been pulling my hair out over trying to get a hole punched out for the price block on the product page. I have looked at numerous sources, including some from you good people at stackoverflow, but I have been getting a fatal error, so something is incorrect. Here are some sources that I used:
http://invisiblezero.net/magento-ee-punch-hole-in-full-page-cache/
http://www.kingletas.com/2012/09/how-does-magento-full-page-cache-works.html
Magento full page cache
Trying get dynamic content hole-punched through Magento's Full Page Cache
How to implement magento cache hole punching for shopping cart block
As you can see, I have been all over, and I have read more in addition to this but some of them conflict a litt, and I think that is where I have my issue, now let me post some code for you.
cache.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<placeholders>
<SpecialPrice>
<block>catalog/product_price</block>
<name>product.pricing</name>
<placeholder>CATALOG_PRODUCT_PRICE</placeholder>
<container>MyStore_SpecialPrice_Model_Container_Cache</container>
<cache_lifetime>8640</cache_lifetime>
</SpecialPrice>
</placeholders>
</config>
cache.php
<?php
class MyStore_SpecialPrice_Model_Container_Cache extends Enterprise_PageCache_Model_Container_Abstract
{
/**
* Get customer identifier from cookies
*
* #return string
*/
protected function _getIdentifier()
{
return $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '');
}
/**
* Get cache identifier
*
* #return string
*/
protected function _getCacheId()
{
return 'CATALOG_PRODUCT_PRICE' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier());
}
/**
* Render block content
*
* #return string
*/
protected function _renderBlock()
{
$blockClass = $this->_placeholder->getAttribute('block');
$template = $this->_placeholder->getAttribute('template');
$block = new $blockClass;
$block->setTemplate($template);
return $block->toHtml();
}
}
congig.xml
<?xml version="1.0"?>
<config>
<modules>
<MyStore_SpecialPrice>
<version>0.1.0</version>
</MyStore_SpecialPrice>
</modules>
<frontend>
<events>
<catalog_product_get_final_price>
<observers>
<MyStore_SpecialPrice_Model_Observer>
<class>MyStore_SpecialPrice_Model_Observer</class>
<method>setSpecialPrice</method>
</MyStore_SpecialPrice_Model_Observer>
</observers>
</catalog_product_get_final_price>
</events>
</frontend>
<admin>
<routers>
<SpecialPrice>
<use>admin</use>
<args>
<module>MyStore_SpecialPrice</module>
<frontName>SpecialPrice</frontName>
</args>
</SpecialPrice>
</routers>
</admin>
<global>
<models>
<SpecialPrice>
<class>MyStore_SpecialPrice_Model</class>
</SpecialPrice>
</models>
</global>
</config>
snippet from local.xml
<reference name="right">
<block type="catalog/product_price" name="product.pricing" template="catalog/product/product-price-block.phtml" before="-" >
Let me know if there is anything that jumps out to you.
Im trying to call an Observer after the order has been created, and AFTER payment has been captured.
So far I've tried;
checkout_submit_all_after,
sales_order_payment_place_end,
sales_order_place_after,
sales_order_payment_pay,
sales_order_payment_capture,
sales_order_payment_transaction_save_after
Just to name the main ones.
I've also logged all Event Dispaches inside dispatchEvent() but found nothing that stands out and is only fired when i need it.
the issue i'm having is that the status of the order is always ether 'Payment Pending' or something that predated this; meaning that i don't know whether the order will fail or succeed.
My aim, is to fire a function only on successful orders.
thanks.
after much more testing i found the following Observer to do the trick;
checkout_onepage_controller_success_action
This returns just the order id, so;
$order_id = $observer->getData('order_ids');
$order = Mage::getModel('sales/order')->load($order_id);
and you see that the order status is 'processing' and the payment is aproved (or not).
1 ) here is custom config.xml for call observer file
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Modulename>
<version>0.1.0</version>
</Namespace_Modulename>
</modules>
<frontend>
<events>
<checkout_submit_all_after>
<observers>
<Namespace_Modulename_Customevent>
<type>singleton</type>
<class>Namespace_Modulename_Model_Observer</class>
<method>customFunction</method>
</Namespace_Modulename_Customevent>
</observers>
</checkout_submit_all_after>
</events>
</frontend>
</config>
2 ) create observer.php file inside your module/Model directory and paste this code
<?php
class Namespace_Modulename_Model_Observer
{
public function customFunction(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getOrder();
//here you can add your custom code
}
}
please try this.. sure it will help you !
I have also tried all event but didn't get success. Then I moved to override Mage OnePageController and called my custom function. Below is the code to override onestep checkout.
app\etc\modules\Namespace_Module.xml
<Namespace_Checkout>
<active>true</active>
<codePool>local</codePool>
</Namespace_Checkout>
app\code\local\Namespace\Checkout\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Checkout>
<version>0.1.0</version>
</Namespace_Checkout>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Namespace_Checkout before="Mage_OneStepCheckout">Namespace_Checkout</Namespace_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
app\code\local\Namespace\Checkout\controllers\OnepageController.php
<?php
require_once 'Mage/Checkout/controllers/OnepageController.php';
class Namespace_Checkout_OnepageController extends Mage_Checkout_OnepageController{
public function successAction(){
$session = $this->getOnepage()->getCheckout();
if (!$session->getLastSuccessQuoteId()) {
$this->_redirect('checkout/cart');
return;
}
$lastQuoteId = $session->getLastQuoteId();
$lastOrderId = $session->getLastOrderId();
$lastRecurringProfiles = $session->getLastRecurringProfileIds();
if (!$lastQuoteId || (!$lastOrderId && empty($lastRecurringProfiles))) {
$this->_redirect('checkout/cart');
return;
}
$this->customFunction(); // Custom function to call
$session->clear();
$this->loadLayout();
$this->_initLayoutMessages('checkout/session');
Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId)));
$this->renderLayout();
}
function customFunction(){
// This function is calling before clearing order session
//Here you can put all your custom code
}
}
?>
In the above controller, I have added customFunction() wher you can put your custom code.
Hope it will help you!
I have created a module to add a discount code to the customers cart if they are either a new customer or have not ordered in the last 24 hours, it is for a company supplying lunch for their employees and they receive a subsidiary each day to use of £3.00.
So I have:
app/code/local/Brave/Subsidary/controllers/CartControlller.php
<?php
require_once Mage::getModuleDir('controllers', 'Mage_Checkout').DS.'CartController.php';
class Brave_Subsidary_CartController extends Mage_Checkout_CartController {
const DISCOUNTCODE = 'BCOMSTAFF';
public function addAction() {
parent::addAction();
$this->autoApplySubsidaryDiscount();
}
public function indexAction() {
parent::addAction();
$this->autoApplySubsidaryDiscount();
}
public function autoApplySubsidaryDiscount() {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', $customer->getId());
if(!$orders->getSize()) {
// New Customer...
$this->applyDiscountCoupon();
} else {
// Check last order date
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFilter('customer_id', $customer->getId())
->setOrder('created_at', Varien_Data_Collection_Db::SORT_ORDER_DESC);
$newestOrder = $orderCollection->getFirstItem();
$dateToday = Mage::getModel('core/date')->timestamp(time());
$lastOrderDate = Mage::getModel('core/date')->timestamp(strtotime($newestOrder->getData('created_at')));
// only apply if last order was more than 24hrs ago..
if( $dateToday > $lastOrderDate ) {
$this->applyDiscountCoupon();
}
}
}
public function applyDiscountCoupon() {
Mage::getSingleton("checkout/session")->setData("coupon_code",self::DISCOUNTCODE);
Mage::getSingleton('checkout/cart')->getQuote()->setCouponCode(self::DISCOUNTCODE)->save();
}
}
?>
app/code/local/Brave/Subsidary/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Brave_Subsidary>
<version>0.1.0</version>
</Brave_Subsidary>
</modules>
<frontend>
<routers>
<checkout>
<use>standard</use>
<args>
<modules>
<Brave_Subsidary before="Mage_Checkout">Brave_Subsidary</Brave_Subsidary>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
Then my module file:
app/etc/modules/Brave_Subsidary.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Brave_Subsidary>
<active>true</active>
<codePool>local</codePool>
</Brave_Subsidary>
</modules>
</config>
The problem is that I am getting a redirect loop on the cart page or from adding an item to the cart, this is probably a real simple issue but trying to Google anything related this is a real needle in a haystack!
The error FireFox tells me is:
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
The problem is:
You are calling parent:addAction() which redirects back to indexAction which is your indexAction which calles parent:addAction again...thus the redirect loop.
Bad code:
public function indexAction() {
parent::addAction();
$this->autoApplySubsidaryDiscount();
}
You must not call addAction in your above seen custom indexAction!
Solution:
Remove
public function indexAction() {
parent::addAction();
$this->autoApplySubsidaryDiscount();
}
Change
public function addAction() {
$this->autoApplySubsidaryDiscount();
parent::addAction();
}
Done.
But better instead rewriting the controller would be to use an observer...but thats another thread i guess :)