Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在签出购物车Magento中上载文件_Php_Magento_File Upload_Checkout_Cart - Fatal编程技术网

Php 在签出购物车Magento中上载文件

Php 在签出购物车Magento中上载文件,php,magento,file-upload,checkout,cart,Php,Magento,File Upload,Checkout,Cart,我尝试使用$cart->addProduct($product,$request)将图像推送到结账车 如果我在普通产品中使用自定义选项,我的请求就是这样的 $_FILES: array(2) { ["options_76_file"] => array(5) { ["name"] => string(14) "Conference.jpg" ["type"] => string(10) "image/jpeg" ["tmp_name"] =&

我尝试使用$cart->addProduct($product,$request)将图像推送到结账车

如果我在普通产品中使用自定义选项,我的请求就是这样的

  $_FILES:
  array(2) {
  ["options_76_file"] => array(5) {
    ["name"] => string(14) "Conference.jpg"
    ["type"] => string(10) "image/jpeg"
    ["tmp_name"] => string(14) "/tmp/phpkKRgHA"
    ["error"] => int(0)
    ["size"] => int(938613)
  }
  ["options_80_file"] => array(5) {
    ["name"] => string(16) "capra-felice.jpg"
    ["type"] => string(10) "image/jpeg"
    ["tmp_name"] => string(14) "/tmp/php8SXzIk"
    ["error"] => int(0)
    ["size"] => int(93196)
  }
}

Request:
array(7) {
  ["uenc"] => string(76) "aHR0cDovL2Rldi5rd2lrd2ViLmNvbS5hdS9uc2ovYWNjZXNzc29yaWVzL3NpbmdsZXQuaHRtbA,,"
  ["product"] => string(2) "22"
  ["related_product"] => string(0) ""
  ["options_76_file_action"] => string(8) "save_new"
  ["options"] => array(1) {
    [77] => string(3) "251"
  }
  ["options_80_file_action"] => string(8) "save_new"
  ["qty"] => string(1) "1"
}
正如你可能已经注意到的,我正在传递两张图片。 现在,我正在尝试从我的自定义控制器中执行相同的操作。我设法将产品添加到购物车,但找不到负责将文件保存到订单的功能。 有人知道Magento是怎么处理的吗? 谢谢
Soipo

我在博客上找到了这段代码

// the path of the file, relative to Magento base directory.
// For example /media/image.jpg
$image = "YOURFILE.JPG";
// the ID of the product
$product_id = XXX;

$product = Mage::getModel('catalog/product')->load($product_id);

$cart = Mage::getModel('checkout/cart');
$cart->init();
$params = array(
'product' => $product_id,
'qty' => 1,
'options' => array(
12345 => array(
'quote_path' => $image,
'secret_key' => substr(md5(file_get_contents(Mage::getBaseDir() . $image)), 0, 20)),
)
);

$cart->addProduct($product, $params);
$cart->save();

Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
为此,请确保阵列如下所示:

$title= $option['name'];
                $image = DS."media".DS."logos".DS.$title;
                $path = Mage::getBaseDir().$image;

                $imgSize = getimagesize($path);
                $size =  filesize($path);

                $array = array(
                'type' => "application/octet-stream",
                'title' => $title,
                'size' => $size ,
                'width' => $imgSize[0],
                'height' => $imgSize[1],
                'quote_path'=> $image, 
                'order_path'=> $image, 

                'secret_key' => substr(md5(file_get_contents($path)), 0, 20));

                $options[$key] = $array;

本机magento中没有在保存订单过程中保存文件的功能。您必须使用普通的php函数/code处理您的文件。嗨,OSdave,我成功地保存了我的文件,没有问题,但我无法在选项中保存名称。因此,该图像将不会在签出时显示,而将显示在订单概览中。