Jump to content

B@JTík

Members
  • Posts

    17
  • Joined

  • Last visited

Profile Information

  • Activity
    Other

Recent Profile Visitors

647 profile views

B@JTík's Achievements

Newbie

Newbie (1/14)

3

Reputation

  1. Check ID's of carrier, country, lang, currency, payment module ... all must exist and be enabled. My actual and working code with NEW/EXIST customer testing and with cart rules: <?php header('Content-type: text/html; charset=utf-8'); //------------------------------------ // POST Data simulation (for testing) // $_GET['pf_firstname'] = 'Firstname'; // $_GET['pf_lastname'] = 'Lastname'; // $_GET['pf_address1'] = 'MyStreet 321'; // $_GET['pf_postcode'] = '54321'; // $_GET['pf_city'] = 'MyCity'; // $_GET['pf_email'] = '[email protected]'; // $_GET['pf_phone'] = '987654321'; // $_GET['pf_quantity'] = '4'; // $_GET['pf_cart_rule_free_shipping'] = 'true'; // $_GET['pf_cart_rule_free_gift'] = 'true'; // $_GET['pf_cart_rule_discount_code'] = 'true'; //--------------- // Configuration define('DEBUG', false); define('PS_SHOP_PATH', 'http://'.$_SERVER['HTTP_HOST'].'/_presta'); define('PS_WS_AUTH_KEY', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456'); require_once('PSWebServiceLibrary.php'); $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $id['country'] = '16'; $id['lang'] = '1'; $id['currency'] = '1'; $id['carrier'] = '3'; $product['id'] = '1'; $product['price'] = '399'; $shipping = '117'; include ("../_presta/config/settings.inc.php"); // nastavení databáze prestashopu (jen kvůli Cart Rules) if ($_GET['pf_cart_rule_free_gift'] == 'true') $_GET['pf_quantity']++; $product['total'] = $product['price'] * $_GET['pf_quantity']; //----------------- // CREATE/UPDATE Customer and Address $xml = $webService->get(array('resource' => 'customers', 'filter[email]' => $_GET['pf_email'], 'display' => '[id]', 'limit' => '1')); if ($id['customer'] = $xml->customers->customer->id){ // If e-mail registered UPDATE (Customer and Address) $xml = $webService->get(array('resource' => 'customers', 'id' => $id['customer'])); // UPDATE Customer $xml->customer->firstname = $_GET['pf_firstname']; $xml->customer->lastname = $_GET['pf_lastname']; $xml = $webService->edit(array('resource' => 'customers', 'id' => $id['customer'], 'putXml' => $xml->asXML())); $xml = $webService->get(array('resource' => 'addresses', 'filter[id_customer]' => '['.$id['customer'].']', 'display' => '[id]', 'limit' => '1')); $id['address'] = $xml->addresses->address->id; $xml = $webService->get(array('resource' => 'addresses', 'id' => $id['address'])); // UPDATE Address $xml->address->firstname = $_GET['pf_firstname']; $xml->address->lastname = $_GET['pf_lastname']; $xml->address->address1 = $_GET['pf_address1']; $xml->address->postcode = $_GET['pf_postcode']; $xml->address->city = $_GET['pf_city']; $xml->address->phone = $_GET['pf_phone']; $xml->address->id_country = $id['country']; $xml = $webService->edit(array('resource' => 'addresses', 'id' => $id['address'], 'putXml' => $xml->asXML())); } else { // If e-mail NOT registered CREATE (Customer and Address) $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/customers?schema=blank')); // CREATE Customer $xml->customer->firstname = $_GET['pf_firstname']; $xml->customer->lastname = $_GET['pf_lastname']; $xml->customer->email = $_GET['pf_email']; $xml->customer->newsletter = '1'; $xml->customer->optin = '1'; $xml->customer->active = '1'; $xml->customer->associations->groups->group->id = '3'; $xml = $webService->add(array('resource' => 'customers', 'postXml' => $xml->asXML())); $id['customer'] = $xml->customer->id; // ID of created customer $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/addresses?schema=blank')); // CREATE Address $xml->address->id_customer = $id['customer']; $xml->address->firstname = $_GET['pf_firstname']; $xml->address->lastname = $_GET['pf_lastname']; $xml->address->address1 = $_GET['pf_address1']; $xml->address->postcode = $_GET['pf_postcode']; $xml->address->city = $_GET['pf_city']; $xml->address->phone = $_GET['pf_phone']; $xml->address->id_country = $id['country']; $xml->address->alias = '-'; $xml = $webService->add(array('resource' => 'addresses', 'postXml' => $xml->asXML())); $id['address'] = $xml->address->id; // ID of created address } //------------- // CREATE Cart $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/carts?schema=blank')); $xml->cart->id_customer = $id['customer']; $xml->cart->id_address_delivery = $id['address']; $xml->cart->id_address_invoice = $id['address']; $xml->cart->id_currency = $id['currency']; $xml->cart->id_lang = $id['lang']; $xml->cart->id_carrier = $id['carrier']; $xml->cart->associations->cart_rows->cart_row->id_product = $product['id']; $xml->cart->associations->cart_rows->cart_row->quantity = $_GET['pf_quantity']; $xml = $webService->add(array('resource' => 'carts', 'postXml' => $xml->asXML())); $id['cart'] = $xml->cart->id; // ID of created cart //--------------- // SET Cart rules $pdo = new PDO("mysql:dbname="._DB_NAME_.";host="._DB_SERVER_, _DB_USER_, _DB_PASSWD_); $pdo->exec("set names utf8"); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $query = $pdo->prepare("INSERT into "._DB_PREFIX_."cart_cart_rule (id_cart, id_cart_rule) VALUES(?, ?)"); unset($pdo); $discounts = 0; if ($_GET['pf_cart_rule_free_shipping'] == 'true'){ $query->execute(array($id['cart'], "1")); $shipping = 0; } if ($_GET['pf_cart_rule_free_gift'] == 'true'){ $query->execute(array($id['cart'], "2")); $discounts += 399; } if ($_GET['pf_cart_rule_discount_code'] == 'true'){ $query->execute(array($id['cart'], "3")); $discounts += 80; } //-------------- // CREATE Order $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=blank')); $xml->order->id_customer = $id['customer']; $xml->order->id_address_delivery = $id['address']; $xml->order->id_address_invoice = $id['address']; $xml->order->id_cart = $id['cart']; $xml->order->id_currency = $id['currency']; $xml->order->id_lang = $id['lang']; $xml->order->id_carrier = $id['carrier']; $xml->order->payment = 'Dobírka'; $xml->order->module = 'cashondelivery'; $xml->order->total_discounts = $discounts; $xml->order->total_paid = $product['total'] + $shipping - $discounts; $xml->order->total_paid_real = '0'; $xml->order->total_products = $product['total']; $xml->order->total_products_wt = $product['total']; $xml->order->conversion_rate = '1'; $xml->order->associations->order_rows->order_row->product_id = $product['id']; $xml->order->associations->order_rows->order_row->product_quantity = $_GET['pf_quantity']; $xml = $webService->add(array('resource' => 'orders', 'postXml' => $xml->asXML())); $id['order'] = $xml->order->id; // ID of created order //-------------- // CHANGE Order State $xml = $webService->get(array('resource' => 'orders', 'id' => $id['order'])); $xml->order->current_state = '3'; $xml = $webService->edit(array('resource' => 'orders', 'id' => $id['order'], 'putXml' => $xml->asXML())); //-------------- // THANK YOU! header('Location: ../dekujeme.php'); exit; ?>
  2. Kdyby měl někdo stejný problém, vyřešeno zde: https://www.prestashop.com/forums/topic/464511-add-cart-rule-via-webservice-to-order-api/
  3. It's very nice piece of code, thank you for share it. I have my "stupid newbee" way for learning how-it-works. This working fine for me. Perhaps it may be useful for you. <?php header('Content-type: text/html; charset=utf-8'); // POST Data simulation {for testing} $_POST['firstname'] = 'Firstname'; $_POST['lastname'] = 'Lastname'; $_POST['address1'] = 'MyStreet 321'; $_POST['postcode'] = '654321'; $_POST['city'] = 'MyCity'; $_POST['email'] = '[email protected]'; $_POST['phone'] = '987654321'; $_POST['quantity'] = '1'; // SETings define('DEBUG', true); define('PS_SHOP_PATH', 'http://127.0.0.1/_presta'); define('PS_WS_AUTH_KEY', 'QRDL6DG7P7RMU26UT5T1GWIQC43MX2TV'); require_once('./PSWebServiceLibrary.php'); $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); $id['country'] = '1'; $id['lang'] = '2'; $id['currency'] = '1'; $id['carrier'] = '6'; $product['id'] = '1'; $product['price'] = '399'; $product['total'] = $product['price'] * $_POST['quantity']; // CREATE Customer $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/customers?schema=blank')); $xml->customer->firstname = $_POST['firstname']; $xml->customer->lastname = $_POST['lastname']; $xml->customer->email = $_POST['email']; $xml->customer->newsletter = '1'; $xml->customer->optin = '1'; $xml->customer->active = '1'; $opt = array('resource' => 'customers'); $opt['postXml'] = $xml->asXML(); $xml = $webService->add($opt); // ID of created customer $id['customer'] = $xml->customer->id; // CREATE Address $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/addresses?schema=blank')); $xml->address->id_customer = $id['customer']; $xml->address->firstname = $_POST['firstname']; $xml->address->lastname = $_POST['lastname']; $xml->address->address1 = $_POST['address1']; $xml->address->postcode = $_POST['postcode']; $xml->address->city = $_POST['city']; $xml->address->phone = $_POST['phone']; $xml->address->id_country = $id['country']; $xml->address->alias = '-'; $opt = array('resource' => 'addresses'); $opt['postXml'] = $xml->asXML(); $xml = $webService->add($opt); // ID of created address $id['address'] = $xml->address->id; // CREATE Cart $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/carts?schema=blank')); $xml->cart->id_customer = $id['customer']; $xml->cart->id_address_delivery = $id['address']; $xml->cart->id_address_invoice = $id['address']; $xml->cart->id_currency = $id['currency']; $xml->cart->id_lang = $id['lang']; $xml->cart->id_carrier = $id['carrier']; $xml->cart->associations->cart_rows->cart_row->id_product = $product['id']; $xml->cart->associations->cart_rows->cart_row->quantity = $_POST['quantity']; $opt = array('resource' => 'carts'); $opt['postXml'] = $xml->asXML(); $xml = $webService->add($opt); // ID of created cart $id['cart'] = $xml->cart->id; // CREATE Order $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=blank')); $xml->order->id_customer = $id['customer']; $xml->order->id_address_delivery = $id['address']; $xml->order->id_address_invoice = $id['address']; $xml->order->id_cart = $id['cart']; $xml->order->id_currency = $id['currency']; $xml->order->id_lang = $id['lang']; $xml->order->id_carrier = $id['carrier']; $xml->order->payment = 'Cash on delivery'; $xml->order->module = 'cashondelivery'; $xml->order->total_paid = $product['total']; $xml->order->total_paid_real = '0'; $xml->order->total_products = $product['total']; $xml->order->total_products_wt = $product['total']; $xml->order->conversion_rate = '1'; $xml->order->associations->order_rows->order_row->product_id = $product['id']; $xml->order->associations->order_rows->order_row->product_quantity = $_POST['quantity']; $opt = array('resource' => 'orders'); $opt['postXml'] = $xml->asXML(); $xml = $webService->add($opt); ?> It needs yet something like if (email exist) update customer and address else create customer and address and other things for production use, it's really only for learning.
  4. Thanks much again, it's very helpful for me.
  5. Thanks much for fast reply. I'm not sure, if I understand good (sorry, it's my bad english). Do you create new cart via API (webservice), then write remotely direct to database (ps_cart_cart_rule) row with association cart-id -> cart-rule-id and after that you create new order (again via API)?
  6. Hi, did you find any solution, PLEASE, or anyone? I have same problem, create succesfull order (new customer->new address->new cart->new order) in Prestashop (via webservice) from my external one-product microstore (order form), it works well, but I need apply some discounts (2pcs=free shipping, 4pcs=gift, discount vouchers) and it not works, cart rules is not applied for order created via webservice. In webservice XML for creating order are items total_shipping and total_discounts, how it works? When I send any numbers in this items, Prestashop disregard it. (sorry for my bad english)
  7. Ahoj, mám prosbu, najde se někdo, kdo se vyzná v API Prestashopu? Potřebuju do Presty vkládat objednávky z externího, jednoproduktového mikroshopu (objednávkového formuláře). Napsal jsem si jednoduchý skript, který přes API vytvoří v Prestashopu zákazníka, přiřadí mu adresu, vytvoří košík a z něj následně objednávku, funguje to bezvadně ... ALE ... Potřeboval bych do toho zahrnout nějaké slevy a to se mi vůbec nedaří. Jednak poštovné zdarma od dvou kusů, druhak ke čtyřem pátý zdarma a třeťak možnost zadat slevový kód (kupón na pevnou částku). To vše jde snadno nastavit v "pravidlech pro košík", bohužel se tato pravidla do objednávky vytvořené přes Webservice nepromítnou (když objednám přímo v prestashopu, je vše OK). V XML pro komunikaci s API (/api/orders?schema=synopsis) jsou zajímavé položky total_shipping a total_discounts, ale ať tam při tvorbě objednávky napíšu cokoliv, Presta na to vůbec nebere ohled a přiřadí poštovné vlastní, slevu si vnutit nenechá ... nemáte někdo tušení, jak tyto položky fungují a zda by se nechaly nějak použít, případně jakýkoliv jiný nápad, jak to vyřešit? Předem moc díky, nějak jsem se na tom nepříjemně seknul a nevím co dál ...
  8. Pročetl jsem toto vlákno a vůbec nechápu, co to mělo být ze strany GoPay s tím nekonečným vývojem modulu pro PS1.5, který stejně nakonec nějak nedopadl. Na PS1.6 mi naprosto bezchybně funguje jejich modul 1.9 pro PS1.4 s touto drobounkou úpravou (dva řádky kódu). Jak už tu někdo psal, štvaly mě taky ty nesmyslné názvy načítané přímo z GoPay serveru (kdo má sakra vědět, že "GP WebPay" je platba kartou), Toto jsem pořešil v gopay.php pár řádky s "překladem": for ($i = 0; $i < count($paymentMethodList); $i++) { if ($preconfMethod == $paymentMethodList[$i]->code) { $param = "&paymentChannel=".$paymentMethodList[$i]->code; } if (Configuration::get($paymentMethodList[$i]->code) == "1") { if ($paymentMethodList[$i]->paymentMethod == "GP WebPay") $paymentMethodList[$i]->metoda = "platební kartou"; if ($paymentMethodList[$i]->paymentMethod == "ePlatby") $paymentMethodList[$i]->metoda = "on-line převodem z Raiffeisenbank"; if ($paymentMethodList[$i]->paymentMethod == "Mojeplatba") $paymentMethodList[$i]->metoda = "on-line převodem z Komerční banky"; if ($paymentMethodList[$i]->paymentMethod == "mPeníze") $paymentMethodList[$i]->metoda = "on-line převodem z mBank"; if ($paymentMethodList[$i]->paymentMethod == "Fio banka") $paymentMethodList[$i]->metoda = "on-line převodem z Fio banky"; $paymentMethods[] = array('metoda' => $paymentMethodList[$i]->metoda, 'title' => $paymentMethodList[$i]->paymentMethod, 'logo' => $paymentMethodList[$i]->logo, 'code' => $paymentMethodList[$i]->code); } } a pak v gopay_multi.tpl volám samozřejmě {$item.metoda} místo {$item.title}. Co se mi ale hodně nelíbí a taky tu už bylo zmíněno, že objednávka se uzavírá již v momentě přesměrování na bránu a nikoliv až po zaplacení. Neřešil (nevyřešil) jste to někdo? Pochopil jsem tu, že PrestaCS.cz to má stejně, co Presta-modul.shopmk? A co identifikace platby (variabilní symbol) pomocí $order->reference namísto $order->id? Na tom právě dělám, máte to na těch placených modulech uživatelsky nastavitelné?
  9. Ještě jsem si uvědomil, že po publikování toho kódu jsem narazil na drobný bug, totiž že pokud zákazník vybere pobočku uloženky a posléze se rozhodne využít jinou dopravu, třeba obchodní balík, vypíše se "Obchodní balík - POBOČKA ULOŽENKY". Úprava je jednoduchá: $pobocka_shortcut = Context::getContext()->cookie->ulozenka; $local = _PS_MODULE_DIR_.'ulozenka/ulozenka.xml'; $xml= simplexml_load_file($local); foreach($xml->branch as $pobocka) if (StrPos (" " . $carrier->name, "Osobní") && $pobocka->shortcut == $pobocka_shortcut) $pobocka_name = ' - '.$pobocka->name; $template_vars = array( '{pobocka}' => $pobocka_name, ...
  10. Modul Zásilkovny neznám, ale dle toho jak všichni od sebe vzájemně vykrádají, možná bude fungovat podobně jako modul Uloženky, kde jsem totéž řešil před pár dny a vyřešil takto - http://forum.c4.cz/prestashop-1-6-upozorneni-emailem-pobocka-ulozenky-t5044.html MERLIN, LIQUA.cz
  11. Here - http://www.prestashop.com/forums/topic/323576-solved-slider-module/?p=1637376 With deleted themes/default-bootstrap/modules/homeslider/homeslider.tpl it works EDIT: only DEL in this file this string {if isset($slide.size) && $slide.size} {$slide.size}{else} width="100%" height="100%"{/if}
  12. Same problem with IE8 http://www.liqua.cz/ any idea?
  13. Now I change letters references to numbers globaly for all PrestaShop (strtoupper(Tools::passwdGen(9, 'NO_NUMERIC')); to strtoupper(Tools::passwdGen(9, 'NUMERIC')); in classes/order/Order.php) and think is SOLVED for me.
  14. Hello guys, i need make own extra_mail_var from order-reference in function __construct() of bankwire.php Something as: public function __construct() { $reference = HOW TO GET IT HERE?; if (isset($reference) && !empty($reference)){ $a = array ( "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ); $b = array ( "1", "2", "3", "4", "5", "6", "7", "8", "9", "1", "2", "3", "4", "5", "6", "7", "8", "9", "1", "2", "3", "4", "5", "6", "7", "8" ); $reference_number = str_replace($a,$b,$reference); } $this->extra_mail_vars = array( '{reference_number}' => $reference_number, '{bankwire_owner}' => Configuration::get('BANK_WIRE_OWNER'), '{bankwire_details}' => nl2br(Configuration::get('BANK_WIRE_DETAILS')), '{bankwire_address}' => nl2br(Configuration::get('BANK_WIRE_ADDRESS')) ); } } How to get order_reference (order_name) on this place? I try $order->reference, $params['objOrder']->reference, $order->getUniqReference(), nothing works PLEASE help ... (and sorry for my bad english).
  15. Tak to padá v souboru ulozenka-ajax.php na řádcích: if($instance::isFreeShipping(Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS))) a $retval['version'] = $instance::getVersion(); Pro sebe jsem soubor pro PS 1.6 provizorně upravil (ořezal) takto: <?php include(dirname(__FILE__).'/../../config/config.inc.php'); include(dirname(__FILE__).'/../../init.php'); $val = Tools::getValue('selpobocka'); $retval['refresh'] = 1; // OPC=1 else 0 if(strlen($val) && strlen(Context::getContext()->cookie->ulozenka)) { $retval['refresh'] = 0; } $instance = Module::getInstanceByName('ulozenka'); Context::getContext()->cookie->ulozenka = $val; $retval['platba'] = $instance->ajax_getPaymentMethods(); if($val && strlen($val)) { $retval['allow'] = 1; } else { $retval['allow'] = 0; } $retval['opc'] = (int)Configuration::get('PS_ORDER_PROCESS_TYPE'); $retval['version'] = 160; die(json_encode($retval)); ?> možná to někomu pomůže. Upozorňuji, že nebude fungovat, používáte-li různé ceny pro různá odběrní místa, ale máte-li pro celou uloženku jen jednu defaultní cenu (což asi většina), tak ajax v košíku zdá se konečně šlape jak má ... uff
×
×
  • Create New...