dquoj04882 2014-01-27 21:57
浏览 19

Magento以编程方式添加层级价格,但使用自定义字段

I have a problem about add product tier price by code. I did some research that there is a magento API that could be used to add tier price. However, since I have customized our magento and add a new field to the tier price, which is "production time", I don't know how to add tier price via API anymore.

Here is the sample code

$proxy = new SoapClient(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'/api/soap/?wsdl');
$sessionId = $proxy->login('API user','API Key');
$tierPrices[] = array(
    'website'           => 'all',
    'customer_group_id' => 'all',
    'production_time    => $data[2],
    'qty'               => $data[3],
    'price'             => $data[4]
);
 try {
        $proxy->call($sessionId, 'product_tier_price.update', array($sku, $tierPrices));
    } catch (Exception $e) {
        $e->getMessage() . "
";
}

I will get an error says "invalid tier price".

Any idea why does it happen? or is there other ways to add tier prices?

Thank you.

  • 写回答

3条回答 默认 最新

  • dongmangji0950 2014-01-28 10:44
    关注

    Better than API where are not all the functions you can use standard Magento script, you only need to be placed anywhere in magento folder:

    require("../../app/Mage.php");
    Mage::init();
    
    // Set an Admin Session
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    Mage::getSingleton('core/session', array('name' => 'adminhtml'));
    $userModel = Mage::getModel('admin/user');
    $userModel->setUserId(1);
    $session = Mage::getSingleton('admin/session');
    $session->setUser($userModel);
    $session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
    
    
    foreach ($youritemlist as $item) {  
    
    
       $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$item);  
    
        if(is_object($product)) {              
    
    
                    $product->setTierPrice($yourprice);  
                    echo "..(set)..";
    
    
                          $product->save();                          
    
                           echo "..saved
    ";                                      
    
          }; // end testing of product exist              
    
    
    }; // enf foreach
    
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题