Shopify send product with options on shopify - php

$productShopify = array(
"body_html" => $product->description[(int)$id_lang],
"created_at" => $date_now,
"handle" => $product->name[(int)$id_lang],
"id" => $product->id,
"images"=>array(array("src"=>$ProducDATA['image']),
// array("src"=>$imageShopify[0]),
array("src"=>$imageShopify[1])
),
"options" => array("name" => $group_name[0],array("name" => $group_name[1])),
"product_type" => $ProducDATA['Category_1'],
"published_at" => $date_now,
"published_scope" => "global",
"tags" => $Tag,
"template_suffix" => null,
"title" => $product->name[(int)$id_lang],
"variants" => array(
array(
"barcode" => $product->ean13,
"grams" => $product->weight,
"option1" => $attribute_name[0][1],
"price" => $product->price,
"sku" => $ProducDATA['manufacturer_reference'].'-1',
"title" => $product->name[(int)$id_lang],
// "id" => 808950810,
"product_id" => $product->id,
"inventory_quantity" => $product->id
),
array(
"barcode" => $product->ean13,
"grams" => $product->weight,
"option2" => $attribute_name[0][2],
"price" => $product->price,
"sku" => $ProducDATA['manufacturer_reference'].'-2',
"title" => $product->name[(int)$id_lang],
// "id" => 808950810,
"product_id" => $product->id,
"inventory_quantity" => $product->id
),
array(
"barcode" => $product->ean13,
"grams" => $product->weight,
"option1" => $attribute_name[1][1],
"price" => $product->price,
"sku" => $ProducDATA['manufacturer_reference'].'-3',
"title" => $product->name[(int)$id_lang],
// "id" => 808950810,
"product_id" => $product->id,
"inventory_quantity" => $product->id
),
array(
"barcode" => $product->ean13,
"grams" => $product->weight,
"option2" => $attribute_name[1][2],
"price" => $product->price,
"sku" => $ProducDATA['manufacturer_reference'].'-4',
"title" => $product->name[(int)$id_lang],
// "id" => 808950810,
"product_id" => $product->id,
"inventory_quantity" => $product->id
)
),
"vendor" => $ProducDATA['marque'],
);
I can not find the solution to send a product with several options on shopify, syntax error
I try everything but impossible to understand the principle if you have an idea
I can send the product on shopify with 1 option but not +
I can send the product on shopify with only 1 option but I do not start with Php be indulgent

Each of your 4 variants should have a value for both option1 and an option2. For example:
array(
"barcode" => $product->ean13,
"grams" => $product->weight,
"option1" => $attribute_name[0][1],
"option2" => $attribute_name[0][2],
"price" => $product->price,
"sku" => $ProducDATA['manufacturer_reference'].'-1',
"title" => $product->name[(int)$id_lang],
// "id" => 808950810,
"product_id" => $product->id,
"inventory_quantity" => $product->id
)
Also, you should check the response code and response body from the Shopify API. If your request fails, it will contain information that is useful in tracking down the error.

Related

'MercadoPagoException' with message 'transaction_amount attribute can't be null

