如何在洋红色中添加密码?它是否需要任何扩展包


How to add pincodes in magento? does it need any extension packs?

这个问题似乎不符合规则,但需要专家的帮助。

我不是一个有经验的Magento - 开发人员,所以我们与另一个开发人员签署了我们新的电子商务网站的协议,

我来自印度和我都有各州的所有密码列表。我有php开发的经验,但没有Magento的经验。

我的要求是将PIN码添加到我们的网站以进行通常的COD可用性检查,当我联系开发人员时,他们说他们需要一个扩展包来实现这一点。 这是正确的方法吗?

我想知道为什么无法检查用户输入的 PIN 码是我们在 COD 列表中拥有的 pin代码(考虑一般编程(,等待专家的回复

我不确定这是否是完美的解决方案,但这就是我的做法。

首先为 COD 密码列表的数据库表创建一个模块。这是我在创建此模块 http://alanstorm.com/magento_models_orm 引用的文章。

现在你必须创建另一个模块来执行 Ajax 调用。我不记得我提到的创建此模块的文章,因此将分享我的模块详细信息。让我们调用模块 AjaxBlock。要了解如何在Magento中创建自定义模块,请参阅此链接 http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table

AjaxBlock 模块的文件列表:

  1. 应用程序/etc/模块/Namespace_AjaxBlock.xml
  2. app/code/local/Namespace/AjaxBlock/etc/config.xml
  3. app/code/local/Namespace/AjaxBlock/controllers/IndexController.php

config.xml内容

<frontend>
        <routers>
          <ajaxblock>
            <use>standard</use>
            <args>
              <module>Namespace_AjaxBlock</module>
              <frontName>ajaxblock</frontName>
            </args>
          </ajaxblock>
        </routers>  
    </frontend>

这就是IndexController.php的样子

class Namespace_AjaxBlock_IndexController extends Mage_Core_Controller_Front_Action {
    public function indexAction() {
        $pinCode=$_POST['pincodeValue']; // pincode entered by the user
        // Validation for pin code
        if (!preg_match("/^'d{6}$/i",$pinCode)){
            //Validation failed, provided zip/postal code is not valid.
            $result="Please enter a valid pincode.";
        }else{
            //Validation passed, provided zip/postal code is valid.
            // This is model for COD pincode database table, change it to your resource model name. This filters the table with the pincode entered by the user
            $model = Mage::getModel('<module>/<module>')->getCollection()->addFieldToFilter('pincode', $pinCode);
            if(empty($model)){ // the collection will be empty if the pincode entered by the user is not present in the database table
                $result="COD not available";
            }else{
                $result="COD available";
            }
        }
        $this->getResponse()->setBody($result);
    }
}

我想要产品页面中的密码检查器。所以我在产品页面 phtml 文件中添加了以下代码。您可以在要显示 PIN 码检查器的位置添加此代码。

<div class="pincode-check">
    <p class="pincode-title">Check Cash on delivery availability</p>
    <input type="text" name="pin" id="pin-input" placeholder ="Enter your pincode" />
    <button id="submit-pin">Check</button>
    <p id="message"></p>
</div>
    <!-- Ajax Block-->
    <script type="text/javascript">
        var pincodeValue = $j( "#pin-input" ).val();
        $j( "#submit-pin" ).click(function(){
            pincodeValue = $j( "#pin-input" ).val();
            $j('#message').hide();
            // alert(pincodeValue);
            $j.ajax({
                url: "<?php echo $this->getUrl('ajaxblock/index/index') ?>",
                type: "POST",
                data: {
                pincodeValue:pincodeValue,},
            success: function(data) {
                $j('#message').show();
                $j('#message').html(data);
                },
            error: function(MLHttpRequest, textStatus, errorThrown){
                alert(errorThrown);
                }
            });   
        });       
    </script>
相关文章: