Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在magento onepage签出过程中添加驱动程序提示?_Php_Magento_Checkout - Fatal编程技术网

Php 如何在magento onepage签出过程中添加驱动程序提示?

Php 如何在magento onepage签出过程中添加驱动程序提示?,php,magento,checkout,Php,Magento,Checkout,目前,我需要在magento onepage签出过程中添加一个自定义驱动程序提示步骤,就在发货方法(步骤3)之后,我希望用户从一些给定选项(我将制作单选按钮)中选择包含一定数量的提示,假设用户选择150美元,那么该金额将添加到总付款中?我在谷歌上尝试了所有其他教程,没有一个对我有用,非常感谢任何帮助,我最近也在研究类似的需求。 所以请按照我的指示:- 我要求你不要关注答案的长度,只关注结果 步骤1:-如果要将驱动程序提示置于装运和装运方法之间,请首先打开 \app\code\core\Mage\

目前,我需要在magento onepage签出过程中添加一个自定义驱动程序提示步骤,就在发货方法(步骤3)之后,我希望用户从一些给定选项(我将制作单选按钮)中选择包含一定数量的提示,假设用户选择150美元,那么该金额将添加到总付款中?我在谷歌上尝试了所有其他教程,没有一个对我有用,非常感谢任何帮助,

我最近也在研究类似的需求。 所以请按照我的指示:-

我要求你不要关注答案的长度,只关注结果

步骤1:-如果要将驱动程序提示置于装运和装运方法之间,请首先打开

\app\code\core\Mage\Checkout\Block\Onepage.php 有一个数组$stepCodes(行号:-44)。 换成这个

$stepCodes = array('billing', 'shipping', 'excellence2','shipping_method', 'payment', 'review'); 
我使用的是卓越2您也可以使用此名称

步骤2:- 现在我们需要在app\code\core\Mage\Checkout\Block\Onepage上创建Excellence2类\ 因此,创建一个新的php文件并将代码放入其中,另存为Excellence2.php

class Mage_Checkout_Block_Onepage_Excellence2 extends Mage_Checkout_Block_Onepage_Abstract
{
protected function _construct()
{
    $this->getCheckout()->setStepData('excellence2', array(
        'label'     => Mage::helper('checkout')->__('Tip Ammount'),
        'is_show'   => $this->isShow()
    ));
    parent::_construct();

}
}
注意:-现在您可以在_construct()函数的标签上添加任何名称,因此将'Tip amount'更改为驱动程序提示

步骤3:-现在打开位于app\code\core\Mage\Checkout\controllers\中的OnepageController.php,找到saveBillingAction()函数(行号:-296),并用该函数替换该代码

 public function saveBillingAction()
{       
    if ($this->_expireAjax())
      {
        return;
      }
    if ($this->getRequest()->isPost()) {
        //            $postData = $this->getRequest()->getPost('billing', array());
        //            $data = $this->_filterPostData($postData);
        $data = $this->getRequest()->getPost('billing', array());
        $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);

        if (isset($data['email'])) {
            $data['email'] = trim($data['email']);
        }
        $result = $this->getOnepage()->saveBilling($data, $customerAddressId);

        if (!isset($result['error'])) {
            /* check quote for virtual */
            if ($this->getOnepage()->getQuote()->isVirtual()) {
                $result['goto_section'] = 'payment';
                $result['update_section'] = array(
                    'name' => 'payment-method',
                    'html' => $this->_getPaymentMethodsHtml()
                );
            } elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
                $result['goto_section'] = 'excellence2';  //Goes to our step
                $result['allow_sections'] = array('shipping');
                $result['duplicateBillingInfo'] = 'true';
            } else {
                $result['goto_section'] = 'shipping';
            }
        }

        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}
