Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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_Magento 1.6 - Fatal编程技术网

Php Magento以编程方式添加层价格,但带有自定义字段

Php Magento以编程方式添加层价格,但带有自定义字段,php,magento,magento-1.6,Php,Magento,Magento 1.6,我有一个关于按代码添加产品层价格的问题。我做了一些研究,发现有一个MagentoAPI可以用来增加价格。然而,由于我已经定制了我们的magento并在层价格中添加了一个新字段,即“生产时间”,我不知道如何通过API添加层价格 下面是示例代码 $proxy = new SoapClient(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'/api/soap/?wsdl'); $sessionId = $proxy->login('

我有一个关于按代码添加产品层价格的问题。我做了一些研究,发现有一个MagentoAPI可以用来增加价格。然而,由于我已经定制了我们的magento并在层价格中添加了一个新字段,即“生产时间”,我不知道如何通过API添加层价格

下面是示例代码

$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() . "\n";
}
我会得到一个错误,上面写着“无效的层价格”

知道为什么会这样吗?或者是否有其他方法来增加分层价格


谢谢。

比API更好,在API中,并非所有函数都可以使用标准Magento脚本,您只需将其放置在Magento文件夹中的任何位置:

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\n";                                      

      }; // end testing of product exist              


}; // enf foreach

我发现加载API用于分层价格的模型是最容易的,这样它可以帮助您验证数据

$tierPrices = array();

$tierPrices[] = array(
    'customer_group_id' => 1,       // or 'all' or whatever your customer group ID is
    'qty'               => 1,       // Must be greater than 0
    'price'             => 5.99,    // Use an int here, don't currency format
    'website_id'        => 0        // or whatever website ID you need to set this to
);

// Set more tiered prices here if you'd like...

$tierPriceModel = Mage::getModel('catalog/product_attribute_tierprice_api');

// Assume 12345 is your product ID
$tierPriceModel->update(12345, $tierPrices);

像我这样的人想知道为什么在考虑到网站id的情况下没有更新分层价格,这是因为@Tyler V.代码中存在错误,或者api代码已更改

这是设置新层级价格的正确方法:

$tierPrices[] = array(
    'customer_group_id' => 'all',     
    'qty'               => 1,       
    'price'             => 5.99,    
    'website'        => 0         
);

当您将网站指定到层级价格数组中时,这不再是网站id,而是网站

如果你能告诉我如何正确定价,那会更有帮助。