0

我尝试使用以下链接以编程方式创建订单:http: //pastebin.com/8cft4d8v#。问题是:保存报价后,如何重定向到结帐/单页/保存订单?我尝试重定向,但它显示“访问网页被拒绝”;

这是我的代码:

$productid = Mage::app()->getRequest()->getParam('value');
        $payment = Mage::app()->getRequest()->getParam('payment');
        $session = Mage::getSingleton('customer/session');
        if(!$session->isLoggedIn())
        {
            //login
            $username = Mage::app()->getRequest()->getParam('username');
            $password = Mage::app()->getRequest()->getParam('password');
            try
            {
                $result = $session->login($username,$password);
            }
            catch(Mage_Core_Exception $e)
            {
                $response['status'] = 0;
                $response['message'] = $e->getMessage();
                echo Zend_Json::encode($response);
                return false;
            }

            $session->setCustomerAsLoggedIn($session->getCustomer());
        }
        $cust_id = $session->getId();

        $customer = Mage::getModel('customer/customer')->load($cust_id);

        $quote = Mage::getModel('sales/quote')
                ->setStoreId(Mage::app()->getStore('default')->getId());

        $quote->assignCustomer($customer);

        // add product(s)
        $product = Mage::getModel('catalog/product')->load($productid);
        $buyInfo = array(
                'qty' => 1,
        );
        $quote->addProduct($product, new Varien_Object($buyInfo));

        $billing = $customer->getDefaultBillingAddress();
        $addressData = array(
                'firstname' => $billing->getFirstname(),
                'lastname' => $billing->getLastname(),
                'street' => $billing->getStreet(),
                'city' => $billing->getCity(),
                'postcode' => $billing->getPostcode(),
                'telephone' => $billing->getTelephone(),
                'country_id' => $billing->getCountryId(),
                'region_id' => $billing->getRegionId());

        $billingAddress = $quote->getBillingAddress()->addData($addressData);

        $quote->getPayment()->importData(array('method' => $payment));

        $quote->collectTotals()->save();

        $response['status'] = 1;
        echo Zend_Json::encode($response);
4

1 回答 1

0

以编程方式创建订单后,您可以重定向到订单成功页面。为什么你想去订单保存页面。保存报价后即可保存订单。使用 $this->_redirect 进行重定向

于 2013-09-19T10:47:02.363 回答