dtbiszu7724 2016-04-04 15:25
浏览 77
已采纳

在前端和后端(以及电子邮件)上解码产品自定义

I've got a prestashop setup that has a small 'customization form' that currently saves the information to the products default customization text input. I did this to save time on having to write a complete custom module to add additional customization form fields and such.

Currently all the inputs are serialized (json) and entered as a long string into the text input like this:

Client Customization: %5B%5B%7B%22name%22%3A%22trophy%5B1%5D%5Bline1%5D%22%2C%22engraving%22%3A%22Test%20Trophy%22%7D%2C%7B%22name%22%3A%22trophy%5B1%5D%5Bline2%5D%22%2C%22engraving%22%3A%22test%20trophy%22%7D%2C%7B%22name%22%3A%22trophy%5B1%5D%5Bline3%5D%22%2C%22engraving%22%3A%221111111%22%7D%5D%5D

On the front end - when the customized data is displayed I can use PHP to decode & display it appropriately.

Is there a way where I can change that globally somewhere so I don't have to try and find every place where it might display and add that PHP code?

I'm running into the issue that I can't seem to find where to add the PHP code to 'decode' that string for the emails that are being sent out - so the long ugly string is being seen instead of the nice few lines of customization the user entered.

Any thoughts on how to handle this? Is there a spot where I can globally assign the decoded string to the products customization?

  • 写回答

1条回答 默认 最新

  • douhuang2218 2016-04-05 09:32
    关注

    You could either try the PaymentModule class to decode the string just before the emails are sent, or Product's method called "getAllCustomizedDatas" for a more "global" approach. And then test a lot, of course :)

    Here's a quick draft of the second approach:

    <?php
    class Product extends ProductCore
    {
        public static function getAllCustomizedDatas($id_cart, $id_lang = null, $only_in_cart = true, $id_shop = null)
        {
            $datas = parent::getAllCustomizedDatas($id_cart, $id_lang, $only_in_cart, $id_shop);
    
            /*
             * Iterate over $datas, you're looking for
             * [id_product][id_product_attribute][id_address_delivery][id_customization][datas]
             * Datas will contain an array of fields broken by their type. You can then decode
             * the ones that need to be decoded and return the result:
             */
    
            return $datas;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。
  • ¥15 抖音看过的视频,缓存在哪个文件