Jump to content

An'im Fahmy

Members
  • Posts

    23
  • Joined

  • Last visited

Contact Methods

Profile Information

  • First Name
    An'im
  • Last Name
    fahmy

Recent Profile Visitors

259 profile views

An'im Fahmy's Achievements

Newbie

Newbie (1/14)

2

Reputation

1

Community Answers

  1. How to check the hook is works? This is my code <?php if (!defined('_PS_VERSION_')) exit; class InagataModule extends Module { public function __construct() { $this->name = 'inagatamodule'; $this->tab = 'billing_invoicing'; $this->version = '1.0.0'; $this->author = "Achmad An'im Fahmy "; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Inagata Module'); $this->description = $this->l('Mengirim push notification ketika status order berubah.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get('INAGATAMODULE')) $this->warning = $this->l('No name provided'); } #displayBackOfficeHeader public function install() { if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); if (!parent::install() || !$this->registerHook('actionOrderStatusPostUpdate') || !Configuration::updateValue('INAGATAMODULE', 'my friend') ) return false; return true; } public function uninstall() { if (!parent::uninstall() || !Configuration::deleteByName('INAGATAMODULE') ) return false; return true; } public function hookactionOrderStatusPostUpdate($params) { $file = 'coba'; // Open the file to get existing content $current = file_get_contents($params); // Append a new person to the file $current .= "$params\n"; // Write the contents back to the file file_put_contents($file, $current); echo "<pre>".print_r($params)."</pre>";die(); } } in function hookactionOrderStatusPostUpdate not write anything to coba file and not print anything. But, when I use standard hooks, it's showing in website (displayHeader) Thank you
  2. Can I use the actionOrderStatusPostUpdate hook from php outside files? Do you have the docs or tutorial? Or I must make a module? Thanks
  3. How to use this code for my own php? what must I include? Thankyou
  4. I have one question, I succesfully create order via webservice, but not shown to back office, just in database, because delivery address and invoice address not inserted in database column, altough was POST: id_address_delivery and POST: id_address_invoice After I input manually to the column, the order shown in backoffice. Any ideas? Thank you
  5. Thank you very much for your reply. My code wrong here: $opt = array('resource' => 'orders'); $opt['putXml'] = $xml->asXML(); print_r($opt['putXml']); //return false; //COMMENT THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I type 'putXml' for placing order, after I change to postXml, all running well without change everything after that, order successfully added to database. But, one more problem, With your code or my code, not showing to back office because nothing address input in database, actually I was added the address. Once again Thank you
  6. Terima kasih telah membaca thread ini, Langsung saja, ada yang pernah membuat order via webservice? Saya sudah melakukan hal di bawah ini dengan sukses: 1. Membuat customer 2. Membuat address 3. Membuat cart Dan ketika membuat order, statusnya Bad Parameter given. Padahal yang required=true sudah saya isi semua termasuk cart_rows di dalam associations Saya menggunakan https://github.com/PrestaShop/PrestaShop-webservice-lib/ sebagai referensi, cuma di place order saja yang belum berhasil. Adakah yang pernah mengalami masalah ini? Silahkan mengajukan pertanyaan bila ada yang belum jelas, Terima kasih
  7. Hello, I was read and reply all related topic about creating order via webservice, but not found the solution. I was succeed 1. creating customer; 2. creating address, and; 3. creating cart All can accessed in www.mystore.com/api/ But, when I am create order, I have error status: Bad Parameter Given. Must I do task after create cart and before create order? I am sorry for bad english Thank you, Regards,
  8. And this is the result <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <order> <id></id> <id_address_delivery>5047</id_address_delivery> <id_address_invoice>5047</id_address_invoice> <id_cart>37</id_cart> <id_currency>1</id_currency> <id_lang>1</id_lang> <id_customer>34</id_customer> <id_carrier>60</id_carrier> <current_state>59</current_state> <module>bca</module> <invoice_number></invoice_number> <invoice_date></invoice_date> <delivery_number></delivery_number> <delivery_date></delivery_date> <valid></valid> <date_add></date_add> <date_upd></date_upd> <shipping_number></shipping_number> <id_shop_group>1</id_shop_group> <id_shop>1</id_shop> <secure_key></secure_key> <payment>BCA</payment> <recyclable></recyclable> <gift></gift> <gift_message></gift_message> <mobile_theme></mobile_theme> <total_discounts></total_discounts> <total_discounts_tax_incl></total_discounts_tax_incl> <total_discounts_tax_excl></total_discounts_tax_excl> <total_paid>816000</total_paid> <total_paid_tax_incl>816000</total_paid_tax_incl> <total_paid_tax_excl>816000</total_paid_tax_excl> <total_paid_real>825000</total_paid_real> <total_products>816000</total_products> <total_products_wt>816000</total_products_wt> <total_shipping>0</total_shipping> <total_shipping_tax_incl>0</total_shipping_tax_incl> <total_shipping_tax_excl>0</total_shipping_tax_excl> <carrier_tax_rate>0</carrier_tax_rate> <total_wrapping>0</total_wrapping> <total_wrapping_tax_incl>0</total_wrapping_tax_incl> <total_wrapping_tax_excl>0</total_wrapping_tax_excl> <round_mode>0</round_mode> <round_type></round_type> <conversion_rate>1</conversion_rate> <reference></reference> <associations> <order_rows> <order_row> <product_id>3</product_id> <product_attribute_id>0</product_attribute_id> <product_quantity>1</product_quantity> <product_name>Raflesia Yellow ggwp</product_name> <product_price>30000</product_price> </order_row> <order_row> <product_id>6</product_id> <product_attribute_id>0</product_attribute_id> <product_quantity>1</product_quantity> <product_name>Good Night</product_name> <product_price>795000</product_price> </order_row> </order_rows> </associations> </order> </prestashop> {"status":"Other error <br \/>Bad parameters given"}
  9. Do you have suggest for me? <?php require_once('config.php'); require_once('../PSWebServiceLibrary.php'); //default POST $_POST['id_currency']=1; $_POST['id_lang']=1; $_POST['id_shop_group']=1; $_POST['id_shop']=1; $_POST['product_attribute_id']=0; $_POST['current_state']=59; $_POST['module']=strtolower($_POST['payment']); $_POST['payment']=strtoupper($_POST['payment']); $_POST['conversion_rate']=1.000000; //end default function getAddress($idCustomer){ $xml_file = "https://".PS_WS_AUTH_KEY."@".PS_SHOP_PATH."/api/addresses?filter[id_customer]=".$idCustomer; $xml = file_get_contents($xml_file); $xml = XmlCleanStrips($xml); $xml = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA); $xml = json_decode(json_encode($xml)); $id_address = (isset($xml->addresses->address->{'@attributes'}->id) ? $xml->addresses->address->{'@attributes'}->id : $xml->addresses->address[0]->{'@attributes'}->id); return $id_address; } function getCart($idCart){ $xml_file = "https://".PS_WS_AUTH_KEY."@".PS_SHOP_PATH."/api/carts/".$idCart; $xml = file_get_contents($xml_file); $xml = XmlCleanStrips($xml); $xml = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA); $xml = json_decode(json_encode($xml)); $id_customer = $xml->cart->id_customer; $xml = $xml->cart->associations->cart_rows; unset($xml->{'@attributes'}); $arr["id_customer"] = $id_customer; $arr["rows"] = $xml; return $arr; } function updateCartAddr($idCart){ try{ $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $opt = array('resource' => 'carts'); if (isset($idCart)){ $opt['id'] = $idCart; } $xml = $webService->get($opt); // Here we get the elements from children of customer markup which is children of prestashop root markup $resources = $xml->children()->children(); } catch (PrestaShopWebserviceException $e) { // Here we are dealing with errors $trace = $e->getTrace(); if ($trace[0]['args'][0] == 404) $status["status"] = 'Bad ID'; else if ($trace[0]['args'][0] == 401) $status["status"] = 'Bad auth key'; else $status["status"] = 'Other error<br />'.$e->getMessage(); echo json_encode($status); } // Second : We update the data and send it to the web service if (isset($idCart)) { // Here we have XML before update, lets update XML with new values foreach ($resources as $nodeKey => $node){ $resources->$nodeKey = $resources->$nodeKey; } try { $cartRows = getCart($idCart)["rows"]; $defaulAddr = getAddress(getCart($idCart)["id_customer"]); $default_id_address_delivery = (isset($_POST['id_address_delivery']) ? $_POST['id_address_delivery'] : $defaulAddr); $default_id_address_invoice = (isset($_POST['id_address_invoice']) ? $_POST['id_address_invoice'] : $defaulAddr); $resources->id_address_delivery = $default_id_address_delivery; $resources->id_address_invoice = $default_id_address_invoice; $orderke = 0; if(count($cartRows->cart_row)==1){ foreach($cartRows as $key => $value){ $resources->associations->cart_rows->cart_row[$orderke]->id_product = $value->id_product; $resources->associations->cart_rows->cart_row[$orderke]->id_product_attribute = 0; $resources->associations->cart_rows->cart_row[$orderke]->quantity = $value->quantity; $resources->associations->cart_rows->cart_row[$orderke]->id_address_delivery = $default_id_address_delivery; $orderke++; } }else if(count($cartRows->cart_row)>0){ foreach($cartRows->cart_row as $key => $value){ $resources->associations->cart_rows->cart_row[$orderke]->id_product = $value->id_product; $resources->associations->cart_rows->cart_row[$orderke]->id_product_attribute = 0; $resources->associations->cart_rows->cart_row[$orderke]->quantity = $value->quantity; $resources->associations->cart_rows->cart_row[$orderke]->id_address_delivery = $default_id_address_delivery; $orderke++; } } $opt = array('resource' => 'carts'); $opt['putXml'] = $xml->asXML(); //print_r($opt['putXml']); //return false; //COMMENT THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $opt['id'] = $idCart; $xml = $webService->edit($opt); }catch (PrestaShopWebserviceException $ex){ $trace = $ex->getTrace(); if ($trace[0]['args'][0] == 404) $status["status"] = 'Bad ID'; else if ($trace[0]['args'][0] == 401) $status["status"] = 'Bad auth key'; else $status["status"] = 'Other error<br />'.$ex->getMessage(); echo json_encode($status); } } } //updateCartAddr(35);//DO BEFORE PLACE ORDER function getProductInfo($idProduct){ $xml_file = "https://".PS_WS_AUTH_KEY."@".PS_SHOP_PATH."/api/products/".$idProduct; $xml = file_get_contents($xml_file); $xml = XmlCleanStrips($xml); $xml = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA); $discount = $xml->product->addChild('ina_discount'); $inaapi = new inaAPI; $inadiscount = $inaapi->getProductDiscount($idProduct); $from_quantity = (isset($inadiscount[0]['from_quantity']) ? $inadiscount[0]['from_quantity'] : 0); $reduction = (isset($inadiscount[0]['reduction']) ? $inadiscount[0]['reduction'] : 0); $discount->addChild('reduction', $reduction); $discount->addChild('from_quantity', $from_quantity); $product = json_decode(json_encode($xml))->product; $info = array(); $name = $product->name->language; $price = (float)$product->price; $_reduction = (float)$product->ina_discount->reduction; $_from_quantity = (integer)$product->ina_discount->from_quantity; $info['name']=$name; $info['price']=$price; $info['reduction']=$_reduction; $info['from_quantity']=$_from_quantity; return($info); } //print_r(getProductInfo(3)); function placeOrder($idCart){ try { $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $opt = array('resource' => 'orders'); $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=blank')); $resources = $xml->children()->children(); } catch (PrestaShopWebserviceException $e){ // Here we are dealing with errors $trace = $e->getTrace(); if ($trace[0]['args'][0] == 404) $status["status"] = 'Bad ID'; else if ($trace[0]['args'][0] == 401) $status["status"] = 'Bad auth key'; else $status["status"] = "Orders - Other error1".$ex->getMessage(); echo json_encode($status); } // Second : We update the data and send it to the web service if (isset($idCart)) { // Here we have XML before update, lets update XML with new values $defaulAddr = getAddress(getCart($idCart)["id_customer"]); $_POST['id_address_delivery'] = (isset($_POST['id_address_delivery']) ? $_POST['id_address_delivery'] : $defaulAddr); $_POST['id_address_invoice'] = (isset($_POST['id_address_invoice']) ? $_POST['id_address_invoice'] : $defaulAddr); foreach ($resources as $nodeKey => $node){ $resources->$nodeKey = $_POST[$nodeKey]; } try { $total=0; $totalreal=0; $cartRows = getCart($idCart)["rows"]; $orderke = 0; if(count($cartRows->cart_row)==1){ foreach($cartRows as $key => $value){ $resources->associations->order_rows->order_row[$orderke]->product_id = $value->id_product; $resources->associations->order_rows->order_row[$orderke]->product_attribute_id = 0; $resources->associations->order_rows->order_row[$orderke]->product_quantity = $value->quantity; $resources->associations->order_rows->order_row[$orderke]->product_name = getProductInfo($value->id_product)['name']; $resources->associations->order_rows->order_row[$orderke]->product_price = getProductInfo($value->id_product)['price']; $total+= getProductInfo($value->id_product)['reduction']>0 ? (getProductInfo($value->id_product)['price']-(getProductInfo($value->id_product)['price']*getProductInfo($value->id_product)['reduction']))*$value->quantity : getProductInfo($value->id_product)['price']*$value->quantity; $totalreal+=getProductInfo($value->id_product)['price']*$value->quantity;; $orderke++; } }else if(count($cartRows->cart_row)>0){ foreach($cartRows->cart_row as $key => $value){ $resources->associations->order_rows->order_row[$orderke]->product_id = $value->id_product; $resources->associations->order_rows->order_row[$orderke]->product_attribute_id = 0; $resources->associations->order_rows->order_row[$orderke]->product_quantity = $value->quantity; $resources->associations->order_rows->order_row[$orderke]->product_name = getProductInfo($value->id_product)['name']; $resources->associations->order_rows->order_row[$orderke]->product_price = getProductInfo($value->id_product)['price']; $total+= getProductInfo($value->id_product)['reduction']>0 ? (getProductInfo($value->id_product)['price']-(getProductInfo($value->id_product)['price']*getProductInfo($value->id_product)['reduction']))*$value->quantity : getProductInfo($value->id_product)['price']*$value->quantity; $totalreal+=getProductInfo($value->id_product)['price']*$value->quantity;; $orderke++; } } $resources->total_paid = $total; $resources->total_paid_tax_incl = $total; $resources->total_paid_tax_excl = $total; $resources->total_paid_real = $totalreal; $resources->total_products = $total; $resources->total_products_wt = $total; $resources->total_shipping = 0.000000; $resources->total_shipping_tax_incl=0.000000; $resources->total_shipping_tax_excl=0.000000; $resources->carrier_tax_rate=0.000; $resources->total_wrapping=0.000000; $resources->total_wrapping_tax_incl=0.000000; $resources->total_wrapping_tax_excl=0.000000; $resources->round_mode=0; $opt = array('resource' => 'orders'); $opt['putXml'] = $xml->asXML(); print_r($opt['putXml']); //return false; //COMMENT THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $xml = $webService->add($opt); $idOrder = (array)$xml->order->id; $status["id"] = $idOrder[0]; $status["status"] = "success"; echo json_encode($status); }catch (PrestaShopWebserviceException $ex){ $trace = $ex->getTrace(); if ($trace[0]['args'][0] == 404) $status["status"] = 'Bad ID'; else if ($trace[0]['args'][0] == 401) $status["status"] = 'Bad auth key'; else $status["status"] = 'Other error<br />'.$ex->getMessage(); echo json_encode($status); } } } if(isset($_POST['id_cart']) && ctype_digit($_POST['id_cart'])){ placeOrder($_POST['id_cart']); }
×
×
  • Create New...