【问题标题】:Magento/PHP - redirect on submitMagento/PHP - 提交时重定向
【发布时间】:2011-06-28 15:48:35
【问题描述】:

我们有一个报价模块,它将提交报价请求然后重定向到某个页面。我们想返回产品页面,但尝试了一些方法后仍然无法正常工作。

下面的代码显示了报价的处理器,最后显示:$this->_redirect('Quotation/Quote/List/');

我在尝试获取 URL 方面尝试了几个想法,但目前还没有任何效果。

在处理产品 URL 并重定向到该页面而不是报价单/报价单/列表页面时,我需要添加什么内容?

    /**
     * Create a quote inquiry with cart's products
     *
     */
    public function CreateRequestAction()
    {
        $this->loadLayout();
        $this->renderLayout();              
    }

    /**
     * Create a quote inquiry with cart's products
     *
     */
    public function CreateIndividualRequestAction()
    {
        $this->loadLayout();
        $this->renderLayout();              
    }


    /**
     * Post a new quote request Individual
     *
     */
    public function SendIndividualRequestAction()
    {
        $CustomerId = mage::Helper('customer')->getCustomer()->getId();

        $storeId = mage::getModel('customer/customer')->load($CustomerId)->getStoreId();
        $defaultValidityDuration = Mage::getStoreConfig('quotation/general/default_validity_duration', $storeId);
        $defaultExpirationDate = time() + $defaultValidityDuration * 24 * 3600;

        //Create new quotation
        $NewQuotation = mage::getModel('Quotation/Quotation')
            ->setcustomer_id($CustomerId)
            ->setcaption($this->__('New request'))
            ->setcreated_time(date("Y/m/d"))
            ->setcustomer_msg($this->getRequest()->getPost('description'))
            ->setcustomer_request(1)
            ->setstatus(MDN_Quotation_Model_Quotation::STATUS_CUSTOMER_REQUEST)
            ->setvalid_end_time(date('Y/m/d', $defaultExpirationDate))
            ->save();
        $NewQuotation->setincrement_id($NewQuotation->GenerateIncrementId())->save();

        //Add selected product
        $product = mage::getModel('catalog/product')->load($this->getRequest()->getPost('product_id'));
        if ($product->getId())
        {
            //add product to quotation          
            $quotationItem = mage::getModel('Quotation/Quotationitem')
                ->setquotation_id($NewQuotation->getId())
                ->setorder(1)
                ->setproduct_id($product->getId())
                ->setqty(1)
                ->setprice_ht($product->getPrice())
                ->setcaption($product->getName())
                ->setsku($product->getSku())
                ->setcost($product->getCost())  
                ->setweight($product->getWeight())
                ->save();       

            //compute quotation price & weight
            $NewQuotation->CalculateWeight();
            $NewQuotation->CalculateQuotationPriceHt();
        }

        //Notify admin
        $NewQuotation->NotifyCreationToAdmin();


        //confirm

        $this->_redirect('Quotation/Quote/List/');
    }

【问题讨论】:

    标签: php url magento redirect


    【解决方案1】:

    _redirectReferer()代替_redirect()

    看起来_redirect()getUrl() 的工作方式相同(实际上,它是按原样使用的)。

    $this->_redirect('catalog/product/view', array(
        'id'=>$product->getId(),
        '_use_rewrite'=>true
    ));
    

    注意:由于可以识别产品的方式,这将重定向到 URL 中没有类别的页面。如果您知道从中选择/提交产品的类别 ID,则将其作为 category 包含在数组中。

    【讨论】:

    • 不幸的是,这似乎不起作用,它只是返回到报价请求页面。我们需要它返回到报价页面之前的产品页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多