可下载产品:以编程方式将文件链接添加到可下载产品 [英] Downloadable product : add file links to downloadable product programmatically

查看:73
本文介绍了可下载产品:以编程方式将文件链接添加到可下载产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式添加指向可下载产品的链接,以下是我正在使用的代码.

I am trying to add link to downloadable product programmatically, below is the code on which i am working.

$linkfile = array();
$_highfilePath = $FolderPath.DS.$fname;
$linkfile[] = array(
        'file' => $filePath,
        'name' => $fname,
        'size' => filesize($filePath),
        'status' => 'new'
);

$linkFileName = Mage::helper('downloadable/file')->moveFileFromTmp(
            Mage_Downloadable_Model_Link::getBaseTmpPath(),
            Mage_Downloadable_Model_Link::getBasePath(),
            $linkfile
    );

    $linkModel = Mage::getModel('downloadable/link')->setData(array(
            'product_id' => $product->getId(),
            'sort_order' => 0,
            'number_of_downloads' => 0, // Unlimited downloads
            'is_shareable' => 2, // Not shareable
            'link_url' => '',
            'link_type' => 'file',
            'link_file' => json_encode($linkfile),
            'sample_url' => $SamplePathUrl,
            'sample_file' => json_encode($linkfile),
            'sample_type' => 'file',
            'use_default_title' => true,
            'default_price' => 0,
            'price' => 0,
            'store_id' => 0,
            'website_id' => $product->getStore()->getWebsiteId(),
    ));

,这是我得到An error occurred while saving the file(s).的错误. 请帮助

and this is the error i get An error occurred while saving the file(s).. Please help

推荐答案

在没有更多信息的情况下无法确定地进行诊断.这是失败的呼叫的代码:

Impossible to diagnose with certainty without more information. Here's the code for the call that's failing:

/**
 * Checking file for moving and move it
 *
 * @param string $baseTmpPath
 * @param string $basePath
 * @param array $file
 * @return string
 */
public function moveFileFromTmp($baseTmpPath, $basePath, $file)
{
    if (isset($file[0])) {
        $fileName = $file[0]['file'];
        if ($file[0]['status'] == 'new') {
            try {
                $fileName = $this->_moveFileFromTmp(
                    $baseTmpPath, $basePath, $file[0]['file']
                );
            } catch (Exception $e) {
                Mage::throwException(Mage::helper('downloadable')->__('An error occurred while saving the file(s).'));
            }
        }
        return $fileName;
    }
    return '';
}

一个好的开始是检查文件系统权限,确保您的数据类型与函数注释中指定的类型匹配,并确保所有文件和目录都存在.

A good place to start would be checking filesystem permissions, making sure your datatypes match the types specified in the function comments, and making sure all files and directories exist.

这篇关于可下载产品:以编程方式将文件链接添加到可下载产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