Arkataev Posted May 23, 2013 Share Posted May 23, 2013 (edited) Hi! I have this problem. I need the price for each product to be imported with xml. request from the other server and displayed in pruduct.tpl. I have the following xml: $xml=" <digiseller.request> <id_goods></id_goods> </digiseller.request> "; function _GetAnswer($address, $xml){ $ch = curl_init($address); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); $result=curl_exec($ch); return $result; } $answer=_GetAnswer("http://shop.digiseller.ru/xml/personal_goods_info.asp", $xml); $xmlres = simplexml_load_string($answer); foreach ($xmlres->price_goods->wmr as $price_goods) { echo $price_goods; }; $smarty->assign('digsale',$xml); I need prestashop to take each product reference value and put it to <id_goods>HERE</id_goods> in xml. request. Than I need to assign the xml response to a variable and display it in the price field on product page. I input the xml request to productcontroller.php and assigned the variable 'digsale'. But I i wonder how to insert the product reference variable into the xml request. Could anyone help me, please? [sOLVED] Edited August 2, 2013 by vekia (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted May 23, 2013 Share Posted May 23, 2013 You could do something like this. First add a static text REPLACEME so you have a needle to find $xml=" <digiseller.request> <id_goods>REPLACEME</id_goods> </digiseller.request> "; Then use string replace function to replace REPLACEME with the product reference. $xml=str_replace('REPLACEME', $product->reference, $xml) Then you can send that request and use the response information as you like. However if I understand you properly, that will only change the price display on the product page. If the customer tries to purchase this product, it will not use this price during checkout. 1 Link to comment Share on other sites More sharing options...
Arkataev Posted May 23, 2013 Author Share Posted May 23, 2013 Unfortunately it refuse working:( I did as you adviced: $xml=" <digiseller.request> <id_goods>REPLACEME</id_goods> </digiseller.request> "; $xml=str_replace('REPLACEME', $product->reference, $xml); function _GetAnswer($address, $xml){ $ch = curl_init($address); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); $result=curl_exec($ch); return $result; } $answer=_GetAnswer("http://shop.digiseller.ru/xml/personal_goods_info.asp", $xml); $xmlres = simplexml_load_string($answer); foreach ($xmlres->price_goods->wmr as $price_goods) { echo $price_goods; }; $smarty->assign('digsale',$xml); } I tried different placement throughout the productcontroller.php but without any use. Maybe I did smth wrong in tpl.? I just put an {$digsale} variable into product tpl. waiting it will return the proper value.But there's no any sign of it. I suppose this got to be lil' bit trickier... Link to comment Share on other sites More sharing options...
Arkataev Posted May 23, 2013 Author Share Posted May 23, 2013 I've tested the xml. request on xampp and it returns correctly. So it makes me think I did smth wrong with tpl... Link to comment Share on other sites More sharing options...
Arkataev Posted May 23, 2013 Author Share Posted May 23, 2013 However if I understand you properly, that will only change the price display on the product page. If the customer tries to purchase this product, it will not use this price during checkout. You're right, but that's exactly what I need. That's because I use an external checkout: after hitting the 'Buy" button, client is redirected to the outside payment system, where he also gets his product (digital). Link to comment Share on other sites More sharing options...
Arkataev Posted May 23, 2013 Author Share Posted May 23, 2013 (edited) Fortunately i got it work, in some words... $xml=" <digiseller.request> <id_goods>REPLACEME</id_goods> </digiseller.request> "; $xml=str_replace("REPLACEME", 122332, $xml); function _GetAnswer($address, $xml){ $ch = curl_init($address); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); $result=curl_exec($ch); return $result; } $answer=_GetAnswer("http://shop.digiseller.ru/xml/personal_goods_info.asp", $xml); $xmlres = simplexml_load_string($answer); foreach ($xmlres->price_goods->wmr as $price_goods) ; $this->context->smarty->assign(array( 'digsale'=>$price_goods )); This returns the price of a product from the outside server in right way. But in the mean time, when I use $product->reference instead of that fixed number here $xml=str_replace('REPLACEME', 31313134, $xml); This returns nothing. Apparantly this is about $product->reference p.s. I put the code to /controllers/front/productcontroller.php Edited May 23, 2013 by vega17 (see edit history) Link to comment Share on other sites More sharing options...
Arkataev Posted May 24, 2013 Author Share Posted May 24, 2013 Got it! [/size] $xml=" <digiseller.request> <id_goods>REPLACEME</id_goods> </digiseller.request> "; $xml=str_replace("REPLACEME", (int)$this->product->reference, $xml); function _GetAnswer($address, $xml){ $ch = curl_init($address); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); $result=curl_exec($ch); return $result; } $answer=_GetAnswer("http://shop.digiseller.ru/xml/personal_goods_info.asp", $xml); $xmlres = simplexml_load_string($answer); foreach ($xmlres->price_goods->wmr as $price_goods) ; $this->context->smarty->assign(array( 'digsale'=>$price_goods )); This returns the right response formed with a product reference. Link to comment Share on other sites More sharing options...
Arkataev Posted August 1, 2013 Author Share Posted August 1, 2013 [sOLVED] Link to comment Share on other sites More sharing options...
vekia Posted August 1, 2013 Share Posted August 1, 2013 hello can you say something more about your solution? im convinced that it will be really helpfull for other forum members thanks in advance Link to comment Share on other sites More sharing options...
Arkataev Posted August 2, 2013 Author Share Posted August 2, 2013 Hi! The problem was to change price display on product page. I needed to use data from external source with a help of xml response. And one more thing. An xml requst had to be formed using data in "product reference" field. So I put the following code into productcontroller itself (controllers->front). It gows on line 251 protected function assignPriceAndTax() { .....some code here $xml=" <digiseller.request> <id_goods>REPLACEME</id_goods> </digiseller.request> "; $xml=str_replace("REPLACEME", (int)$this->product->reference ,$xml); function _GetAnswer($address, $xml){ $ch = curl_init($address); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); $result=curl_exec($ch); return $result; } $answer=_GetAnswer("http://shop.digiseller.ru/xml/personal_goods_info.asp", $xml); $xmlres = simplexml_load_string($answer); foreach ($xmlres->price_goods->wmr as $price_goods) ; $xmlres = simplexml_load_string($answer); foreach ($xmlres->price_goods->wmu as $wmu ); $xmlres = simplexml_load_string($answer); foreach ($xmlres->price_goods->pcr as $pcr ); $xmlres = simplexml_load_string($answer); foreach ($xmlres->reward as $reward ); $xmlres = simplexml_load_string($answer); foreach ($xmlres->reward_summ as $arew ); $xmlres = simplexml_load_string($answer); foreach ($xmlres->reward_curr as $arewc ); $this->context->smarty->assign(array( 'digsale'=>$price_goods, 'digsalewmu'=>$wmu, 'digsalepcr'=>$pcr, 'digsalereward'=>$reward, 'digsalearew'=>$arew, 'digsalearewc'=>$arewc, )); } This thing returns data needed and then it assignes the proper variables for it. As a result I'm availabe to use that variables in product.tpl. To do this you need to just input them in your tpl. in {$yourvariable} form. Now I have a product price formed with a help of data from an external source. p.s. I use ps 1.5.2.0 Link to comment Share on other sites More sharing options...
vekia Posted August 2, 2013 Share Posted August 2, 2013 many thanks, very valuable information im convinced that it will be helpfull for whole community im going to mark this topic as solved thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now