I'm attempting to add a very basic (literally just a div with some text and a continue button) step to the onepage checkout but have come up short, in that they don't work (i suspect it's because they were created prior to 1.7.0.2), when following the examples here (Fontis), here (inchoo) and here (Magento Forums).
I've also tried to combined bits from different examples and forum posts but i've gotten no where in the week i've been attempting to do this.
I have been recommended the book 'Php Architect's Guide to E-Commerce Programming with Magento' which i've purchased and will begin reading but i was wondering if someone could kindly point me in the right direction in adding a new step to 1.7.0.2's onepage checkout?
Much appreciated for any help!
I have done this successfully in 1.7.0.2 following this guide:
http://www.excellencemagentoblog.com/magento-onestep-checkout-add-step
In summary, you need to extend/override Mage_Checkout_Block_Onepage::getSteps() to add your new step in the sequence.
Create your new step's block/template (loaded using an Ajax request when the previous step is completed) Your block class will need to extend: Mage_Checkout_Block_Onepage_Abstract
You also need to extend the onepagecheckout javascript as this does much of the heavy lifting. The Prototype library has a nice way of doing this.
Finally you will need to extend the controller class (Mage_Checkout_OnepageController) to override the responses of any existing steps, return the content of your new step (loaded using ajax), and handle the save action of any data (form fields etc) entered in your new step.
By default magento gives some checkout steps. But Sometime you need to add extra information from the customer for future reference. A common requested customization is to add the Custom Form in default checkout process.
This is not good practice to touch core files. You can do this via overriding Modules.
In this example Comapnyname is Ipragmatech and Module name is Checkoutstep.
Step1: Add Custom step in the checkout process
Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code
class Ipragmatech_Checkoutstep_Block_Onepage_Checkoutstep extends Mage_Checkout_Block_Onepage_Abstract
{
protected function _construct()
{
$this->getCheckout()->setStepData('checkoutstep', array(
'label' => Mage::helper('checkout')->__('Invitation to participation'),
'is_show' => true
));
parent::_construct();
}
}
Step2: Add steps which and where you want in the checkout process
Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code
class Ipragmatech_Checkoutstep_Block_Onepage extends Mage_Checkout_Block_Onepage
{
public function getSteps()
{
$steps = array();
if (!$this->isCustomerLoggedIn()) {
$steps['login'] = $this->getCheckout()->getStepData('login');
}
$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'checkoutstep', 'review');
foreach ($stepCodes as $step) {
$steps[$step] = $this->getCheckout()->getStepData($step);
}
return $steps;
}
}
Step3: Grab the submitted value of custom form and set the values of Custom form
Open the ipragmatech > Checkoutstep > controllers > OnepageController.php and write the following fucntion
public function saveCheckoutstepAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
//Grab the submited value
$_entrant_name = $this->getRequest()->getPost('entrant_name',"");
$_entrant_phone = $this->getRequest()->getPost('entrant_phone',"");
$_entrant_email = $this->getRequest()->getPost('entrant_email',"");
$_permanent_address = $this->getRequest() ->getPost('permanent_address',"");
$_address = $this->getRequest()->getPost('local_address',"");
Mage::getSingleton('core/session') ->setIpragmatechCheckoutstep(serialize(array(
'entrant_name' =>$_entrant_name,
'entrant_phone' =>$_entrant_phone,
'entrant_email' =>$_entrant_email,
'permanent_address' =>$_permanent_address,
'address' =>$_address
)));
$result = array();
$redirectUrl = $this->getOnePage()->getQuote()->getPayment() ->getCheckoutRedirectUrl();
if (!$redirectUrl) {
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->_getReviewHtml()
);
}
if ($redirectUrl) {
$result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
Step4: Save Custom Form information
When checkout_onepage_controller_success_action
event hook is called. Open the Ipragmatech > Checkoutstep > Model >Observer.php and write the following
class Ipragmatech_Checkoutstep_Model_Observer {
const ORDER_ATTRIBUTE_FHC_ID = 'checkoutstep';
public function hookToOrderSaveEvent() {
if (Mage::helper('checkoutstep')->isEnabled()) {
$order = new Mage_Sales_Model_Order ();
$incrementId = Mage::getSingleton ( 'checkout/session' )->getLastRealOrderId ();
$order->loadByIncrementId ( $incrementId );
// Fetch the data
$_checkoutstep_data = null;
$_checkoutstep_data = Mage::getSingleton ( 'core/session' )->getIpragmatechCheckoutstep ();
$model = Mage::getModel ( 'checkoutstep/customerdata' )->setData ( unserialize ( $_checkoutstep_data ) );
$model->setData ( "order_id",$order["entity_id"] );
try {
$insertId = $model->save ()->getId ();
Mage::log ( "Data successfully inserted. Insert ID: " . $insertId, null, 'mylog.log');
} catch ( Exception $e ) {
Mage::log ( "EXCEPTION " . $e->getMessage (), null, 'mylog.log' );
}
}
}
}
Magento – Add Custom Form in Checkout Extension is a complete solution to add extra step in Checkout process for your ecommerce website. It allow admin to export data from custom table in CSV format.
Visit the link to get this free extension http://www.magentocommerce.com/magento-connect/custom-form-in-checkout.html
Related
I am try to create an additional step in the Magento onepage checkout process.
I am following the tutorial located at http://www.excellencemagentoblog.com/magento-onestep-checkout-add-step but specifically adding a step at the end before the review.
My folder / file structure is as follows. (Ignore widget.xml)
I have uploaded the code in it's current state to this gist:
https://gist.github.com/Relequestual/5263498
I have the theme set to 'new'.
I am var_dumping the $this->getSteps() which shows that the 'testcheck' returns null.
In config.xml, if I change under gobal, blocks, checkout, rewrite, onepage to the same class with '_TestCheck' on the end, the checkout doesn't display at all, but 'Test Check' appears in the progress section on the right. When I revert this change, it then shows as not being null in the var dump like so...
But, I still don't see the step actually added to the page.
I've not done any magento before, so feel a bit in over my head. I expect there is some problem with the xml configuration files, but I've been working on this for 2 days now, and am somewhat lost as to what else I can try.
I know this question may sound similar to others, which it is, however I can't find a question where the OP has the same symptoms as what I am seeing.
By default magento gives some checkout steps. But Sometime you need to add extra information from the customer for future reference. A common requested customization is to add the Custom Form in default checkout process.
This is not good practice to touch core files. You can do this via overriding Modules.
In this example Comapnyname is Ipragmatech and Module name is Checkoutstep.
Step1: Add Custom step in the checkout process
Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code
class Ipragmatech_Checkoutstep_Block_Onepage_Checkoutstep extends Mage_Checkout_Block_Onepage_Abstract
{
protected function _construct()
{
$this->getCheckout()->setStepData('checkoutstep', array(
'label' => Mage::helper('checkout')->__('Invitation to participation'),
'is_show' => true
));
parent::_construct();
}
}
Step2: Add steps which and where you want in the checkout process
Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code
class Ipragmatech_Checkoutstep_Block_Onepage extends Mage_Checkout_Block_Onepage
{
public function getSteps()
{
$steps = array();
if (!$this->isCustomerLoggedIn()) {
$steps['login'] = $this->getCheckout()->getStepData('login');
}
$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'checkoutstep', 'review');
foreach ($stepCodes as $step) {
$steps[$step] = $this->getCheckout()->getStepData($step);
}
return $steps;
}
}
Step3: Grab the submitted value of custom form and set the values of Custom form
Open the ipragmatech > Checkoutstep > controllers > OnepageController.php and write the following fucntion
public function saveCheckoutstepAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
//Grab the submited value
$_entrant_name = $this->getRequest()->getPost('entrant_name',"");
$_entrant_phone = $this->getRequest()->getPost('entrant_phone',"");
$_entrant_email = $this->getRequest()->getPost('entrant_email',"");
$_permanent_address = $this->getRequest() ->getPost('permanent_address',"");
$_address = $this->getRequest()->getPost('local_address',"");
Mage::getSingleton('core/session') ->setIpragmatechCheckoutstep(serialize(array(
'entrant_name' =>$_entrant_name,
'entrant_phone' =>$_entrant_phone,
'entrant_email' =>$_entrant_email,
'permanent_address' =>$_permanent_address,
'address' =>$_address
)));
$result = array();
$redirectUrl = $this->getOnePage()->getQuote()->getPayment() ->getCheckoutRedirectUrl();
if (!$redirectUrl) {
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->_getReviewHtml()
);
}
if ($redirectUrl) {
$result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
Step4: Save Custom Form information
When checkout_onepage_controller_success_action
event hook is called. Open the Ipragmatech > Checkoutstep > Model >Observer.php and write the following
class Ipragmatech_Checkoutstep_Model_Observer {
const ORDER_ATTRIBUTE_FHC_ID = 'checkoutstep';
public function hookToOrderSaveEvent() {
if (Mage::helper('checkoutstep')->isEnabled()) {
$order = new Mage_Sales_Model_Order ();
$incrementId = Mage::getSingleton ( 'checkout/session' )->getLastRealOrderId ();
$order->loadByIncrementId ( $incrementId );
// Fetch the data
$_checkoutstep_data = null;
$_checkoutstep_data = Mage::getSingleton ( 'core/session' )->getIpragmatechCheckoutstep ();
$model = Mage::getModel ( 'checkoutstep/customerdata' )->setData ( unserialize ( $_checkoutstep_data ) );
$model->setData ( "order_id",$order["entity_id"] );
try {
$insertId = $model->save ()->getId ();
Mage::log ( "Data successfully inserted. Insert ID: " . $insertId, null, 'mylog.log');
} catch ( Exception $e ) {
Mage::log ( "EXCEPTION " . $e->getMessage (), null, 'mylog.log' );
}
}
}
}
Magento – Add Custom Form in Checkout Extension is a complete solution to add extra step in Checkout process for your ecommerce website. It allow admin to export data from custom table in CSV format.
Visit the link to get this free extension http://www.magentocommerce.com/magento-connect/custom-form-in-checkout.html
I want to create some kind of sitemap in extbase/fluid (based on the pagetree). I have loaded the pages table into a model:
config.tx_extbase.persistence.classes.Tx_MyExt_Domain_Model_Page.mapping.tableName = pages
I have created a controller and repository, but get stuck on the part wich can load the subpages as relation into my model.
For example:
$page = $this->pageRepository->findByPid($rootPid);
Returns my rootpage. But how can I extend my model that I can use $page->getSubpages() or $page->getNestedPages()?
Do I have to create some kind of query inside my model? Or do I have to resolve this with existing functions (like the object storage) and how?
I tried a lot of things but can simply figure out how this should work.
you have to overwrite your findByPid repository-method and add
public function findByPid($pid) {
$querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);
$this->setDefaultQuerySettings($querySettings);
$query = $this->createQuery();
$query->matching($query->equals('pid', $pid));
$pages = $query->execute();
return $pages;
}
to get all pages. Than you can write your own getSubpages-method like
function getSubpages($currentPid) {
$subpages = $this->pagesRepository->findByPid($currentPid);
if (count($subpages) > 0) {
$i = 0;
foreach($subpages as $subpage) {
$subpageUid = $subpage->getUid();
$subpageArray[$i]['page'] = $subpage;
$subpageArray[$i]['subpages'] = $this->getSubpages($subpageUid);
$i++;
}
} else {
$subpageArray = Array();
}
return $subpageArray;
}
i didn't test this method, but it looks like this to get alle subpages.
i wonder that i could´t find a typo3 method that return the complete Page-Tree :( So i write a little function (you can use in an extbase extension), for sure not the best or fastes way, but easy to extend or customize ;)
first you need an instance of the PageRepository
$this->t3pageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
this->t3pageRepository->init();
make the init, to set some basic confs, like "WHERE deletet = 0 AND hidden = 0..."
then with this function you get an array with the page data and subpages in. I implement yust up to three levels:
function getPageTree($pid,$deep=2){
$fields = '*';
$sortField = 'sorting';
$pages = $this->t3pageRepository->getMenu($pid,$fields,$sortField);
if($deep>=1){
foreach($pages as &$page) {
$subPages1 = $this->t3pageRepository->getMenu($page['uid'],$fields,$sortField);
if(count($subPages1)>0){
if($deep>=2){
foreach($subPages1 as &$subPage1){
$subPages2 = $this->t3pageRepository->getMenu($subPage1['uid'],$fields,$sortField);
if(count($subPages2>0)){
$subPage1['subpages'] = $subPages2;
}
}
}
$page['subpages'] = $subPages1;
}
}
}
return $pages;
}
I am trying to create a new shipping method. This method allows users to COLLECT items from a paticular warehouse. So not much involved really.
I have followed a couple of tuts online, and have my module built and installed. It is working on the backend, i can enAble it, and set various values.
When i use the frontend checkout....or even use the following code:
Mage::getSingleton('shipping/config')->getAllCarriers();
I do not get the new shipping method name output.
The message i get on the frontend checkout is:
Sorry, no quotes are available for this order at this time.
Even though i have other shipping methods enabled.
I have another extension in use (regarding stock located in several warehouses). As part of this extension, it lists available shipping options...so that i can assign specific options to a specific warehouse. My new shipping method is not listed that shipping options list.
I seem to have everything required. My other extension is not picking up the method...so must be missing something.
Also, given i am getting no shipping options on frontend...confusing.
I was creating a complex shipping method...rather than a copy of the free shipping method. Turns out i actually needed a copy of the free shipping method, so made my life easier...
This was easier than i thought it would be.
Dont want to post all my code (you will also need a config.xml and system.xml file) but heres my carrier model logic file:
class Myco_Clickcollectshipping_Model_Carrier_Mymethod extends Mage_Shipping_Model_Carrier_Abstract {
protected $_code = 'mymethod ';
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getFreeShipping() && !$item->getProduct()->isVirtual()) {
$freeBoxes+=$item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') { // per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') { // per item
$shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
} else {
$shippingPrice = false;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('mymethod ');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('mymethod ');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
public function getAllowedMethods()
{
return array('mymethod ' => $this->getConfigData('name'));
}
}
I'm trying to get some custom routing going on in Magento using the following code (which I've only slightly modified from here https://stackoverflow.com/a/4158571/1069232):
class Company_Modulename_Controller_Router extends Mage_Core_Controller_Varien_Router_Standard {
public function match(Zend_Controller_Request_Http $request){
$path = explode('/', trim($request->getPathInfo(), '/'));
// If path doesn't match your module requirements
if ($path[1] == 'home.html' || (count($path) > 2 && $path[0] != 'portfolios')) {
return false;
}
// Define initial values for controller initialization
$module = $path[0];
$realModule = 'Company_Modulename';
$controller = 'index';
$action = 'index';
$controllerClassName = $this->_validateControllerClassName(
$realModule,
$controller
);
// If controller was not found
if (!$controllerClassName) {
return false;
}
// Instantiate controller class
$controllerInstance = Mage::getControllerInstance(
$controllerClassName,
$request,
$this->getFront()->getResponse()
);
// If action is not found
if (!$controllerInstance->hasAction($action)) {
return false;
}
// Set request data
$request->setModuleName($module);
$request->setControllerName($controller);
$request->setActionName($action);
$request->setControllerModule($realModule);
// Set your custom request parameter
$request->setParam('url_path', $path[1]);
// dispatch action
$request->setDispatched(true);
$controllerInstance->dispatch($action);
// Indicate that our route was dispatched
return true;
}
}
The result is a page where the template has loaded but with no content. If I comment out the $this->loadLayout() / $this->renderLayout() in my controller I can print to screen. But when I try and load a Template and/or Block it breaks somewhere.
home.html also loads fine (as the method returns false if the path is home.html).
Any assistance would be greatly appreciated.
I was implementing something similar to this and came across the same problem(That makes sense, because I copypasted your code)
before $request->setDispatched(true);
I added $request->setRouteName('brands'); (brands is the frontname of my module).
And It worked.Don't know if It'll work for you, but definetely there was something missing so that magento didn't know what layout to apply, because I could tell that teh controller was being reached.
I want to show all bundles on a simple product's page and so need to retrieve the information. I searched and tried a lot. This post sounds promising, but is either not working or maybe not for my problem:
Magento - get a list of bundled product ids from a product id
I found a solution for grouped products but this can't be applied here.
$grouped_product_model = Mage::getModel('bundle/product_selection');
$groupedParentId = $grouped_product_model->getParentIdsByChild($product->getId());
I found the table catalog_product_bundle_selection to be the right place to search, but I wonder if there is a clean way and existing function to search this table by product_id than just to hack this.
I didn't find a solution in Mage_Bundle.
What did I miss?
After getting first aid from vrnet I wrote a new block class, so I can update the layout
class Thomaier_Catalog_Block_Product_View_BundledSelect extends Mage_Catalog_Block_Product_View
{
protected $_simpleProducts = array( '3' ); // just an example
public function getBundles() {
$bundleIds = array();
$bundlesCollectionModel = Mage::getResourceModel('bundle/selection_collection');
$bundlesCollection = $bundlesCollectionModel->getSelect()
->where('`selection`.`product_id` in (' . join(',', (array)$this->_simpleProducts) . ')');
foreach ($bundlesCollection as $bundleItem) {
$bundleIds[] = $bundleItem->getParentProductId();
}
...
}
}
I skipped some parts. As I mentioned in the comment, the SQL query works fine when I try it in phpmyadmin, but $bundleItem is not created and ->load() throws an exception.
Thanks for advice.
Below is a method I wrote for a client having the same request with an extra : the ability to shuffle the result.
Hope it helps.
protected $_simpleProducts = array(); // Array with IDs of simple products you want bundles from.
protected $_shuffle = false;
public function getBundles() {
$bundleIds = array();
/*Rather than using a collection model
and make operations with getSelect,
a more elegant way is to extend
Mage_Bundle_Model_Mysql4_Selection_Collection
with a method that would be something like
setProductIdsFilter($productIds)*/
$bundlesCollectionModel = Mage::getResourceModel('bundle/selection_collection');
$bundlesCollection = $bundleCollectionModel->getSelect()
->where('`selection`.`product_id` in (' . join(',', (array)$this->_simpleProducts) . ')');
foreach ($bundlesCollection as $bundleItem) {
$bundleIds[] = $bundleItem->getParentProductId();
}
if (count($bundleIds)) {
$allowBundles = Mage::getResourceModel('catalog/product_collection')
->addIdFilter($bundleIds)
->addFieldToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
if ($this->_shuffle) {
$allowBundles->getSelect()->order('rand()');
}
if ($allowBundles->count()) {
return $allowBundles;
}
}
return;
The following is the best way to work with these. This way you do not rely on a custom query but instead you can use the core methods:
$bundlesCollection = Mage::getResourceModel('bundle/selection')
->getParentIdsByChild($simple_product_ids_array_or_int);
foreach ($bundlesCollection as $bundleProdId) {
//do anything you want with the bundleProdId array elements
}