步骤4:-同样在同一个文件OnepageController.php中有一个saveShippingAction()函数(第331行)将其更改为

 public function saveShippingAction()
 {
    if ($this->_expireAjax()) {
        return;
    }
    if ($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost('shipping', array());
        $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
        $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

        if (!isset($result['error'])) {
            $result['goto_section'] = 'excellence2'; //Go to our step
        }
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
  }
此代码告诉用户,当用户通过发货步骤时,他将转到我们的驾驶员提示步骤

步骤5:-同样在同一个文件(OnepageController.php)中,我们需要告诉用户在通过驱动程序提示后将重定向到哪里。因此,在saveShippingAction()函数之后创建一个saveExcellence2Action()

public function saveExcellence2Action()
{
    if ($this->_expireAjax()) {
        return;
    }
    if ($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost('excellence2', array());

        $result = $this->getOnepage()->saveExcellence2($data);

        if (!isset($result['error'])) {
            $result['goto_section'] = 'shipping_method';
            $result['update_section'] = array(
                'name' => 'shipping-method',
                'html' => $this->_getShippingMethodsHtml()
            );
        }

        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}
步骤6:-现在我们更改位于中的checkout.xml

\app\design\frontend\default\your template\layour打开它并查找

<checkout_onepage_index translate="label">
步骤9:-现在我们需要创建一个新函数来保存所选用户的数据。 因此,我们在Onepage.php中的saveShipping($data,$customerAddressId)finction之后创建了一个名为saveExcellence2()的新函数,该函数位于\app\code\core\Mage\Checkout\Model\Type中\

public function saveExcellence2($data)
{
    if (empty($data)) 
    {
        return array('error' => -1, 'message' => $this->_helper->__('Invalid data.'));
    }
    $this->getQuote()->setExcellenceLike2($data['like']);
    $this->getQuote()->collectTotals();
    $this->getQuote()->save();

    $this->getCheckout()

    ->setStepData('excellence2', 'complete', true)
    ->setStepData('shipping_method', 'allow', true);

    return array();
}

默认情况下,magento提供一些签出步骤。但有时您需要添加来自客户的额外信息以供将来参考。一个常见的定制请求是在默认签出过程中添加定制表单。 这不是接触核心文件的好做法。您可以通过覆盖模块来实现这一点。 在本例中,Comapnyname为IPFragmatech,模块名称为Checkoutstep

步骤1:在签出过程中添加自定义步骤

打开ipfragmatech>Checkoutstep>Block>Onepage>Checkoutstep.php文件并编写以下代码

    class Ipragmatech_Checkoutstep_Block_Onepage_Checkoutstep extends Mage_Checkout_Block_Onepage_Abstract
    {
       protected function _construct()
       {     
          $this->getCheckout()->setStepData('checkoutstep', array(
          'label'     => Mage::helper('checkout')->__('Invitation to participation'),
          'is_show'   => true
        ));
        parent::_construct();
       }
     }
    class Ipragmatech_Checkoutstep_Block_Onepage extends Mage_Checkout_Block_Onepage
    {
      public function getSteps()
      {
             $steps = array();

             if (!$this->isCustomerLoggedIn()) {
                $steps['login'] = $this->getCheckout()->getStepData('login');
             }

            $stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'checkoutstep', 'review');
         foreach ($stepCodes as $step) {
             $steps[$step] = $this->getCheckout()->getStepData($step);
          }

    return $steps;
   }
}
步骤2:在结账过程中添加您想要的步骤和位置

打开ipfragmatech>Checkoutstep>Block>Onepage>Checkoutstep.php文件并编写以下代码

    class Ipragmatech_Checkoutstep_Block_Onepage_Checkoutstep extends Mage_Checkout_Block_Onepage_Abstract
    {
       protected function _construct()
       {     
          $this->getCheckout()->setStepData('checkoutstep', array(
          'label'     => Mage::helper('checkout')->__('Invitation to participation'),
          'is_show'   => true
        ));
        parent::_construct();
       }
     }
    class Ipragmatech_Checkoutstep_Block_Onepage extends Mage_Checkout_Block_Onepage
    {
      public function getSteps()
      {
             $steps = array();

             if (!$this->isCustomerLoggedIn()) {
                $steps['login'] = $this->getCheckout()->getStepData('login');
             }

            $stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'checkoutstep', 'review');
         foreach ($stepCodes as $step) {
             $steps[$step] = $this->getCheckout()->getStepData($step);
          }

    return $steps;
   }
}
步骤三:抓取自定义表单提交值,设置自定义表单值

打开ipfragmatech>Checkoutstep>controllers>OnepageController.php并编写以下函数

    public function saveCheckoutstepAction()
    {
      $this->_expireAjax();
      if ($this->getRequest()->isPost()) {

     //Grab the submited value 
     $_entrant_name = $this->getRequest()->getPost('entrant_name',"");
     $_entrant_phone = $this->getRequest()->getPost('entrant_phone',"");
     $_entrant_email = $this->getRequest()->getPost('entrant_email',"");
     $_permanent_address = $this->getRequest() ->getPost('permanent_address',"");
     $_address = $this->getRequest()->getPost('local_address',"");

     Mage::getSingleton('core/session') ->setIpragmatechCheckoutstep(serialize(array(
    'entrant_name' =>$_entrant_name,
    'entrant_phone' =>$_entrant_phone,
    'entrant_email' =>$_entrant_email,
    'permanent_address' =>$_permanent_address,
    'address' =>$_address
     )));

    $result = array();
    $redirectUrl = $this->getOnePage()->getQuote()->getPayment() ->getCheckoutRedirectUrl();
        if (!$redirectUrl) {
            $this->loadLayout('checkout_onepage_review');
            $result['goto_section'] = 'review';
            $result['update_section'] = array(
                'name' => 'review',
                'html' => $this->_getReviewHtml()
            );

        }

        if ($redirectUrl) {
            $result['redirect'] = $redirectUrl;
        }

        $this->getResponse()->setBody(Zend_Json::encode($result));
    }
}
步骤4:保存自定义表单信息

