How to change URL on a magento extension? - php

I want to know how I can change the URL of my checkout cart. Whenever I continue to checkout or click on the checkout button, I get to the URL: mypage.com/onepagecheckout
I'm using this extension: http://www.magentocommerce.com/magento-connect/one-page-checkout.html
The only way I got it working was making one rewrite and a redirect, one rewrite from "onepagecheckout" to "checkout" and another one permanent redirect from "onepagecheckout" to "checkout". I don't think this method is best practice, so I would like to know if there's a better option.
I tried going to the app/code/community/IWD/OnepaceCheckout/etc/config.xml and changed frontname to "checkout", but even that did not change anything.
Thanks for your time and help would be greatly appreciated!

Please check in config.xml.here you found that onepagecheckout
just change onepagecheckout according
<frontend>
<routers>
.......
<use>standard</use>
<args>
<module>IWD_OnepaceCheckout/</module>
<frontName>onestepcheckout</frontName>
</args>
.......
</routers>
also changed it onestepcheckout.xml accoding to you wish frontName

Solved the problem by changing the in config.xml on both standard and admin.

Related

Remove controller name from url for my custom module in Magento

I have created my own module. In that, I used IndexController. So the URL for me looks like http://192.168.1.25/upload/index.php/capsync/index/api.
I want to shorten the URL like http://192.168.1.25/upload/index.php/capsync/api.
I want to remove controller name. I tried in the config.xml file, but it shows a 404 error. I don't know how to fix this. Any ideas?
Try Magento rewrite functionality..
Open config.xml and add below code. It will make URL http://192.168.1.25/module/index/index/id/5 --> http://192.168.1.25/module/id/5 like this. Change Rule according to your need.
<global>
<rewrite>
<fancy_url>
<from><![CDATA[/module\/(.*)/]]></from>
<to><![CDATA[module/index/index/id/$1/]]></to>
<complete>1</complete>
</fancy_url>
</rewrite>
...
The most common solution for this is to divide your endpoint info different controller-files. In your example, you could change name from IndexController.php to ApiController.php and the method name from ApiAction() to IndexAction().
The code which works for me is as follows.
<global>
<rewrite>
<fancy_url>
<from><![CDATA[/capsync\/(.*)/]]></from>
<to><![CDATA[/capsync/index/$1/]]></to>
<complete>1</complete>
</fancy_url>
</rewrite>

Magento: Check if product is already in cart

Using magento for my shopping cart system. I have mini cart on top menu, when I added product it will show product title with price in mini cart. Currently have product quantity edit link but I need quantity box in mini cart to update quantity with ajax. I have followed this link http://ceckoslab.com/magento/magento-check-if-product-is-in-cart/, but getting following error
Fatal error: Class 'Mage_Smartview_Helper_Data' not found in /app/Mage.php on line 547
can anyone help me to resolve above error ?
When Magento is trying to look to Mage_Somemodule_ instead of your own module, it does means that it did not found your own file or your own module.
Three possible reasons :
Your module is not recognized at all, maybe something is wrong in your module definition
Something is wrong/mistyped in your config.xml
Something is wrong/mistyped in your class name
Be sure you have everything right from the tutorial and/or copy paste your code here so we can help further
In this case the two xml are wrong in the way that it should not ignore case sensitivity
CeckosLab_SmartView.xml
<?xml version="1.0"?>
<config>
<modules>
<CeckosLab_SmartView>
<active>true</active>
<codePool>local</codePool>
</CeckosLab_SmartView >
</modules>
</config>
config.xml
<?xml version="1.0"?>
<config>
<modules>
<CeckosLab_SmartView>
<version>1.0.0</version>
</CeckosLab_SmartView>
</modules>
<global>
<helpers>
<smartview>
<class>CeckosLab_SmartView_Helper</class>
</smartview>
</helpers>
</global>
</config>
please check it the Answer of stackoverflow
Click Here
In this link check this answer with 20 votes
Please check the releasenotes:
It will help you guide how to solve this issue
If your helper error contains Mage_ before your module, it means your helper is either not defined or defined incorrectly in your module's xml or you are calling it incorrectly.
If it is defined correctly this should work:
Mage::helper('smartview')->doSomething();
or try:
Mage::helper('ceckoslab_smartview')->doSomething();
Also, make sure you clear the cache as xml is cached heavily.
Hope this helps
Make enrty in config.xml
<global>
......
<helpers>
<test>
<class>Module_Test_Helper</class>
</test>
</helpers>
......
</global>
Create a Data.php file inside Helper folder and write following code
<?php
class Module_Test_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Thats it you need to do now if you call this code it will not throw any error:
<?php Mage::helper("test")->actionname(); ?>

can not find the save action when magento submit a form

