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
Related
I'm using Magento 1.9.2 and I'm developing a custom extension.
Here is my config file of the extension:
<?xml version="1.0"?>
<config>
<frontend>
<layout>
<updates>
<automatedstatus>
<file>automatedstatus.xml</file>
</automatedstatus>
</updates>
</layout>
</frontend>
<modules>
<VivasIndustries_AutomatedStatus>
<version>1.0.0</version>
</VivasIndustries_AutomatedStatus>
</modules>
<global>
<models>
<automatedstatus>
<class>VivasIndustries_AutomatedStatus_Model</class>
<resourceModel>vivasindustries_automatedstatus_resource</resourceModel>
</automatedstatus>
<vivasindustries_automatedstatus_resource>
<class>VivasIndustries_AutomatedStatus_Model_Resource</class>
<entities>
<automatedstatus>
<table>VivasIndustries_AutomatedStatus</table>
</automatedstatus>
</entities>
</vivasindustries_automatedstatus_resource>
</models>
<resources>
<automatedstatus_setup>
<setup>
<module>VivasIndustries_AutomatedStatus</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</automatedstatus_setup>
<automatedstatus_read>
<connection>
<use>core_read</use>
</connection>
</automatedstatus_read>
<automatedstatus_write>
<connection>
<use>core_write</use>
</connection>
</automatedstatus_write>
</resources>
<helpers>
<automatedstatus>
<class>VivasIndustries_AutomatedStatus_Helper</class>
</automatedstatus>
</helpers>
<blocks>
<automatedstatus>
<class>VivasIndustries_AutomatedStatus_Block</class>
</automatedstatus>
</blocks>
</global>
<crontab>
<jobs>
<automatedstatus>
<schedule>
<cron_expr>*/1 * * * *</cron_expr>
</schedule>
<run>
<model>automatedstatus/observer::setStatus</model>
</run>
</automatedstatus>
</jobs>
</crontab>
<adminhtml>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<system>
<children>
<config>
<children>
<automatedstatusadmin>
<title>Vivas - All</title>
</automatedstatusadmin>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<VivasIndustries_AutomatedStatus before="Mage_Adminhtml">VivasIndustries_AutomatedStatus_Adminhtml</VivasIndustries_AutomatedStatus>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
For developing purposes I have set the cron job to run every minute.
Here is my observer.php
class VivasIndustries_AutomatedStatus_Model_Observer
{
public function setStatus() {
Mage::log("The order status was changed!");
}
}
Like this every minute I can see that the cron job is done by seeing that The order status was changed! message is added to my system.log file
However when I change it to this:
<?php
class VivasIndustries_AutomatedStatus_Model_Observer
{
public function setStatus() {
$orderId = "100005082";
$order = Mage::getModel('sales/order')->load($orderId);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true);
$order->save();
Mage::log("The order status was changed!");
}
}
In the system.log file there are no longer The order status was changed! message added and also the order status is not changed.
I am pretty sure the problem comes from the code for order status changing.
Where is my mistake how can I fix it?
Thanks in advance!
When you use $order->setState(Mage_Sales_Model_Order::STATE_COMPLETE, true); Magento throws exception "The Order State "complete" must not be set manually".
So you need to change the way to set state manually. Please try this
$orderId = "100005082";
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$order->setData('state',Mage_Sales_Model_Order::STATE_COMPLETE);
$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE);
$order->save();
You must use loadByIncrementId() instead of load().
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
Actually, in Magento, the Order State "complete" must not be set manually. It requires the order to have Invoice and Shipment created first. If you really want to mark it as complete, you can do it as follow:
public function setStatus() {
$orderId = "100005082";
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
if (!$order->getId()) {
return false;
}
if (!$order->canInvoice()) {
return false;
}
$savedQtys = array();
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($savedQtys);
if (!$invoice->getTotalQty()) {
return false;
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
//create invoice
$invoice->register();
$invoice->getOrder()->setCustomerNoteNotify(false);
$invoice->getOrder()->setIsInProcess(true);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($invoice)
->addObject($invoice->getOrder());
$transactionSave->save();
//create shipment
$shipment = $order->prepareShipment();
if ($shipment) {
$shipment->register();
$order->setIsInProcess(true);
$transaction_save = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder())
->save();
}
}
Then the order state will automatically set as COMPLETE.
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 working on Magento framework.
I want to rewrite Mage_Adminhtml_Block_Widget_Grid to optimize search filtering.
I add rewrite block on my etc/config.xml and name block as grid_search_date.
<config>
<global>
<helpers>
<core>
<rewrite>
<data>Jdate_Format_Helper_Data</data>
</rewrite>
</core>
</helpers>
<blocks>
<grid_search_date>
<rewrite>
<widget_grid>Jdate_Format_Block_Widget_Grid</widget_grid>
</rewrite>
</grid_search_date>
<topmenu_admin_time>
<rewrite>
<widget_grid_column_renderer_date>Jdate_Format_Block_Widget_Grid_Column_Renderer_Date</widget_grid_column_renderer_date>
</rewrite>
</topmenu_admin_time>
</blocks>
</global>
</config>
You can see Jdate_Format_Block_Widget_Grid want to rewrite widget_grid and we move to this file
class Jdate_Format_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
protected function _addColumnFilterToCollection($column)
{
if ($this->getCollection()) {
$field = ( $column->getFilterIndex() ) ? $column->getFilterIndex() : $column->getIndex();
if ($column->getFilterConditionCallback()) {
call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column);
} else {
$cond = $column->getFilter()->getCondition();
die(var_dump($cond["orig_from"]));
die(var_dump($cond["orig_to"]));
if ($field && isset($cond)) {
$this->getCollection()->addFieldToFilter($field , $cond);
}
}
}
return $this;
}
}
But nothing happen. But if I change directly Widget_Grid file to this, it works.
Any idea?
Try
<global>
<blocks>
<adminhtml> <!-- should be the name of the module -->
<rewrite>
<widget_grid>Jdate_Format_Block_Widget_Grid</widget_grid>
</rewrite>
</adminhtml>
</blocks>
.....
Hi all i am new with magento and i am trying to insert records in database in admin section. This is a function of controller file.
public function saveAction()
{
$data = $this->getRequest()->getParams();
$arrData = array('number_of_products'=>$data['number_of_products'],'price'=>$data['price']);
$model = Mage::getModel('a/totebags')->setData($arrData);
try {
$insertId = $model->save()->getId();
echo "Data successfully inserted. Insert ID: ".$insertId;
} catch (Exception $e){
echo $e->getMessage();
}
}
My Question is that when run this code then i got this error:
Fatal error: Call to a member function setData() on a non-object in /Library/WebServer/Documents/magento/app/code/community/ToteBags/Adminform/controllers/Adminhtml/AdminformController.php on line 40
This is my config.xml
<?xml version="1.0"?>
<config>
<modules>
<ToteBags_Adminform>
<version>1.0.0</version>
</ToteBags_Adminform>
</modules>
<global>
<blocks>
<totebags_adminform>
<class>ToteBags_Adminform_Block</class>
</totebags_adminform>
</blocks>
<helpers>
<totebags_adminform>
<class>ToteBags_Adminform_Helper</class>
</totebags_adminform>
</helpers>
<models>
<totebags_adminform>
<class>ToteBags_Adminform_Model</class>
<resourceModel>totebags_adminform_mysql4</resourceModel>
</totebags_adminform>
<totebags_adminform_mysql4>
<class>ToteBags_Adminform_Model_Mysql4</class>
<entities>
<category>
<table>totebags_fbstore_category</table>
</category>
<category_product>
<table>totebags_fbstore_category_product</table>
</category_product>
</entities>
</totebags_adminform_mysql4>
</models>
<resources>
<totebags_adminform_setup>
<setup>
<module>ToteBags_Adminform</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</totebags_adminform_setup>
<totebags_adminform_write>
<connection>
<use>core_write</use>
</connection>
</totebags_adminform_write>
<totebags_adminform_read>
<connection>
<use>core_read</use>
</connection>
</totebags_adminform_read>
</resources>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<totebags_adminform after="Mage_Adminhtml">ToteBags_Adminform_Adminhtml</totebags_adminform>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<totebags_adminform>
<file>totebags_adminform.xml</file>
</totebags_adminform>
</updates>
</layout>
<translate>
<modules>
<ToteBags_Adminform>
<files>
<default>ToteBags_Adminform.csv</default>
</files>
</ToteBags_Adminform>
</modules>
</translate>
</adminhtml>
<default>
<totebags_adminform>
<general>
<default_sort_by><![CDATA[position]]></default_sort_by>
</general>
</totebags_adminform>
</default>
</config>
Please help me.
Did you upload app/etc/modules/modulename.xml file that has codePool details something like this
true
core
replace Mage_Connect by namespace_modulename
Looks like above part you have done.
Controller is not extended using class Varien_Object so there is no setData to be used with Controller class instance.
$model = Mage::getModel('a/totebags')->setData($arrData);
what class is extended to create your Model.You have probably extended some controller.
As error points to some controller.
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