从JSON中删除连字符
我在OWEBIA Shipping 2.0中使用此JSON代码在我的magento商店上创建一个Shipping方法:从JSON中删除连字符,json,string,magento,Json,String,Magento,我在OWEBIA Shipping 2.0中使用此JSON代码在我的magento商店上创建一个Shipping方法: { "demo": { "label": "3 dias úteis", "conditions": "({cart.price+tax+discount} > 59.89) && ({shipto.postcode} > 88000000) && ({shipto.postcode} < 88
{ "demo": { "label": "3 dias úteis", "conditions":
"({cart.price+tax+discount} > 59.89) && ({shipto.postcode} > 88000000)
&& ({shipto.postcode} < 88124999)", "fees": 10, "customer_groups":
"3" } }
{“demo”:{“label”:“3 diasúteis”,“conditions”:
“({cart.price+tax+折扣}>59.89)&({shipto.postcode}>88000000)
&&({shipto.postcode}<88124999)”,“费用”:10,“客户群体”:
"3" } }
它工作正常,但巴西邮政编码使用连字符!
就像这个xxxxx-xxx
如何从用户在字段中插入的字符串中删除“-”?
非常感谢 只要我记得Magento是基于PHP的,那么您首先需要执行以下操作:
$response = json_decode($json_response); // this will convert the json object into php array;
然后,为了避免删除所有hypens(如果您在其他任何地方需要它们),请搜索带有邮政编码的属性并执行以下操作:
$postcode_without_hyphens = str_replace('-','', $response->post_code); //example
问候!如果您需要任何进一步的帮助或解释,请告诉我!:) 太晚了
我也有同样的问题。但通过检查Owebia代码,我找到了解决方案
解决方案是添加一个验证器,以便只允许邮政编码中的数字:
文件:app/code/community/Owebia/Shipping2/Model/ConfigParser.php第152行
更改此功能:
protected function _extract($data, $attributes)
{
$extract = array();
foreach ($attributes as $to => $from) {
$extract[$to] = isset($data[$from]) ? $data[$from] : null;
}
return $extract;
}
为此:
protected function _extract($data, $attributes)
{
$extract = array();
foreach ($attributes as $to => $from) {
// Here we validate the info, check if the current attribute is the postcode
if($from == "dest_postcode"){
//So we use preg_replace to allow only digits
$data[$from] = preg_replace('/\D/', '', $data[$from]);
}
$extract[$to] = isset($data[$from]) ? $data[$from] : null;
}
return $extract;
}
非常感谢你的回答!我想我不能使用PHP。请看一看这张图片:JSON代码有一个特定的输入字段。这意味着你必须按照我在用户输入其post代码的表单中所写的操作:)。就这么简单。从表单中读取post数据并删除其中的连字符。是的,您可以使用php,因为Magento只在php上编写。祝你好运!:)我会花上几天的时间!还有别的办法吗?要插入到我显示的框中的代码?:Dyou可以在配置文件页面或配送的提交页面上应用我的方法。换句话说,当你在计算完成之前发送信息时。我明白了!我真的很感谢你的帮助。但我不是一个开发者,只是一个商人:)这就是为什么我要花很多时间!哈哈哈