签出时\u onepage\u控制器\u成功\u操作 事件挂钩被称为。打开ipfragmatech>Checkoutstep>Model>Observer.php并编写以下代码

    class Ipragmatech_Checkoutstep_Model_Observer {
      const ORDER_ATTRIBUTE_FHC_ID = 'checkoutstep';
      public function hookToOrderSaveEvent() {
      if (Mage::helper('checkoutstep')->isEnabled()) {
         $order = new Mage_Sales_Model_Order ();
         $incrementId = Mage::getSingleton ( 'checkout/session' )->getLastRealOrderId ();
         $order->loadByIncrementId ( $incrementId );

       // Fetch the data 
       $_checkoutstep_data = null;
       $_checkoutstep_data = Mage::getSingleton ( 'core/session' )->getIpragmatechCheckoutstep ();
       $model = Mage::getModel ( 'checkoutstep/customerdata' )->setData ( unserialize ( $_checkoutstep_data ) );
       $model->setData ( "order_id",$order["entity_id"] );
       try {
           $insertId = $model->save ()->getId ();
             Mage::log ( "Data successfully inserted. Insert ID: " . $insertId, null, 'mylog.log');
        } catch ( Exception $e ) {
            Mage::log ( "EXCEPTION " . $e->getMessage (), null, 'mylog.log' );
          }
        }
    }
}

Magento–在结帐扩展中添加自定义表单是为您的电子商务网站在结帐过程中添加额外步骤的完整解决方案。它允许管理员以CSV格式从自定义表导出数据。
访问链接以获得此免费分机

非常好的回复!你知道这是否适用于1.7.0.2吗?我按照所有的指示做了,但不起作用。最后,我无法通过第一个结账步骤。你知道这在1.7.0.2中是否有效吗?我遵循了所有的步骤,但最终还是无法通过第一个结账步骤。
    public function saveCheckoutstepAction()
    {
      $this->_expireAjax();
      if ($this->getRequest()->isPost()) {

     //Grab the submited value 
     $_entrant_name = $this->getRequest()->getPost('entrant_name',"");
     $_entrant_phone = $this->getRequest()->getPost('entrant_phone',"");
     $_entrant_email = $this->getRequest()->getPost('entrant_email',"");
     $_permanent_address = $this->getRequest() ->getPost('permanent_address',"");
     $_address = $this->getRequest()->getPost('local_address',"");

     Mage::getSingleton('core/session') ->setIpragmatechCheckoutstep(serialize(array(
    'entrant_name' =>$_entrant_name,
    'entrant_phone' =>$_entrant_phone,
    'entrant_email' =>$_entrant_email,
    'permanent_address' =>$_permanent_address,
    'address' =>$_address
     )));

    $result = array();
    $redirectUrl = $this->getOnePage()->getQuote()->getPayment() ->getCheckoutRedirectUrl();
        if (!$redirectUrl) {
            $this->loadLayout('checkout_onepage_review');
            $result['goto_section'] = 'review';
            $result['update_section'] = array(
                'name' => 'review',
                'html' => $this->_getReviewHtml()
            );

        }

        if ($redirectUrl) {
            $result['redirect'] = $redirectUrl;
        }

        $this->getResponse()->setBody(Zend_Json::encode($result));
    }
}
    class Ipragmatech_Checkoutstep_Model_Observer {
      const ORDER_ATTRIBUTE_FHC_ID = 'checkoutstep';
      public function hookToOrderSaveEvent() {
      if (Mage::helper('checkoutstep')->isEnabled()) {
         $order = new Mage_Sales_Model_Order ();
         $incrementId = Mage::getSingleton ( 'checkout/session' )->getLastRealOrderId ();
         $order->loadByIncrementId ( $incrementId );

       // Fetch the data 
       $_checkoutstep_data = null;
       $_checkoutstep_data = Mage::getSingleton ( 'core/session' )->getIpragmatechCheckoutstep ();
       $model = Mage::getModel ( 'checkoutstep/customerdata' )->setData ( unserialize ( $_checkoutstep_data ) );
       $model->setData ( "order_id",$order["entity_id"] );
       try {
           $insertId = $model->save ()->getId ();
             Mage::log ( "Data successfully inserted. Insert ID: " . $insertId, null, 'mylog.log');
        } catch ( Exception $e ) {
            Mage::log ( "EXCEPTION " . $e->getMessage (), null, 'mylog.log' );
          }
        }
    }