magento 修改paypal传递产品name参数
来源:互联网 发布:世界图书出版社 知乎 编辑:程序博客网 时间:2024/04/30 15:16
magento 整合了paypal方便了很多人,但是对一些paypal的用户有特殊要求的用户就会觉得修改起来非常麻烦,有朋友问我,如何修改magento传递到paypal 的产品的名称为自定义想要的参数呢?
通过追查源码,发现了app\code\core\Mage\Paypal\Model下的cart.php有这么一个方法
/** * Add a line item * * @param string $name * @param numeric $qty * @param float $amount * @param string $identifier * @return Varien_Object */ public function addItem($name, $qty, $amount, $identifier = null) { $this->_shouldRender = true; $item = new Varien_Object(array( 'name' => $name, 'qty' => $qty, 'amount' => (float)$amount, )); if ($identifier) { $item->setData('id', $identifier); } $this->_items[] = $item; return $item; }
通过注释我们也能很快的理解 他接受传递过来的 name qty amont等参数。这个就和cart传递的参数很像了,往后去看看 他在什么时候去使用这个方法
/** * Add a usual line item with amount and qty * * @param Varien_Object $salesItem * @return Varien_Object */ protected function _addRegularItem(Varien_Object $salesItem) { if ($this->_salesEntity instanceof Mage_Sales_Model_Order) { $qty = (int) $salesItem->getQtyOrdered(); $amount = (float) $salesItem->getBasePrice(); // TODO: nominal item for order } else { $qty = (int) $salesItem->getTotalQty(); $amount = $salesItem->isNominal() ? 0 : (float) $salesItem->getBaseCalculationPrice(); } // workaround in case if item subtotal precision is not compatible with PayPal (.2) $subAggregatedLabel = ''; if ($amount - round($amount, 2)) { $amount = $amount * $qty; $subAggregatedLabel = ' x' . $qty; $qty = 1; } // aggregate item price if item qty * price does not match row total if (($amount * $qty) != $salesItem->getBaseRowTotal()) { $amount = (float) $salesItem->getBaseRowTotal(); $subAggregatedLabel = ' x' . $qty; $qty = 1; }return $this->addItem($salesItem->getName() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());
}
在这儿,我们能看到magento对购物车中产品信息进行处理,最后通过addItem()这个方法去添加到paypal的参数列表中去
所以,如果我们想要修改magento想paypal提交的产品名称,只需要修改 addItem()这个方法传递的参数
例如,我修改传递过去的产品名称为产品的ID,只需要在return的时候,修改name为id
return $this->addItem($salesItem->getId() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());同理,修改为sku
return $this->addItem($salesItem->getSku() . $subAggregatedLabel, $qty, $amount, $salesItem->getSku());magento面向对象的编程方式,这儿只要$salesItem里面有的属性,都可以通过魔术方法get来获取当做传递到paypal的参数。
稍微复杂点的,可以自己去按照自己的需求来写业务逻辑。
- magento 修改paypal传递产品name参数
- magento 修改 paypal order product name
- 提交数据到paypal时,magento的产品名修改
- magento -- 如何修改产品列表默认排序
- 批量修改magento产品库存数量
- Magento配置Paypal
- magento设置paypal付款
- magento后台paypal设置
- 修改magento产品列表页每行显示的产品个数
- 参数传递,修改
- Magento PAYPAL支付方式研究
- [Magento] Setting PayPal Express checkout
- magento paypal 无法处理付款
- magento get paypal transaction id
- Magento 修改添加产品的默认属性值
- Magento 产品添加购物车时修改价格
- Magento返回产品name,sku,Description,ShortDescription,Specifications,Weight 的 SQL查询语句
- PayPal支付接口参数
- c#asp.net url 传递中文参数要使用 System.Web.HttpUtility.UrlEncode 而不能使用Server.UrlEncode
- Extjs ---动态拼接panel
- git安装与使用(一)
- OCP-1Z0-053-V12.02-399题
- win7下运行VC++6.0
- magento 修改paypal传递产品name参数
- 多线程中Sleep的作用
- 6. 求解100以内的所有素数
- TCP 和 HTTP
- 分析优酷/土豆/pptv/乐视 HTML5、m3u8地址
- 设计模式(十一)代理模式Proxy(结构型)
- 从摄像头拍照,并把图片转为视频
- mulit ComboTree Select and query
- UVa11996 splay树(WA)