I am getting an error
I want to implement payment gateway but the error is much like :
Illegal string offset 'code'
Illegal string offset 'description'
'MercadoPagoException' with message 'transaction_amount attribute can't be null
This is my array
$preference_data = array(
"items" => array(
array(
"id" => "Code",
"title" => $rest['name'],
"currency_id" => "USD",
"picture_url" =>"https://www.mercadopago.com/org-img/MP3/home/logomp3.gif",
"description" => "Description",
"category_id" => "Category",
"quantity" => 1,
"unit_price" => intval($total_price)
)
),
"payer" => array(
"name" => "APRO".$a[0],
"surname" => $a[1],
"email" => "test_user_44825516#testuser.com",
"date_created" => "2014-07-28T09:50:37.521-04:00",
"phone" => array(
"area_code" => "11",
"number" => "4444-4444"
),
"identification" => array(
"type" => "DNI",
"number" => "12345678"
),
"address" => array(
"street_name" => "Street",
"street_number" => 123,
"zip_code" => "1430"
)
),
"back_urls" => array(
"success" => "http://localhost/duncan_fooddelivery/api/success.php",
"failure" => "http://www.failure.com",
"pending" => "http://www.pending.com"
),
"auto_return" => "approved",
"payment_methods" => array(
"excluded_payment_methods" => array(
array(
"id" => "amex",
)
),
"excluded_payment_types" => array(
array(
"id" => "ticket"
)
),
"installments" => 24,
"default_payment_method_id" => null,
"default_installments" => null,
),
"shipments" => array(
"receiver_address" => array(
"zip_code" => "1430",
"street_number"=> 123,
"street_name"=> "Street",
"floor"=> 4,
"apartment"=> "C"
)
),
"token" => array (
"card_id" => NULL,
"card_number_length" => 16,
"cardholder" => array (
"identification" => array (
"number" => "11111111",
"type" => "DNI",
),
"name" => "APROARPAN BAJPAI",
),
"creation_date" => NULL,
"due_date" => NULL,
"esc" => NULL,
"expiration_month" => 6,
"expiration_year" => 2022,
"first_six_digits" => "450995",
"id" => "ad56c2e6cb4a2b17c18e632139366a7e",
"last_four_digits" => "3704",
"last_modified_date" => NULL,
"luhn_validation" => "true",
"public_key" => "TEST-1a0ffe62-165f-4e7b-b501-df15741b6d87",
"security_code_length" => 3,
"status" => "active",
"trunc_card_number" => NULL,
"used_date" => NULL,
),
"transaction_amount" => 60,
"notification_url" => "https://www.your-site.com/ipn",
"external_reference" => "Reference_1234",
"expires" => false,
"expiration_date_from" => null,
"expiration_date_to" => null,
);
I am passing "transaction_amount" => 60, But still getting same error.
Please help me I am searching from 5 Hours.
Thanks.

how to extract data from json in mysql

m trying to extract data from json in mysql:
my sample mysql query is :
I already tried using below code , but its returning null vales , But i have value in database .
In the below code column_name1 and er_trading_sales is column name and table_name is the name of the table
SELECT column_name1 as column_name1,
substring(
er_trading_sales,
locate('"C2":{"type":"label","value":"":{"m":"label","k":"(a) to registered dealers","v":"}","C3": { "type":"textbox","value":"',er_trading_sales,locate('"Trading_B_I"',er_trading_s ales))+70,
(locate('"},"C4',er_trading_sales,locate('"C2":{"type":"label","value":"":{"m":"label","k":"(a) to registered dealers","v":"}","C3":{"type":"textbox","value":"',er_trading_sales,locate('"Trading_B_I"',er_trading_sales))) - (locate('"C2":{"type":"label","value":"":{"m":"label","k":"(a) to registered dealers","v":"}","C3": {"type":"textbox","value":"',er_trading_sales,locate('"Trading_B_I"',er_trading_ sales))+70))
) as TradingAmount
from table_name
//sample json
"R10" => array(
"col_data" => array(
"CR1" => array(
"C1" => array(
"type" => "label",
"value" => "8.",
),
"C2" => array(
"type" => "complex",
"value" => array(
"m" => "label",
"k" => "Turnover of sale of goods taxable # ^d^%",
"v" => "4.5"
),
),
"C3" => array(
"type" => "textbox",
"value" => "",
"validation" => "decimal",
),
"C4" => array(
"type" => "textbox",
"value" => "",
"validation" => "decimal",
'htmlOptions' => array('readonly' => 'readonly'),
),
"C5" => array(
"type" => "",
"value" => "",
),
),
),
),
i want "value" of "C3" => array(
"type" => "textbox",
"value" => "",
"validation" => "decimal",
)

if statement in an array