I'm new to magento, and I'm confused how magento handle forms.
I'm using sample data given by magento
In my admin panel, I go to catalog,manage product, and try to figure out how magento save those form data to database. let's say I edit the item which id=881, from the url, when render the page,they use app/design/adminhtml/default/default/template/catalog/product/edit.phtml for the template, and in this file, there is lines of code
<form action="<?php echo $this->getSaveUrl() ?>" method="post" id="product_edit_form" enctype="multipart/form-data">
<?php echo $this->getBlockHtml('formkey')?>
<div style="display:none"></div>
</form>
and i tried to find out which action script specified to handle this post form, I echo it to the page and got something like localhost/magento/index.php/admin/catalog_product/save/id/881/key/d092b22cecaae47664a8c9f9eea63a50/, I think admin is the namesapce, catalog_product is the controllers' name, and save should be the action name, and I look for the file located in Mage_Catalog_controllers_ProductController.php and i can not find the save action.
Admin is your module name, which should give away where you should be looking for the controller,
If you open up app\code\core\Mage\Adminhtml\etc\config.xml,
you will notice,
#FIle :82
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<module>Mage_Adminhtml</module>
<frontName>admin</frontName>
</args>
</adminhtml>
</routers>
</admin>
Notice, <frontName>admin</frontName>
thus for above path of the controller is,
app\code\core\Mage\Adminhtml\controllers\Catalog\ProductController.php
will give you the actions related to product in admin, same way you can track your blocks, helpers and models.

Magento customer registration 'Honey Pot' captcha

I thought I had this one sorted but I have run into a snag. I want to add a 'Honey Pot' to the customer registration form, for those unfamiliar this technique involves hiding a text input using CSS and assumes that the average bot will want to fill it in. Humans however, will not see the field so it needs to validate as empty.
In Magento I created a new module, added the following to the config.xml:
<global>
<fieldsets>
<customer_account>
<honeytrap><create>1</create><update>1</update></honeytrap>
</customer_account>
</fieldsets>
<models>
<customer>
<rewrite>
<customer>MyStore_Honeytrap_Model_Customer</customer>
</rewrite>
</customer>
</models>
</global>
I then added a little bit extra to the validate function to check the field is empty. This all correct as far as I can see but at about line 278 in the AccountController.php the extractData() discards the input field from the post data in the request. I'm still very new to Magento so hoping to learn something here too but how do I prevent the field being stripped out of the post by extractData()?
Guess I just want to know what I'm missing, I've read a few posts on the internet regarding adding a custom field so as far as I know this should be working but maybe I've missed something out as I didn't include the Entity setup since I don't need to save this field in the database it's purely to validate the registration is from a human (as much as possible).
Thanks for any help, I'm sure it's probably something ridiculous that I've missed.
EDIT: Thanks to #gordon-knoppe pointer on using the event:
public function check_trap(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$post = $event->getControllerAction()->getRequest()->getPost();
// Check Honeytrap is empty
if (Zend_Validate::is( trim($post['fname']) , 'NotEmpty'))
{
$customerHelper = Mage::helper('customer');
$error = $customerHelper->__('A problem has occured with your registration.');
Mage::getModel('customer/session')->addError($error);
Mage::app()->getResponse()
->setRedirect(Mage::getUrl('customer/account', array('_secure' => true)))
->sendResponse();
exit;
}
}
With this in the config.xml:
<events>
<controller_action_predispatch_customer_account_createpost>
<observers>
<mystore_honeytrap_observer>
<type>singleton</type>
<class>Mystore_Honeytrap_Model_Observer</class>
<method>check_trap</method>
</mystore_honeytrap_observer>
</observers>
</controller_action_predispatch_customer_account_createpost>
</events>
A more detached way to handle this could be to register an observer for before the relevant controller action (controller_action_predispatch_*) to detect whether your form field has been populated and, if so, redirect them out to prevent the native action from ever processing the request.

config.xml override results in cart not visible?

I am building a second add to cart button with a different redirect on a magento platform.
The tutorial I've used is self explainatory. See here
It works okey as the redirect is in place.
The thing is: The cart itself doesnt show its page (cart.phtml) anymore.
Any idea how to fix this? Or where the problem exists?
If I remove the code underneath the cart is back again, as the redirect isn't working anymore.
File : config.xml
<global>
<routers>
<checkout>
<rewrite>
<cart>
<to>mycheckout/cart</to>
<override_actions>true</override_actions>
<actions>
<add>
<to>mycheckout/cart/add</to>
</add>
</actions>
</cart>
</rewrite>
</checkout>
</routers>
</global>
Seems like your extension does not extend the cart controller that you are overwriting making it impossible to display the methods from original controller

Categories