0

このリンクを使用してプログラムで注文を作成してみます: http://pastebin.com/8cft4d8v#。問題は、見積もりを保存した後、checkout/onepage/saveorder にリダイレクトする方法です。リダイレクトを試みましたが、「Web ページへのアクセスが拒否されました」と表示されました。

これが私のコードです:

$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