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;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条