【问题标题】:How can I add new field in tier price?如何在等级价格中添加新字段?
【发布时间】:2015-12-30 17:59:18
【问题描述】:

app/design/adminhtml/default/default/catalog/product/edit/price/tier.phtml

来自一个新字段Peice_Price 的数据已成功显示在层页面中。 如何将数据插入表catalog_product_entity_tier_price?我想在单击产品页面保存按钮时保存此数据。

【问题讨论】:

  • 我无法理解你的问题。如果可能的话,你能用截图解释一下吗?
  • 我知道这无助于回答您的问题,但“piece”的拼写是“ie”,而不是“ei”。

标签: magento


【解决方案1】:

要添加等级价格,请勿触摸tier.phtml 文件。


为产品添加等级价格:

1*/ 使用这 4 个必需键设置一个数组:website、customer_group_id、qty、price。

$tierPrice = array(
    'website' => 'all', // or website ID
    'customer_group_id' => 2, // or 'all'
    'qty'  => 20, // required & not null, 1 = for not manage qty
    'price'  => 19.99,
);

2*/ 使用Mage_Catalog_Model_Product_Attribute_Tierprice_Api 中的update 方法更新产品价格。

该方法需要一个具有 1,n 层价格的数组:

$tierPrices[] = $tierPrice;
// in example the product ID is 123

try
{
    $api = new Mage_Catalog_Model_Product_Attribute_Tierprice_Api();
    $api->update( 123 , $tierPrices );
}
catch (Exception $ex)
{
    echo "Error when tier price creation: {$e->getMessage()} \n";
}

显示您的管理面板,等级价格与产品一起存储。


更改现有产品的等级价格。

1*/获取产品价格数组:

$api = new Mage_Catalog_Model_Product_Attribute_Tierprice_Api();
$tiersPrices = $api->info( 123 );  // 123 is the product ID

如果你 var_dump($tiersPrices); 你会得到这样的东西:

array(1) {
  [0]=>
  array(4) {
    ["customer_group_id"]=>
    int(1) "2"
    ["website"]=>
    string(3) "all"
    ["qty"]=>
    string(7) "20.0000"
    ["price"]=>
    string(7) "19.9900"
  }
}

2.1*/ 更改现有等级价格:

$tiersPrices[0]['customer_group_id'] = 'all';

2.2*/要添加另一个,设置一个数组:

$tiersPrices[] = array(
    'website' => 'all',
    'customer_group_id' => 'all',
    'qty'  => 50,
    'price'  => 14.99,
);

3*/ 并更新:

$api->update( 123 , $tiersPrices );

等级价格已更新!


核心代码可读且构建良好,足以查找和理解流程。

这是french articledbrugne 写于 2010 年 1 月 22 日的快速翻译。

【讨论】:

  • 您好 Nolwennig,感谢您的回复,我已经尝试了上面的示例,但是当我尝试添加新字段时,正如我在屏幕截图中提到的那样,它不会保存。 $tiersPrices[] = array('website' => 'all', 'customer_group_id' => 'all', 'qty' => 50, 'piece_price' => 10.00 'price' => 14.99, );
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 2021-12-11
相关资源
最近更新 更多