I am unable to get the shipping Addresses of my customers in the 'Transacton Details' page.
It's displaying the following message.
'We have no shipping address on file'
The issue mainly happens when users use PaypalPro (Direct Payment) option.
Can anyone help me in this issue.
Note:
This is my code corresponding to the DoDirectPayment Request.
class ProAuthorizeRequest extends AbstractRequest
{
protected $action = 'Authorization';
public function getData()
{
$data = $this->getBaseData('DoDirectPayment');
$this->validate('amount', 'card');
$this->getCard()->validate();
$data['PAYMENTACTION'] = $this->action;
$data['AMT'] = $this->getAmount();
$data['CURRENCYCODE'] = $this->getCurrency();
$data['INVNUM'] = $this->getTransactionId();
$data['DESC'] = $this->getDescription();
// add credit card details
$data['ACCT'] = $this->getCard()->getNumber();
$data['CREDITCARDTYPE'] = $this->getCard()->getBrand();
$data['EXPDATE'] = $this->getCard()->getExpiryMonth().$this->getCard()->getExpiryYear();
$data['STARTDATE'] = $this->getCard()->getStartMonth().$this->getCard()->getStartYear();
$data['CVV2'] = $this->getCard()->getCvv();
$data['ISSUENUMBER'] = $this->getCard()->getIssueNumber();
$data['IPADDRESS'] = $this->getClientIp();
$data['FIRSTNAME'] = $this->getCard()->getFirstName();
$data['LASTNAME'] = $this->getCard()->getLastName();
$data['EMAIL'] = $this->getCard()->getEmail();
$data['STREET'] = $this->getCard()->getAddress1();
$data['STREET2'] = $this->getCard()->getAddress2();
$data['CITY'] = $this->getCard()->getCity();
$data['STATE'] = $this->getCard()->getState();
$data['ZIP'] = $this->getCard()->getPostcode();
$data['COUNTRYCODE'] = strtoupper($this->getCard()->getCountry());
return $data;
}
}
For DoDirectPayment you need to also include the SHIPTO variables:
public function getData()
{
$data = $this->getBaseData('DoDirectPayment');
$this->validate('amount', 'card');
$this->getCard()->validate();
$data['PAYMENTACTION'] = $this->action;
$data['AMT'] = $this->getAmount();
$data['CURRENCYCODE'] = $this->getCurrency();
$data['INVNUM'] = $this->getTransactionId();
$data['DESC'] = $this->getDescription();
// add credit card details
$data['ACCT'] = $this->getCard()->getNumber();
$data['CREDITCARDTYPE'] = $this->getCard()->getBrand();
$data['EXPDATE'] = $this->getCard()->getExpiryMonth().$this->getCard()->getExpiryYear();
$data['STARTDATE'] = $this->getCard()->getStartMonth().$this->getCard()->getStartYear();
$data['CVV2'] = $this->getCard()->getCvv();
$data['ISSUENUMBER'] = $this->getCard()->getIssueNumber();
$data['IPADDRESS'] = $this->getClientIp();
$data['FIRSTNAME'] = $this->getCard()->getFirstName();
$data['LASTNAME'] = $this->getCard()->getLastName();
$data['EMAIL'] = $this->getCard()->getEmail();
$data['STREET'] = $this->getCard()->getAddress1();
$data['STREET2'] = $this->getCard()->getAddress2();
$data['CITY'] = $this->getCard()->getCity();
$data['STATE'] = $this->getCard()->getState();
$data['ZIP'] = $this->getCard()->getPostcode();
$data['COUNTRYCODE'] = strtoupper($this->getCard()->getCountry());
//shipping information as you want displayed on transaction details. name is a single field.
$data['SHIPTONAME'] = $this->getCard()->getFirstName() . " " . $this->getCard()->getLastName();
$data['SHIPTOSTREET'] = $this->getCard()->getAddress1();
$data['SHIPTOSTREET2'] = $this->getCard()->getAddress2();
$data['SHIPTOCITY'] = $this->getCard()->getCity();
$data['SHIPTOSTATE'] = $this->getCard()->getState();
$data['SHIPTOZIP'] = $this->getCard()->getPostcode();
$data['SHIPTOCOUNTRYCODE'] = strtoupper($this->getCard()->getCountry());
return $data;
}
Related
I am getting error after saving sales and error is occurring in update product function, this function is working fine when i am updating product, but when i try to update product using edit-sales it is giving me this error.
Error
Code where error is
Picture 1 is what error i am getting after saving the edited sales..
picture 2 is code where error is occurring....
This is controller.sales ( which is calling model.edit-sales)
static public function ctrEditSale(){
if(isset($_POST["editSale"])){
/*=============================================
FORMAT PRODUCTS AND CUSTOMERS TABLES
=============================================*/
$table = "sales";
$item = "code";
$value = $_POST["editSale"];
$getSale = ModelSales::mdlShowSales($table, $item, $value);
/*=============================================
CHECK IF THERE'S ANY EDITED SALE
=============================================*/
if($_POST["productsList"] == ""){
$productsList = $getSale["products"];
$productChange = false;
}else{
$productsList = $_POST["productsList"];
$productChange = true;
}
if($productChange){
$products = json_decode($getSale["products"], true);
$totalPurchasedProducts = array();
foreach ($products as $key => $value) {
array_push($totalPurchasedProducts, $value["quantity"]);
$tableProducts = "products";
$item = "id";
$value1 = $value["id"];
$order = "id";
$getProduct = ProductsModel::mdlShowProducts($tableProducts, $item, $value1, $order);
$item1a = "sales";
$value1a = $getProduct["sales"] - $value["quantity"];
$newSales = ProductsModel::mdlUpdateProduct($tableProducts, $item1a, $value1a, $value);
$item1b = "stock";
$value1b = $value["quantity"] + $getProduct["stock"];
$stockNew = ProductsModel::mdlUpdateProduct($tableProducts, $item1b, $value1b, $value);
}
$tableCustomers = "customers";
$itemCustomer = "id";
$valueCustomer = $_POST["selectCustomer"];
$getCustomer = ModelCustomers::mdlShowCustomers($tableCustomers, $itemCustomer, $valueCustomer);
$item1a = "purchases";
$value1a = $getCustomer["purchases"] - array_sum($totalPurchasedProducts);
$customerPurchases = ModelCustomers::mdlUpdateCustomer($tableCustomers, $item1a, $value1a, $valueCustomer);
/*=============================================
UPDATE THE CUSTOMER'S PURCHASES AND REDUCE THE STOCK AND INCREMENT PRODUCT SALES
=============================================*/
$productsList_2 = json_decode($productsList, true);
$totalPurchasedProducts_2 = array();
foreach ($productsList_2 as $key => $value) {
array_push($totalPurchasedProducts_2, $value["quantity"]);
$tableProducts_2 = "products";
$item_2 = "id";
$value_2 = $value["id"];
$order = "id";
$getProduct_2 = ProductsModel::mdlShowProducts($tableProducts_2, $item_2, $value_2, $order);
$item1a_2 = "sales";
$value1a_2 = $value["quantity"] + $getProduct_2["sales"];
$newSales_2 = ProductsModel::mdlUpdateProduct($tableProducts_2, $item1a_2, $value1a_2, $value_2);
$item1b_2 = "stock";
$value1b_2 = $getProduct_2["stock"] - $value["quantity"];
$newStock_2 = ProductsModel::mdlUpdateProduct($tableProducts_2, $item1b_2, $value1b_2, $value_2);
}
$tableCustomers_2 = "customers";
$item_2 = "id";
$value_2 = $_POST["selectCustomer"];
$getCustomer_2 = ModelCustomers::mdlShowCustomers($tableCustomers_2, $item_2, $value_2);
$item1a_2 = "purchases";
$value1a_2 = array_sum($totalPurchasedProducts_2) + $getCustomer_2["purchases"];
$customerPurchases_2 = ModelCustomers::mdlUpdateCustomer($tableCustomers_2, $item1a_2, $value1a_2, $value_2);
$item1b_2 = "lastPurchase";
date_default_timezone_set('America/Bogota');
$date = date('Y-m-d');
$hour = date('H:i:s');
$value1b_2 = $date.' '.$hour;
$dateCustomer_2 = ModelCustomers::mdlUpdateCustomer($tableCustomers_2, $item1b_2, $value1b_2, $value_2);
}
/*=============================================
SAVE PURCHASE CHANGES
=============================================*/
$data = array("idSeller"=>$_POST["idSeller"],
"idCustomer"=>$_POST["selectCustomer"],
"code"=>$_POST["editSale"],
"products"=>$productsList,
"tax"=>$_POST["newTaxPrice"],
"netPrice"=>$_POST["newNetPrice"],
"totalPrice"=>$_POST["saleTotal"],
"paymentMethod"=>$_POST["listPaymentMethod"]);
$answer = ModelSales::mdleditSale($table, $data);
if($answer == "ok"){
echo'<script>
localStorage.removeItem("range");
swal({
type: "success",
title: "The sale has been edited correctly",
showConfirmButton: true,
confirmButtonText: "Close"
}).then((result) => {
if (result.value) {
window.location = "sales";
}
})
</script>';
}
}
}
above code is calling model edit-sales with data to update database
This is model edit sales method
mdl:editsale
you put in last attribute all array $value, you only need to put only id $value['id']
$item1a = "sales";
$value1a = $getProduct["sales"] - $value["quantity"];
$newSales = ProductsModel::mdlUpdateProduct($tableProducts, $item1a, $value1a, $value['id']);
$item1b = "stock";
$value1b = $value["quantity"] + $getProduct["stock"];
$stockNew = ProductsModel::mdlUpdateProduct($tableProducts, $item1b, $value1b, $value['id']);
We are building a script that makes an xml export of orders. In the export, we need to get the EAN code of the product that has been ordered. Currently we use WooCommerce to get the product info, and get the _sku from there.
However, we notice something is going wrong with our multisite setup.
When a product is ordered from site B, we sometimes are unable to get the EAN code of the ordered product, or get a wrong EAN code.
This because if we use our script and ask WooCommerce -> getOrder -> getItems, we get the product id's from site A, not site B. So when we try to get the _sku info from an ordered item, it's looking for the wrong product.
How can we make sure that with our script, it knows what _sku to take when we get our order information so that it doesn't matter which site the order came from, the order information is always correct?
function bol_2020_custom_process_order_manual($order_id) {
global $voorletters;
$order = new WC_Order( $order_id );
// $myuser_id = (int)$order->user_id;
// $user_info = get_userdata($myuser_id);
// $customer = new WC_Customer($order_id);
$items = $order->get_items();
$xml_order_id = $order_id;
$xml_ORDER_DATE = date('Y-m-d');
$xml_DELIVERY_START_DATE = '2017-09-07';
$xml_DELIVERY_END_DATE = '2017-09-08';
$xml_SUPPLIER_NAME = 'DOMAINNAME.nl';
$xml_SUPPLIER_NAME2 = '';
$xml_SUPPLIER_NAME3 = '';
$xml_SUPPLIER_STREET = '**** 71A';
$xml_SUPPLIER_ZIP = '******';
$xml_SUPPLIER_CITY = '********';
$xml_SUPPLIER_COUNTRY = 'NL';
$xml_BUYUR_NAME = get_post_meta($order_id,'_shipping_first_name',true).' '.get_post_meta($order_id,'_shipping_last_name',true);
$xml_BUYUR_NAME2 = get_post_meta($order_id,'_shipping_company',true);
$xml_BUYUR_NAME3 = '';
$xml_BUYUR_STREET = get_post_meta($order_id,'_shipping_address_1',true).' '.get_post_meta($order_id,'_shipping_address_2',true);
$xml_BUYUR_ZIP = get_post_meta($order_id,'_shipping_postcode',true);
$xml_BUYUR_CITY = get_post_meta($order_id,'_shipping_city',true);
$xml_BUYUR_COUNTRY = get_post_meta($order_id,'_shipping_country',true);
$imp = new DOMImplementation;
$dtd = $imp->createDocumentType('ORDER', '', 'openTRANS_ORDER_1_0.dtd');
$dom = $imp->createDocument("", "", $dtd);
$dom->encoding = 'UTF-8';
$root = $dom->appendChild($root = $dom->createElement('ORDER'));
$order_version = $root->appendChild($dom->createAttribute('version'));
$order_version->value = '1.0';
$order_type = $root->appendChild($dom->createAttribute('type'));
$order_type->value = 'standard';
$root->appendChild($client = $dom->createElement('ORDER_HEADER'));
$order_info = $client->appendChild($dom->createElement('ORDER_INFO'));
$order_info->appendChild($ORDER_ID = $order_info->appendChild($dom->createElement('ORDER_ID')));
$ORDER_ID->appendChild($dom->createTextNode($voorletters.$xml_order_id));
$order_info->appendChild($ALT_CUSTOMER_ORDER_ID = $order_info->appendChild($dom->createElement('ALT_CUSTOMER_ORDER_ID')));
$ALT_CUSTOMER_ORDER_ID->appendChild($dom->createTextNode(''));
$order_info->appendChild($ORDER_DATE = $order_info->appendChild($dom->createElement('ORDER_DATE')));
$ORDER_DATE->appendChild($dom->createTextNode($xml_ORDER_DATE));
$DELIVERY_DATE = $order_info->appendChild($order_info->appendChild($dom->createElement('DELIVERY_DATE')));
$DELIVERY_DATE_ATT = $DELIVERY_DATE->appendChild($dom->createAttribute('type'));
$DELIVERY_DATE_ATT->value = 'fixed';
$DELIVERY_START_DATE = $DELIVERY_DATE->appendChild($dom->createElement('DELIVERY_START_DATE'));
$DELIVERY_START_DATE->appendChild($dom->createTextNode($xml_DELIVERY_START_DATE));
$DELIVERY_END_DATE = $DELIVERY_DATE->appendChild($dom->createElement('DELIVERY_END_DATE'));
$DELIVERY_END_DATE->appendChild($dom->createTextNode($xml_DELIVERY_END_DATE));
$ORDER_PARTIES = $order_info->appendChild($order_info->appendChild($dom->createElement('ORDER_PARTIES')));
$BUYER_PARTY = $ORDER_PARTIES->appendChild($dom->createElement('BUYER_PARTY'));
$PARTY_ID = $BUYER_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID_ = $PARTY_ID->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID__ATT = $PARTY_ID_->appendChild($dom->createAttribute('type'));
$PARTY_ID__ATT->value = 'ILN';
//$PARTY_ID_->appendChild($dom->createTextNode('4317784032988'));
$PARTY_ID_->appendChild($dom->createTextNode('4317784044110'));
$SUPPLIER_PARTY = $ORDER_PARTIES->appendChild($dom->createElement('SUPPLIER_PARTY'));
$PARTY_ID = $SUPPLIER_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID_ = $PARTY_ID->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID__ATT = $PARTY_ID_->appendChild($dom->createAttribute('type'));
$PARTY_ID__ATT->value = 'ILN';
$PARTY_ID_->appendChild($dom->createTextNode('4317784000000'));
$SHIPMENT_PARTIES = $ORDER_PARTIES->appendChild($dom->createElement('SHIPMENT_PARTIES'));
$DELIVERY_PARTY = $SHIPMENT_PARTIES->appendChild($dom->createElement('DELIVERY_PARTY'));
$PARTY = $DELIVERY_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID = $PARTY->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID_ATT = $PARTY_ID->appendChild($dom->createAttribute('type'));
$PARTY_ID_ATT->value = 'supplier_specific';
$PARTY_ID->appendChild($dom->createTextNode(''));
$ADDRESS = $PARTY->appendChild($dom->createElement('ADDRESS'));
$NAME = $ADDRESS->appendChild($dom->createElement('NAME'));
$NAME->appendChild($dom->createTextNode($xml_SUPPLIER_NAME));
$NAME2 = $ADDRESS->appendChild($dom->createElement('NAME2'));
$NAME2->appendChild($dom->createTextNode($xml_SUPPLIER_NAME2));
$NAME3 = $ADDRESS->appendChild($dom->createElement('NAME3'));
$NAME3->appendChild($dom->createTextNode($xml_SUPPLIER_NAME3));
$STREET = $ADDRESS->appendChild($dom->createElement('STREET'));
$STREET->appendChild($dom->createTextNode($xml_SUPPLIER_STREET));
$ZIP = $ADDRESS->appendChild($dom->createElement('ZIP'));
$ZIP->appendChild($dom->createTextNode($xml_SUPPLIER_ZIP));
$CITY = $ADDRESS->appendChild($dom->createElement('CITY'));
$CITY->appendChild($dom->createTextNode($xml_SUPPLIER_CITY));
$COUNTRY = $ADDRESS->appendChild($dom->createElement('COUNTRY'));
$COUNTRY->appendChild($dom->createTextNode($xml_SUPPLIER_COUNTRY));
$FINAL_DELIVERY_PARTY = $SHIPMENT_PARTIES->appendChild($dom->createElement('FINAL_DELIVERY_PARTY'));
$PARTY = $FINAL_DELIVERY_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID = $PARTY->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID_ATT = $PARTY_ID->appendChild($dom->createAttribute('type'));
$PARTY_ID_ATT->value = 'buyer_specific';
$PARTY_ID->appendChild($dom->createTextNode(''));
$ADDRESS = $PARTY->appendChild($dom->createElement('ADDRESS'));
$NAME = $ADDRESS->appendChild($dom->createElement('NAME'));
$NAME->appendChild($dom->createTextNode($xml_BUYUR_NAME));
$NAME2 = $ADDRESS->appendChild($dom->createElement('NAME2'));
$NAME2->appendChild($dom->createTextNode($xml_BUYUR_NAME2));
$NAME3 = $ADDRESS->appendChild($dom->createElement('NAME3'));
$NAME3->appendChild($dom->createTextNode($xml_BUYUR_NAME3));
$STREET = $ADDRESS->appendChild($dom->createElement('STREET'));
$STREET->appendChild($dom->createTextNode($xml_BUYUR_STREET));
$ZIP = $ADDRESS->appendChild($dom->createElement('ZIP'));
$ZIP->appendChild($dom->createTextNode($xml_BUYUR_ZIP));
$CITY = $ADDRESS->appendChild($dom->createElement('CITY'));
$CITY->appendChild($dom->createTextNode($xml_BUYUR_CITY));
$COUNTRY = $ADDRESS->appendChild($dom->createElement('COUNTRY'));
$COUNTRY->appendChild($dom->createTextNode($xml_BUYUR_COUNTRY));
$PARTIAL_SHIPMENT_ALLOWED = $order_info->appendChild($order_info->appendChild($dom->createElement('PARTIAL_SHIPMENT_ALLOWED')));
$PARTIAL_SHIPMENT_ALLOWED->appendChild($dom->createTextNode('False'));
$TRANSPORT = $order_info->appendChild($order_info->appendChild($dom->createElement('TRANSPORT')));
$INCOTERM = $TRANSPORT->appendChild($dom->createElement('INCOTERM'));
$INCOTERM->appendChild($dom->createTextNode(''));
$LOCATION = $TRANSPORT->appendChild($dom->createElement('LOCATION'));
$LOCATION->appendChild($dom->createTextNode('EKD'));
$TRANSPORT_REMARK = $TRANSPORT->appendChild($dom->createElement('TRANSPORT_REMARK'));
$TRANSPORT_REMARK->appendChild($dom->createTextNode('10'));
$REMARK_GENERAL = $order_info->appendChild($order_info->appendChild($dom->createElement('REMARK')));
$REMARK_GENERAL_ = $REMARK_GENERAL->appendChild($dom->createAttribute('type'));
$REMARK_GENERAL_->value = 'general';
$REMARK_GENERAL->appendChild($dom->createTextNode('SUPERHANDIG.NL IS HÉT ADRES VOOR PROF. GEREEDSCHAP EN ACCESSOIRES!'));
$REMARK_ORDER = $order_info->appendChild($order_info->appendChild($dom->createElement('REMARK')));
$REMARK_ORDER_ = $REMARK_ORDER->appendChild($dom->createAttribute('type'));
$REMARK_ORDER_->value = 'order';
$REMARK_ORDER->appendChild($dom->createTextNode($voorletters.$xml_order_id));
$ORDER_ITEM_LIST = $root->appendChild($client = $dom->createElement('ORDER_ITEM_LIST'));
$i = 0;
foreach ($items as $item) {
$ean = get_post_meta($item['product_id'], '_sku'); // for single products
$qty = $item['qty'];
if(empty($ean[0])){
$ean = get_post_meta($item['variation_id'], '_sku'); // for variable products
}
$i++;
$ORDER_ITEM = $ORDER_ITEM_LIST->appendChild($dom->createElement('ORDER_ITEM'));
$LINE_ITEM_ID = $ORDER_ITEM->appendChild($dom->createElement('LINE_ITEM_ID'));
$LINE_ITEM_ID->appendChild($dom->createTextNode($i));
$ARTICLE_ID = $ORDER_ITEM->appendChild($dom->createElement('ARTICLE_ID'));
$SUPPLIER_AID = $ARTICLE_ID->appendChild($dom->createElement('SUPPLIER_AID'));
$SUPPLIER_AID->appendChild($dom->createTextNode(''));
$INTERNATIONAL_AID = $ARTICLE_ID->appendChild($dom->createElement('INTERNATIONAL_AID'));
$INTERNATIONAL_AID_ = $INTERNATIONAL_AID->appendChild($dom->createAttribute('type'));
$INTERNATIONAL_AID_->value = 'EAN';
$INTERNATIONAL_AID->appendChild($dom->createTextNode($ean[0]));
$BUYER_AID = $ARTICLE_ID->appendChild($dom->createElement('BUYER_AID'));
$BUYER_AID_ = $BUYER_AID->appendChild($dom->createAttribute('type'));
$BUYER_AID_->value = 'BP';
$BUYER_AID->appendChild($dom->createTextNode(''));
$BUYER_AID = $ARTICLE_ID->appendChild($dom->createElement('BUYER_AID'));
$BUYER_AID_ = $BUYER_AID->appendChild($dom->createAttribute('type'));
$BUYER_AID_->value = 'IN';
$BUYER_AID->appendChild($dom->createTextNode(''));
$DESCRIPTION_SHORT = $ARTICLE_ID->appendChild($dom->createElement('DESCRIPTION_SHORT'));
$DESCRIPTION_SHORT->appendChild($dom->createTextNode(''));
$QUANTITY = $ORDER_ITEM->appendChild($dom->createElement('QUANTITY'));
$QUANTITY->appendChild($dom->createTextNode($qty));
$ORDER_UNIT = $ORDER_ITEM->appendChild($dom->createElement('ORDER_UNIT'));
$ORDER_UNIT->appendChild($dom->createTextNode('C62'));
}
$ORDER_SUMMARY = $root->appendChild($client = $dom->createElement('ORDER_SUMMARY'));
$TOTAL_ITEM_NUM = $ORDER_SUMMARY->appendChild($dom->createElement('TOTAL_ITEM_NUM'));
$TOTAL_ITEM_NUM->appendChild($dom->createTextNode($i));
$dom->formatOutput = true;
$dom->save($_SERVER['DOCUMENT_ROOT'].'/ede_orders/xml/'.$voorletters.$xml_order_id.'.xml');
}
https://gist.github.com/webstylecenter/2491735366a70d82336512e0d0cc4e8f
When added from a third-party product to the cart. I want to change the quantity of goods in the basket. Get alert Product (........ ) is over.
if(is_array($arCartPrice)){
//if($arCartPrice['OPTIONS']['MINIMUM']>1){$QUANTITY=$arCartPrice['OPTIONS']['MINIMUM'];}else{$QUANTITY=1;}
$QUANTITY=$arCartPrice['AVAILABLE_NUM'];
$DefaultCategory = 12;
$DefaultTaxGroup = 0;
$Price = $arCartPrice['PRICE_CONVERTED'];
$PriceVAT = round($Price);
$Reference = $arCartPrice['ARTICLE'].' / '.$arCartPrice['BRAND'];
//Presta init
global $context;
if(!$context){$context = Context::getContext();}
$logged = $context->cookie->__get('logged');
$id_cart = $context->cookie->__get('id_cart');
$id_lang = $context->cookie->__get('id_lang');
$id_guest = $context->cookie->__get('id_guest');
$id_currency = $context->cookie->__get('id_currency');
// Add cart if no cart found
if (!$id_cart){
$context->cart = new Cart();
$context->cart->id_customer = $context->customer->id;
$context->cart->id_currency = $id_currency;
$context->cart->add();
if($context->cart->id){
$context->cookie->id_cart = (int)$context->cart->id;
}
$id_cart = (int)$context->cart->id;
}
$doAdd="Y";
//if(!$logged>0){$doAdd="N"; $TCore->arErrorMessages[] = 'You must be logged in to buy products';}
//if(trim($Reference)=='' OR !$Price>0 OR !$QUANTITY>0){$doAdd="N"; $TCore->arErrorMessages[] = 'Add to cart data is missing!';}
if(!$id_cart>0){$doAdd="N"; ErAdd("Your cookie <b>id_cart</b> is wrong!",1);}
if(!$id_lang>0){$doAdd="N"; ErAdd("Your cookie <b>id_lang</b> is wrong!",1);}
if($doAdd!="N"){
//Check avail. tecdoc item in Presta
$sql = 'SELECT p.`id_product`, pl.`name` FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`)
WHERE pl.`id_lang` = '.$id_lang.' AND
p.`price` = '.$Price.' AND
p.`reference` = "'.$Reference.'"
';
$arRes = Db::getInstance()->executeS($sql);
if(count($arRes)>0){
$NewTID = $arRes[0]['id_product'];
}else{
//Supplier data (for 1C integration)
$supplierName = $arCartPrice['SUPPLIER_STOCK'];
$supplierId = $suppliers = (Supplier::getIdByName($supplierName));
if (!$supplierId) {
$supplier = new Supplier();
$supplier->name = $supplierName;
$supplier->active = 1;
$supplier->add();
$supplierId = $supplier->id;
}
$obProduct = new Product(false,false,$id_lang);
$obProduct->id_category_default = $DefaultCategory;
$obProduct->unity = $arCartPrice['ADD_URL'];
$obProduct->name = $arCartPrice['ARTICLE'] .' / '.substr($arCartPrice['NAME'],0,400).' / '.$arCartPrice['BRAND'];
$obProduct->description = 'This product is created automatically by ';
$obProduct->description_short = $arCartPrice['SUPPLIER_STOCK'].' ['.$arCartPrice['DAY'].' days]';
$obProduct->price = $Price;
$obProduct->wholesale_price = $arCartPrice['PRICE'];
$obProduct->reference = $Reference;
$obProduct->link_rewrite = $arCartPrice['CPID'];
$obProduct->available_for_order = 1; //true
$obProduct->visibility = 'none';
$obProduct->is_virtual = 0;
//$obProduct->weight = round($arCartPrice['OPTIONS']['WEIGHT']/1000,2);
$obProduct->minimal_quantity = 1;
$obProduct->condition = 'used';
$obProduct->condition = 'refurbished';
$obProduct->available_now = $arCartPrice['AVAILABLE_NUM'];
$obProduct->quantity = $arCartPrice['AVAILABLE_NUM'];
//supplier
$obProduct->supplier_name = $supplierName;
$obProduct->id_supplier = $supplierId;
$obProduct->id_tax_rules_group = $DefaultTaxGroup;
//echo '<br><pre>';print_r($obProduct);echo '</pre>';die();
$obProduct->add();
if($obProduct->id>0){
$NewTID = $obProduct->id;
$obProduct->setWsCategories(Array(Array("id"=>$DefaultCategory)));
//Add image
if($arCartPrice['IMG_SRC']!='' AND $NewTID>0){
$shops = Shop::getShops(true, null, true);
$image = new Image();
$image->id_product = $NewTID;
$image->position = Image::getHighestPosition($NewTID)+1;
$image->cover = true; // or false;
if(($image->validateFields(false, true)) === true && ($image->validateFieldsLang(false, true)) === true && $image->add()){
$image->associateTo($shops);
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
if(Tools::copy($arCartPrice['IMG_SRC'], $tmpfile)){
$path = $image->getPathForCreation();
ImageManager::resize($tmpfile, $path.'.jpg');
}
unlink($tmpfile);
}
}
}else{
ErAdd("Prestashop new Item ID is false",1);
}
unset($obProduct);
}
if($NewTID>0){
//if($arCartPrice['AVAILABLE']>0){StockAvailable::setQuantity($NewTID, false, $arCartPrice['AVAILABLE']);}
StockAvailable::setQuantity($NewTID, 0, (int) $arCartPrice['AVAILABLE']);
$obCart = new Cart($id_cart);
$obCart->id_lang = $id_lang;
$obCart->id_currency = $id_currency;
if($obCart->updateQty((int)$QUANTITY=1, (int)$NewTID)){
Header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); die();
}else{
ErAdd(" Add to Cart is false. NewTID=".$NewTID,1);
}
How to fix the code so you can update the quantity of goods in your cart.
And the number of 10 pieces. 1 piece is added to the cart. I want to add more to my cart. How to implement it? When I add 2 pieces. I receive a message Product (........ ) is over..
enter image description here
First of all, after you created the product, check in the Backoffice if the quantity is well stored (If the newly created product quantity is equal with $arCartPrice['AVAILABLE_NUM'] )
Maybe you can try with enabled "Allow ordering when out of stock" .
I am using nopcommerce 3.5. I have added plugin of UPS of TransitInTime and Rate API. I want to get rates by calling UPS Rate API. I want all Rates in dropdown on page load.
So for the first I am using test application using webservices of RateWebReference and in which I get only one Rate but I want Rates for all shipping option.
Here is my code of RateWSClient.cs
RateService rate = new RateService();
RateRequest rateRequest = new RateRequest();
UPSSecurity upss = new UPSSecurity();
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = "CC....";
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = "gi..";
upssUsrNameToken.Password = "Ch..";
upss.UsernameToken = upssUsrNameToken;
rate.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "Rate" };
request.RequestOption = requestOption;
rateRequest.Request = request;
ShipmentType shipment = new ShipmentType();
ShipperType shipper = new ShipperType();
shipper.ShipperNumber = "A65V88";
RateWSSample.RateWebReference1.AddressType shipperAddress = new RateWSSample.RateWebReference1.AddressType();
String[] addressLine = { "", "", "" };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "";
shipperAddress.PostalCode = "30076";
shipperAddress.StateProvinceCode = "GA";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipment.Shipper = shipper;
ShipFromType shipFrom = new ShipFromType();
RateWSSample.RateWebReference1.AddressType shipFromAddress = new RateWSSample.RateWebReference1.AddressType();
shipFromAddress.AddressLine = addressLine;
shipFromAddress.City = "";
shipFromAddress.PostalCode = "30076";
shipFromAddress.StateProvinceCode = "GA";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipment.ShipFrom = shipFrom;
ShipToType shipTo = new ShipToType();
ShipToAddressType shipToAddress = new ShipToAddressType();
String[] addressLine1 = { "", "", "" };
shipToAddress.AddressLine = addressLine1;
shipToAddress.City = "";
shipToAddress.PostalCode = "92262";
shipToAddress.StateProvinceCode = "";
shipToAddress.CountryCode = "US";
shipTo.Address = shipToAddress;
shipment.ShipTo = shipTo;
CodeDescriptionType service = new CodeDescriptionType();
//Below code uses dummy date for reference. Please udpate as required.
service.Code = "02";
shipment.Service = service;
PackageType package = new PackageType();
PackageWeightType packageWeight = new PackageWeightType();
packageWeight.Weight = "125";
CodeDescriptionType uom = new CodeDescriptionType();
uom.Code = "LBS";
uom.Description = "pounds";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;
CodeDescriptionType packType = new CodeDescriptionType();
packType.Code = "02";
package.PackagingType = packType;
PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
//Shipping Rate Chart
// ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
//SRO.RateChartIndicator = "";
//shipment.ShipmentRatingOptions= SRO;
//rateRequest.Shipment = shipment;
ShipmentRatingOptionsType SRO = new ShipmentRatingOptionsType();
SRO.NegotiatedRatesIndicator = "";
shipment.ShipmentRatingOptions = SRO;
rateRequest.Shipment = shipment;
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
Console.WriteLine(rateRequest);
RateResponse rateResponse = rate.ProcessRate(rateRequest);
Console.WriteLine("The transaction was a " + rateResponse.Response.ResponseStatus.Description);
Console.WriteLine("Total Shipment Charges " + rateResponse.RatedShipment[0].TotalCharges.MonetaryValue + rateResponse.RatedShipment[0].TotalCharges.CurrencyCode);
Console.ReadKey();
I have resolved this questions. So If you face this kind of problem don't forget to use
String[] requestOption = { "Shop" };
in place of
String[] requestOption = { "Rate" };
Then you will get rates for all shipping options.
Customer Orders not being bound to Customer
Postby DrFeeling » Mon Jun 01, 2015 4:05 pm
Good Afternoon peeps, I'm currently developping a mobile app for opencart that will bridge both tecnologies.
Most of the stuff is already active but I have a problem regarding order histories.
So, when you purchase something, through the main site, the default template of opencart, it generates a order history, that you can see through the website (my orders) or through the admin page.
My problem is that, whenever someone purchases something from the app, the orders of that costumer arent uptaded.
Though they appear in the main admin window (the dashboard) , once you go to customer (sales -> customers -> customers) the order made by the app isnt listed in the myOrders part of that customer, making both the "my previous orders" and the order of that customer inexistent in that place, but they appear in the dashboard and the notification email is foward to the customer
Please help me, and thanks for the support :D
Only order 261 (which was made in the website) is bounded to its customer, the others arent, as you can see in the pic below
AM I missing a parameter or a validation when the checkout process happens?
http://s16.postimg.org/y2h9rg5fp/image.jpg
EDIT: My code to create a order:
public function end_order() {
if ($this->customer->isLogged() == true){
$data= array();
$datap = array();
$this->load->model('account/customer');
$this->load->model('quickcheckout/order');
$this->load->model('checkout/order');
$myArray = $_POST["formData"];
$treatedArray = array();
foreach($myArray as $value) {
$treatedArray[$value['name']] = $value['value'];
}
$email = $_POST["email"];
$delivery = $_POST["deladdress"];
$delivery = array_shift($delivery); // sobe um nivel as posiçoes do array, em vez de usar $array[0]['bla'] , usasse so $array['bla']
$data2 = array();
$data2 = $this->model_account_customer->getCustomerByEmail($email);
$Method = $_POST["PayMethod"];
$TotalCheckout = $_POST["TotalCheck"];
$IP = $_POST["IP"];
$Agent = $_POST["User"];
$Products = $_POST["Prod"];
$length = count($Products);
for ($i = 0; $i < $length; $i++) {
(int)$datap[$i]['product_id'] = $Products[$i]['Id'];
$datap[$i]['name'] = $Products[$i]['Name'];
$datap[$i]['model'] = $Products[$i]['modelo'];
(int)$datap[$i]['quantity'] = $Products[$i]['NItems'];
$datap[$i]['price'] = $Products[$i]['Preco'];
$datap[$i]['total'] = $Products[$i]['Total'];
$datap[$i]['tax'] = 0; //$Products[$i]['Tax'];
(int)$datap[$i]['reward'] = 0; //$Products[$i]['Reward'];
}
$url = $myurl;
$data['invoice_prefix'] = $this->config->get('config_invoice_prefix');
$data['store_id'] = $this->config->get('config_store_id');
$data['store_name'] = "Loja Teste";
$data['store_url'] = $url;
$data['firstname'] = $data2['firstname'] ;
$data['lastname'] = $data2['lastname'];
$data['email'] = $data2['email'];
$data['telephone'] = $data2['telephone'];
$data['fax'] = $data2['fax'];
$data['payment_firstname'] = $delivery['firstname'];
$data['payment_lastname'] = $delivery['lastname'];
$data['payment_company'] = $delivery['company'];
$data['payment_company_id'] = $delivery['company_id'];;
$data['tax_id'] = $delivery['tax_id'];
$data['payment_address_1'] = $delivery['address_1'];
$data['payment_address_2'] = $delivery['address_2'];
$data['payment_city'] = $delivery['city'];
$data['payment_postcode'] = $delivery['postcode'];
$data['payment_country'] = $delivery['country'];
$data['payment_country_id'] = $delivery['country_id'];
$data['payment_zone'] = $delivery['zone'];
$data['payment_zone_id'] = $delivery['zone_id'];
$data['payment_method'] = "Cash On Delivery";
$data['payment_code'] = 1;
$data['total'] = $TotalCheckout;
//NOTA: esta duas variaveis abaixo servem para tratar dos preços, alterar depois para quando a loja tiver opçoes de escolher preços
$data['language_id'] = (int)$this->config->get('config_language_id');
$data['accept_language'] = $this->request->server['HTTP_ACCEPT_LANGUAGE'];
$data['currency_id'] = (int)2;
$data['currency_code'] = "USD";
$data['currency_value'] = (float)1.00000000;
$data['ip'] = $IP;
$data['forwarded_ip'] = $IP;
$data['user_agent'] = $Agent;
$data['products'] = $datap;
(int)$order = $this->model_checkout_order->addOrder($data);
$this->model_checkout_order->confirm($order, 1 , $comment = '', $notify = false);
echo ("teste");
}
}