douxiuyi6529 2015-06-05 15:33
浏览 29

Magento在索引控制器中获取类别URL

I am having troubles getting my redirectURL to grab the current URL inside of my IndexController. I have written something very similar that grabs the current product URL, but this is for the category. Can someone explain what I may have done wrong?

<?php
class Magestore_Categoryinquiry_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->_initLayoutMessages('catalog/session');
        $this->loadLayout();
        $this->renderLayout();
    }

    public function submitAction() {
        $data = $this->getRequest()->getPost();
        $error = false;
        if($data) {
            $category = Mage::getModel('catalog/category')->load($data['category_id']);
            try {   
                $postObject = new Varien_Object();
                $postObject->setData($data);

                $error = false;

                if (Mage::helper('categoryinquiry')->isRequireFname()) {
                    if (!Zend_Validate::is(trim($data['fname']) , 'NotEmpty')) {
                        $error = true;
                    }
                }
                if (Mage::helper('categoryinquiry')->isRequireLname()) {
                    if (!Zend_Validate::is(trim($data['lname']) , 'NotEmpty')) {
                        $error = true;
                    }
                }
                if (Mage::helper('categoryinquiry')->isRequireEmail()) {
                    if (!Zend_Validate::is(trim($data['customer_email']), 'EmailAddress')) {
                        $error = true;
                    }
                }
                if (Zend_Validate::is(trim($data['hideit']), 'NotEmpty')) {
                    $error = true;
                }
                if ($error) {
                    throw new Exception();
                }

                $model = Mage::getModel('categoryinquiry/categoryinquiry');
                $data['store_id']          = Mage::app()->getStore()->getId();
                $data['status']            = 1;
                $data['created_time']      = now();
                $data['updated_time']      = now();
                $data['category_name']     = $category->getName();

                $categoryinquiry = $this->getLayout()->createBlock('categoryinquiry/sendtocustomer')
                                        ->setInformation($data)
                                        ->setTemplate('categoryinquiry/email/sendtocustomer.phtml')
                                        ->toHtml(); 

                $customercontact = $this->getLayout()->createBlock('categoryinquiry/sendtoadmin')
                                        ->setInformation($data)
                                        ->setTemplate('categoryinquiry/email/sendtoadmin.phtml')
                                        ->toHtml();

                $model->setData($data)->save()
                        ->sendMailToCustomer($model, $categoryinquiry)
                        ->sendMailToAdmin($model, $customercontact)
                        ;
                Mage::getSingleton('catalog/session')->addSuccess(Mage::helper('categoryinquiry')->getSuccessMessage());
                $this->_redirectUrl($category->getCategoryUrl());
                return;

            } catch (Exception $e) {
                Mage::getSingleton('catalog/session')->addError(Mage::helper('categoryinquiry')->getErrorMessage());
                $this->_redirectUrl($category->getCategoryUrl());
                return;
            }
        }
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据