I have a array I have to post (json). But the value accountNr should either be $val_nc_iban or should be NULL depending on a certain value outside this array. So how can I either echo $val_nc_iban (is a string) or NULL (not string) inside an array depending on the outside value?
$curl_post_data_nc = array(
"person" => array(
"title" => "$val_nc_persontitle",
"nationalNr" => NULL,
"firstName" => "$val_nc_personfirstname",
"lastName" => "$val_nc_personsurname",
"birthDate" => "$new_val_nc_persondob"
),
"company" => array(
"type" => "$val_nc_companytype",
"name" => "$val_nc_companyname",
"vat" => "$val_nc_companyvat",
"nace" => "$val_nc_companynace",
"website" => NULL
),
"contact" => array(
"email" => "$val_nc_personemail",
"mobile" => "$val_nc_personphone",
"telephone" => NULL
),
"contract" => array(
"referenceDate" => "$val_nc_refdate",
"startDate" => "$val_nc_startdate"
),
"payment" => array(
"paymentMethodEmail" => false,
"paymentMethodMail" => true,
"paymentInterval" => "$val_nc_paymentbilling",
"method" => "$val_nc_paymentmethod",
"accountNr" => $val_nc_result = ($val_nc_paymentmethod == 'TRANSFER') ? NULL : "$val_nc_iban"
),
"deliveryAddress" => array(
"building" => "HOUSE",
"street" => "$val_nc_personstreet",
"streetNr" => "$val_nc_personstreetnr",
"floor" => NULL,
"boxNr" => NULL,
"localityCode" => "$val_nc_personpostcode",
"localityName" => "$val_nc_personlocality"
),
"invoiceAddress" => array(
"sameAsDelivery" => false,
"building" => "HOUSE",
"street" => "$val_nc_billstreet",
"streetNr" => "$val_nc_billstreetnr",
"floor" => NULL,
"boxNr" => NULL,
"localityCode" => "$val_nc_billpostcode",
"localityName" => "$val_nc_billlocality"
),
"gasMeter" => array(
"ean" => "$val_nc_ean",
"nr" => NULL,
"type" => "gas",
"electric" => NULL,
"gas" => array(
"usage" => $val_nc_gasusage,
"formula" => "TTF103532"
)
),
Why do you put the variables in quotes? You can use their actual value in the array!
Example:
$curl_post_data_nc = array(
"person" => array(
"title" => $val_nc_persontitle,
"nationalNr" => NULL,
"firstName" => $val_nc_personfirstname,
"lastName" => $val_nc_personsurname,
"birthDate" => $new_val_nc_persondob
),
"company" => array(
"type" => $val_nc_companytype,
"name" => $val_nc_companyname,
"vat" => $val_nc_companyvat,
"nace" => $val_nc_companynace,
"website" => NULL
),
"contact" => array(
"email" => $val_nc_personemail,
"mobile" => $val_nc_personphone,
"telephone" => NULL
),
"contract" => array(
"referenceDate" => $val_nc_refdate,
"startDate" => $val_nc_startdate
),
"payment" => array(
"paymentMethodEmail" => false,
"paymentMethodMail" => true,
"paymentInterval" => $val_nc_paymentbilling,
"method" => $val_nc_paymentmethod,
"accountNr" => $val_nc_result = ($val_nc_paymentmethod == 'TRANSFER') ? NULL : $val_nc_iban
),
"deliveryAddress" => array(
"building" => "HOUSE",
"street" => $val_nc_personstreet,
"streetNr" => $val_nc_personstreetnr,
"floor" => NULL,
"boxNr" => NULL,
"localityCode" => $val_nc_personpostcode,
"localityName" => $val_nc_personlocality
),
"invoiceAddress" => array(
"sameAsDelivery" => false,
"building" => "HOUSE",
"street" => $val_nc_billstreet,
"streetNr" => $val_nc_billstreetnr,
"floor" => NULL,
"boxNr" => NULL,
"localityCode" => $val_nc_billpostcode,
"localityName" => $val_nc_billlocality
),
"gasMeter" => array(
"ean" => $val_nc_ean,
"nr" => NULL,
"type" => "gas",
"electric" => NULL,
"gas" => array(
"usage" => $val_nc_gasusage,
"formula" => "TTF103532"
)
),

Magento soap api add product with custom options value in shopping cart

I am using soap custom api for create and add product in cart. I have some custom options associated with the product.
I have to add a product in cart with custom options. I have tried it but it always gives me Error: Please specify the product required option(s).
I have implemented below mentioned two codes for this but both are not working.
$arrProducts = array(
array(
"product_id" => "26",
"qty" => 2,
"sku" => "CHEERCARDS-HAPPY BIRTHDAY-MEOW",
"quantity" => 2,
"bundle_option" => array(
"111" => "toemailid#test.com",
"112" => "fromemailid#test.com",
"110" => "QR Code",
"109" => "Simple message",
),
),
)
and
$arrProducts = array(
array(
"product_id" => "26",
"qty" => 1,
"sku" => "CHEERCARDS-HAPPY BIRTHDAY-MEOW",
"quantity" => 1,
'options' => array (
0 => array(
'key' => 111,
'value' => '1001'
),
1 => array(
'key' => 112,
'value' => '1001'
),
2 => array(
'key' => 110,
'value' => '1001'
),
3 => array(
'key' => 109,
'value' => '1001'
),
),
),
)
you don't need to to give product id and sku with quantity and qty. just try this code.
$arrProducts = array( array( "product_id" => "26", "qty" => 2, "bundle_option" => array( "111" => "toemailid#test.com", "112" => "fromemailid#test.com", "110" => "QR Code", "109" => "Simple message" ) ) );
This works for me. I hope it 'll work for you also.

XML to PHP Array?

I am trying to edit an open source PHP wrapper to export an XML.
Original:
$new_invoice = array(
array(
"Type"=>"ACCREC",
"Contact" => array(
"ContactID" => "[contact id]"
),
"Date" => "2010-04-08",
"DueDate" => "2010-04-30",
"Status" => "SUBMITTED",
"LineAmountTypes" => "Exclusive",
"LineItems"=> array(
"LineItem" => array(
array(
"Description" => "Just another test invoice",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
)
)
)
);
I've added another LineItem, so it become like this:
$new_invoice = array(
array(
"Type"=>"ACCREC",
"Contact" => array(
"ContactID" => "7937FF1D-B135-4BD0-A219-4B621EA3808C"
),
"Date" => "2010-04-08",
"DueDate" => "2010-04-30",
"Status" => "DRAFT",
"LineAmountTypes" => "Exclusive",
"LineItems"=> array(
"LineItem" => array(
array(
"Description" => "Just another test invoice",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
)
"LineItem" => array(
array(
"Description" => "Just another test invoice2",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
)
)
)
);
but I got an error that said "expecting a closing bracket )
It seems that all brackets are there so I am confused.
You've missed a comma after the first LineItem array.
Also, since your two arrays share the same key ("LineItem"), the second will overwrite the first, but that's unrelated to the syntax error.
Edit: To deal with that problem (here assuming that something like SimpleXML is in use):
"LineItems"=> array(
"LineItem" => array(
array(
"Description" => "Just another test invoice",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
),
array(
"Description" => "Just another test invoice2",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
)
)
You forgot a Comma... after the first line item...
your code should look like:
<?php
$new_invoice = array(
array(
"Type"=>"ACCREC",
"Contact" => array(
"ContactID" => "7937FF1D-B135-4BD0-A219-4B621EA3808C"
),
"Date" => "2010-04-08",
"DueDate" => "2010-04-30",
"Status" => "DRAFT",
"LineAmountTypes" => "Exclusive",
"LineItems"=> array(
"0" => array(
array(
"Description" => "Just another test invoice",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
),
"1" => array(
array(
"Description" => "Just another test invoice2",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
)
)
)
);
?>
Also your second line item is overriding the first one.
I will recommend a counter and be incrementing it after every lineitem is added...
It's the missing comma, but like others said, the second one overwrites the first. Try this instead:
$new_invoice = array(
array(
"Type"=>"ACCREC",
"Contact" => array(
"ContactID" => "7937FF1D-B135-4BD0-A219-4B621EA3808C"
),
"Date" => "2010-04-08",
"DueDate" => "2010-04-30",
"Status" => "DRAFT",
"LineAmountTypes" => "Exclusive",
"LineItems"=> array(
"LineItem" => array(
array(
"Description" => "Just another test invoice",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
),
array(
"Description" => "Just another test invoice2",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
)
)
)
);
print_r($new_invoice);
Only Comma (,) is missing in your array after first "lineitem"

Categories