2015-11-02 70 views
1

我有一个脚本,它增加了一个产品在购物车中自定义选项图像,它工作完美,直到CE 1.9.2.1,但后渐变到最新版本它槽异常那Please specify the product's required option(s).magento 1.9.2.2添加到购物车与自定义选项图像不起作用

以下是代码,请指导我如果有什么需要改变为较新的版本。

<?php 
    $productId = xxx; 
    $image = 'path to image(tested image exists)'; 
    $product = Mage::getModel('catalog/product')->load($product_id); 
    $cart = Mage::getModel('checkout/cart'); 
    $cart->init(); 
    $params = array(
     'product' => $productId, 
     'qty' => 1, 
     'options' => array(
      $optionId3inmycase => array(
       'type' => 'image/tiff', 
       'title' => $image, 
       'quote_path' => '/media/custom/' . $image, 
       'order_path' => '/media/custom/' . $image, 
       'fullpath' => Mage::getBaseDir() . '/media/custom/' . $image, 
       'secret_key' => substr(md5(file_get_contents(Mage::getBaseDir() . '/media/custom/' . $image)), 0, 20)), 
     ) 
    ); 
    $request = new Varien_Object(); 
    $request->setData($params); 
    $cart->addProduct($product, $request); 
    $cart->save(); 
    if ($itemId > 0) { 
     $cartHelper = Mage::helper('checkout/cart'); 
     $cartHelper->getCart()->removeItem($itemId)->save(); 
    } 
    Mage::getSingleton('checkout/session')->setCartWasUpdated(true); 
    $this->_redirect('checkout/cart/'); 
?> 
+0

我认为这是因为新补丁http://screencloud.net/v/Fw1n –

回答

1

一个快速的解决方案是重写Mage_Catalog_Model_Product_Option_Type_File类,并改变validateUserValue()功能。

左右线129,与

$fileInfo = null; 
    if (isset($values[$option->getId()]) && is_array($values[$option->getId()])) { 
     // Legacy style, file info comes in array with option id index 
     $fileInfo = $values[$option->getId()]; 
    } else { 
     /* 
     * New recommended style - file info comes in request processing parameters and we 
     * sure that this file info originates from Magento, not from manually formed POST request 
     */ 
     $fileInfo = $this->_getCurrentConfigFileInfo(); 
    } 

但它的旧代码替换

$fileInfo = $this->_getCurrentConfigFileInfo(); 

,将有APPSEC-1079安全问题。

并下载图像这张上传的图像的详细信息等添加此功能在同一模型类。

/** 
* changed the image save address as we are saving image in custom 
* Main Destination directory 
* 
* @param boolean $relative If true - returns relative path to the webroot 
* @return string 
*/ 
public function getTargetDir($relative = false) 
{ 
    $fullPath = Mage::getBaseDir('media') . DS . 'custom'; 
    return $relative ? str_replace(Mage::getBaseDir(), '', $fullPath) : $fullPath; 
} 
相关问题