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

时间:2015-06-05 15:33:43

标签: php magento magento-1.9

我遇到麻烦让我的redirectURL抓取我的IndexController中的当前URL。我写了一些非常相似的内容来抓取当前的产品网址,但这是针对该类别的。有人可以解释一下我做错了吗?

<?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 个答案:

没有答案