我怎么能得到item_size在一个php变量后sendform checkout在simplecart-js

How can I get item_size in a php var after a sendform checkout in simplecart-js?

本文关键字:php 一个 变量 simplecart-js checkout sendform 怎么能 item size      更新时间:2023-09-26

我是一个真正的javascript新手,我找不到自己的解决方案…我想在一些php变量sendform checkout后得到我的项目的大小。

背景:
1 -我有一个产品页面,客户可以选择尺寸和数量,并将产品添加到篮子中。
2 -结帐页面,有拇指,数量,尺寸,价格等,并通过sendform验证(我在结帐页面上没有任何表单,它只是用于获取php中的所有项目变量)
3 -一个在php中返回所有项目的页面,(客户必须为每个项目上传图片):

$content = $_POST;
$item_number = array(); // compteur d items
$item = array(); // tableaux qui récupere les valeurs de chaque items
for($i=1; $i < $content['itemCount'] + 1; $i++) 
{
$name = 'item_name_'.$i;
$quantity = 'item_quantity_'.$i;
$price = 'item_price_'.$i;
$thumb = 'item_thumb_'.$i;
$id = 'item_id_'.$i;
$size = 'item_size_'.$i;
$item_number['total'] = $i;
$item[$i]['name'] = $content[$name];
$item[$i]['quantity'] = $content[$quantity];
$item[$i]['price'] = $content[$price];
$item[$i]['thumb'] = $content[$thumb];
$item[$i]['id'] = $content[$id];
$item[$i]['size'] = $content[$size];
}
$total = $item_number['total'];
$line = 0;
while ($line <= $total -1) 
{
$line++;
echo $item[$line]['name'];
    echo $item[$line]['size'];
}?>

一切似乎都很好,除了尺寸…在项目页面上,我只是使用"item_size"类的大小选择表单,其正确显示在结帐页面上,但…第三页什么也没有…

有谁能帮我这个忙吗?编辑:我已经找到了解决方案,如果有人在我之后想知道这个问题:
添加到项的自定义类属性,在本例中为
class="item_size"

存储在名为

的javascript数组中
item_options

所以你必须得到item_option在一个php变量和分割字符链与一个爆炸函数:

$content = $_POST;
$item_number = array(); // compteur d items
$item = array(); // tableaux qui récupere les valeurs de chaque items
for($i=1; $i < $content['itemCount'] + 1; $i++) 
{
  //I passed two params in item_options, the size and a path to an picture
  $options = 'item_options_'.$i; //let s get the name of the java var in a php var
  $item_number['total'] = $i; //let s count the number of items
  $item[$i]['options'] = $content[$options]; //let s get the values of item_options
}
$total = $item_number['total'];
$line = 0;
while ($line <= $total -1) 
{
$line++;
$split_options = explode(",", $item[$line]['options']); // explode the chain in few chains                                                  
$split_thumb = explode(":", $split_options[0]); // for each chain, cut the useless part before ":", for exemple thumbPath: ../pictures                                           
$split_size = explode(":", $split_options[1]);
echo $split_thumb[1]; // display the path of my thumb
echo $split_size[1]; // display the size of my item
}?>

您可以添加项目data["item_size_" + counter] = item.get("size");SendForm函数中的simplecart.js文件