标签:php magento module zend-framework
我正在开发付款模块.我在任何地方都找不到Magento系统的适当文档.
到目前为止,我正面临着“付款方式模型”的捕获方式问题.请帮我.
我不知道为什么未创建和发送REST API的CURL请求.它仅执行前两三行.我认为我在下面编写代码的方式不正确,请提出最佳方法.下订单后,我按照代码中的说明在日志文件中“获取了信息实例”和金额.我称为Mage :: Log()的其他数据未出现在系统日志文件中.
我有这样的付款方式代码
<?php
class Company_Cashondelivery_Model_Createorder extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'cashondelivery';
protected $_canCapture = true;
protected $_canUseCheckout = true;
public function capture(Varien_Object $payment, $amount)
{
$paymentInfo = $this->getInfoInstance();
Mage::Log('Got Info Instance'); //This is shown in Log file.
Mage::Log($amount); //This is shown in Log file
Mage::Log($payment);
$xml='<?xml version="1.0" encoding="utf-8" ?>'.
'<transaction>'.
'<customerDetails>'.
'<address>This is, address, Purple Talk, 600100</address>'. //I dont know how to get Address as string here
'<contactNo>'.$paymentInfo->getOrder()->getBillingAddress()->getTelephone().'</contactNo>'.
'<email>'.$paymentInfo->getOrder()->getBillingAddress()->email().'</email>'.
'<firstName>'.$paymentInfo->getOrder()->getBillingAddress()->getFirstName().'</firstName>'.
'<lastName>'.$paymentInfo->getOrder()->getBillingAddress()->getLastName().'</lastName>'.
'</customerDetails>'.
'<orderDetails>'.
'<pincode>'.$paymentInfo->getOrder()->getBillingAddress()->getPostCode().'</pincode>'.
'<clientOrderID>'.$paymentInfo->getOrder()->getIncrementId().'</clientOrderID>'.
'<deliveryDate>20-7-20111</deliveryDate>'.
'<orderAmount>'.$amount.'</orderAmount>'.
'<productDetails>';
Mage::Log($xml);//This is not there in log file
foreach ($paymentInfo->getOrder()->getAllItems() as $item)
{
$xml.='<productDetails>'.
'<productID>'.$item->getProductId().'</productID>'.
'<productQuantity>'.$item->getQtyOrdered().'</productQuantity>'.
'<unitCost>'.$item->getPrice().'</unitCost>'.
'</productDetails>';
}
$xml.='</orderDetails>'.
'<additionalInformation>'.
'<parameters>'.
'<name>Some Name</name>'.
'<value>Some Value</value>'.
'</parameters>'.
'<parameters>'.
'<name>Some Name2</name>'.
'<value>Some value2</value>'.
'</parameters>'.
'</additionalInformation>'.
'</transaction>';
Mage::Log($xml);
$url = "http://services.abc.com/rest/service/createOrder";
Mage::Log('Loading url : '.$url); //This is not there in Log;
$ch = curl_init($url) ;
curl_setopt($ch, CURLOPT_HEADER,true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('username:xxxxx','password:xxxxxx','Content-Type:application/xml'));
$response = curl_exec($ch);
Mage::Log($response); //This is not there in Log file;
return $this;
}
}
?>
Config.xml文件是这样的
<?xml version="1.0"?>
<config>
<modules>
<Company_Cashondelivery>
<!-- declare module's version information for database updates -->
<version>0.1.0</version>
</Company_Cashondelivery>
</modules>
<global>
<!-- declare model group for new module -->
<models>
<!-- model group alias to be used in Mage::getModel('newmodule/...') -->
<cashondelivery>
<!-- base class name for the model group -->
<class>Company_Cashondelivery_Model</class>
</cashondelivery>
</models>
<helpers>
<cashondelivery>
<class>Company_Cashondelivery_Helper</class>
</cashondelivery>
</helpers>
<!-- declare resource setup for new module -->
<resources>
<!-- resource identifier -->
<cashondelivery_setup>
<!-- specify that this resource is a setup resource and used for upgrades -->
<setup>
<!-- which module to look for install/upgrade files in -->
<module>Company_Cashondelivery</module>
</setup>
<!-- specify database connection for this resource -->
<connection>
<!-- do not create new connection, use predefined core setup connection -->
<use>core_setup</use>
</connection>
</cashondelivery_setup>
<cashondelivery_write>
<connection>
<use>core_write</use>
</connection>
</cashondelivery_write>
<cashondelivery_read>
<connection>
<use>core_read</use>
</connection>
</cashondelivery_read>
</resources>
</global>
<!-- declare default configuration values for this module -->
<default>
<payment>
<cashondelivery>
<active>1</active>
<model>cashondelivery/createorder</model>
<order_status>pending</order_status>
<payment_action>authorize_capture</payment_action>
<title>Company</title>
</cashondelivery>
</payment>
</default>
</config>
system.xml文件是这样的
<?xml version="1.0"?>
<config>
<sections>
<payment>
<groups>
<cashondelivery translate="label" module="cashondelivery">
<label>Company Cash On delivery</label>
<sort_order>670</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</active>
<order_status translate="label">
<label>New order status</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status_processing</source_model>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</order_status>
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</title>
</fields>
</cashondelivery>
</groups>
</payment>
</sections>
</config>
etc / module / Company_Cashondelivery.xml就像这样
<?xml version="1.0"?>
<config>
<modules>
<Company_Cashondelivery>
<active>true</active>
<codePool>local</codePool>
</Company_Cashondelivery>
</modules>
<depends>
<Mage_Payment />
</depends>
</config>
让我知道是否不清楚.
解决方法:
您的代码存在问题
‘<电子邮件>’ $paymentInfo-> getOrder() – > getBillingAddress() – >电子邮件() ‘< /电子邮件>’.
没有email()函数,您可以使用`”.$paymentInfo-> getOrder()-> getBillingAddress()-> getEmail().”.”检索电子邮件.
此错误会发送到商店所有者的电子邮件中.如果您在localhost上进行开发,我建议您使用smtp的一些模拟,例如(对于win)http://www.toolheap.com/test-mail-server-tool/,然后您可以看到Magento发送的所有电子邮件.
还有第二点.您可以使用Magento随附的Varien_Http_Client(Zend_Http_Client)代替丑陋的卷曲.您可以在我的帖子中看到示例-https://stackoverflow.com/a/9233290/858586
标签:php,magento,module,zend-framework 来源: https://codeday.me/bug/20191010/1885829.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。