博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Product Tier Price add/update in Magento
阅读量:4201 次
发布时间:2019-05-26

本文共 2349 字,大约阅读时间需要 7 分钟。

Magento has strong features to set Tier price. If you are interested to set multiple prices of a product for combination of customer group and product quantities, you can set by Magento Tier price option.

We can handle tier price in many ways. Here I am describing basic logic to add/update tier price in modular way. At first define all tier prices as an array. Ofcourse mind one thing about quantity. Quantity format must be four decimal precision. Like 100.0000. For this you can use below formatting.

$qty = number_format($qty, 4, ‘.’, ”);

01 //Define tier price as an array
02 $tierPrices[] = array(
03              'website_id'  => 0,
04              'cust_group'  => $customer_group_id,
05              'price_qty'   => $qty,
06              'price'       => $price
07            );
08  
09 Ex.
10 $tierPrices[0] = array(
11              'website_id'  => 0,
12              'cust_group'  => 1,
13              'price_qty'   => 100.0000,
14              'price'       => 12.0000
15            );
16  
17 $tierPrices[1] = array(
18              'website_id'  => 0,
19              'cust_group'  => 2,
20              'price_qty'   => 100.0000,
21              'price'       => 10.0000
22            );
23  
24 //get productid for corresponding SKU.
25 $productid = Mage::getModel('catalog/product')
26                   ->getIdBySku($sku);
27  
28 // Initiate product model
29 $product = Mage::getModel('catalog/product');
30  
31 // Load specific product whose tier price want to update
32 $product ->load($productid);
33  
34 // take existing tier prices of that product
35 $existingTierPrice = $product->tier_price;
36  
37 // Marge existing and new tier prices to update
38 $tierPrices=array_merge($existingTierPrice,$newTierPrices);
39  
40 // Assign all tier prices to product's tier_price object
41 $product->tier_price = $tierPrices;
42  
43 // Save you product with all tier prices
44 $product->save();

Also Magento has web service API support to handle tier price. If you are expert in web service work then you can do the same thing using Magento API. To handle tier price with api call do something like below.

01 $proxy = new SoapClient('');
02 $sessionId = $proxy->login('apiUser', 'apiKey');
03  
04 // Get tier prices
05 $tierPrices = $proxy->call($sessionId, 'product_tier_price.info', 'Sku');
06  
07 // Add new
08 $tierPrices[] = array(
09     'website'           => 'all',
10     'customer_group_id' => 'all',
11     'qty'               => 68,
12     'price'             => 18.20
13 );
14  
15 // Update tier prices
16 $proxy->call($sessionId, 'product_tier_price.update', array('Sku', $tierPrices));

转载地址:http://wscli.baihongyu.com/

你可能感兴趣的文章
谷歌获取货币汇率代码
查看>>
安装nginx
查看>>
手动6 - 隐藏Nginx版本号
查看>>
手动7 - nginx 日志切割
查看>>
magento - 使用后台设置的时间用法
查看>>
Linux常用命令
查看>>
清除文件中的.svn文件
查看>>
手动11 -nginx 优化配置
查看>>
php加速器 - zendopcache
查看>>
手动12 - 安装php加速器 Zend OPcache
查看>>
set theme -yii2
查看>>
yii2 - 模块(modules)的view 映射到theme里面
查看>>
yii2 - controller
查看>>
yii2 - 增加actions
查看>>
网站加载代码
查看>>
php图像处理函数大全(缩放、剪裁、缩放、翻转、旋转、透明、锐化的实例总结)
查看>>
magento url中 uenc 一坨编码 base64
查看>>
强大的jQuery焦点图无缝滚动走马灯特效插件cxScroll
查看>>
Yii2.0 数据库查询
查看>>
yii2 db 操作
查看>>