2015-11-02 61 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; 
} 
相關問題