Bigcommerce API Tracking Number Create PHP - api

I am trying to update the tracking number of an order in Bigcommerce using the API. This is the code I am using:
//update BC of order status
$filter = array('status_id' => 2);
$order_status_update = BigCommerce::updateResource('/orders/' . 105, $filter);
$order = Bigcommerce::getOrder(105);
foreach($order->products as $shipment)
{
$filter = array(
'order_address_id' => $shipment->order_address_id,
'items'=> array(
'order_product_id' => $shipment->product_id,
'quantity' => $shipment->quantity
),
'tracking_number' => 'tracking number'
);
$add_tracking = BigCommerce::createResource('/orders/105/shipments', $filter);
var_dump($add_tracking);
}
I have followed the instructions from here:
https://developer.bigcommerce.com/api/stores/v2/orders/shipments#list-shipments
BigCommerce Uploading Tracking Numbers
But I can't seem to get it to work. Can someone help?
In advance, thanks for your help!
Akshay

The payload for creating a shipment is invalid due to the items field needing to be formatted as an object array and the use of the product_id as opposed to the ID of the product within the order.
The code provided is attempting to create one shipment per product in the order, is this intended? Ideally you would ship all items in one shipment, which is why the items field is meant to be an array of product objects.
Additionally, by creating a shipment for an order the order status will automatically change to "Shipped", so the first PUT request is unnecessary.
If you were trying to create a single shipment per order and are assuming no orders will have multiple addresses then this code should work.
$order = Bigcommerce::getOrder(105);
$filter = array(
'order_address_id' => $order->shipping_addresses[0]->id,
'tracking_number' => '123456'
);
foreach($order->products as $product) {
$items[] = array(
'order_product_id' => $product->id,
'quantity' => $product->quantity
);
}
$filter['items'] => $items;
$add_tracking = BigCommerce::createResource('/orders/105/shipments', $filter);
var_dump($add_tracking);

Related

Find Payment links by the Price ID

I created Stripe products, and prices and added payment links to each of them. I am going to use these Payment Links in the future, show them on the site, etc. The PHP backend pulls products, prices, and payment links and shows a pretty formatted picture for the user.
I successfully get products and prices. I didn't find how the PaymentLink API can seek payment links by the price ID. I looked inside the Stripe dashboard and found that it requests payment links in the following way.
https://dashboard.stripe.com/v1/payment_links?include_only[]=data.id&price=price_1MWn4sEnbft6LZBGeHuaLVwf&active=true&limit=2
You can see that it passes the "price" parameter. In the same way, I want to find payment links.
My code
<?php
require_once __DIR__.'/../vendor/autoload.php';
$data = [];// Collected data
$stripe
= new \Stripe\StripeClient('sk_test_');
$products = $stripe->products->all([
'active' => true,
'limit' => 100
]);
foreach ($products as $product) {
$prices = $stripe->prices->all([
'active' => true,
'product' => $product->id,
'limit' => 100,
]);
foreach ($prices as $price) {
$payment_links = $stripe->paymentLinks->all([
'limit' => 100,
// Stripe doesn't have such an option.
//'price' => $price->id
]);
}
// Put found info into the $data var
}
print_r($data);
There is no direct way of searching for PaymentLinks with a certain price ID as you mentioned. The only way is to retrieve a Payment Link's line_items and search whether an item contains the price you're searching for.

Prestashop Add custom column called "number of products", displaying quantity ordered from "ps_order" table

I am trying to find a way to display product ordered quantity in Orders Page, in back-end of a Prestashop v.1.6.1.9 installation.
I already managed to add 2 custom columns by overriding AdminOrdersController.php. I have added phone_mobile and custom notes in this manner:
$this->fields_list['phone_mobile'] = array(
'title' => $this->l('Phone Number')
);
$this->fields_list['note'] = array(
'title' => $this->l('Notes')
);
Any way I can override this file to show the quantity ordered?
First of all let me clear one thing; quantity ordered is not getting stored in {DB_PREFIX}order table; it is stored in {DB_PREFIX}order_detail table.
To add total_qty total quantities ordered you need to get quantity from {DB_PREFIX}order_detail table and to achieve this you can do below things in your override.
<?php
/**
* #override AdminOrdersController
*/
class AdminOrdersController extends AdminOrdersControllerCore
{
public function __construct()
{
parent::__construct();
$this->_select .= ', (SELECT SUM(od.product_quantity) FROM `'._DB_PREFIX_.'order_detail` od WHERE od.id_order = a.id_order GROUP BY od.id_order) as total_qty';
$this->fields_list = array_merge($this->fields_list, array(
'total_qty' => array(
'title' => $this->l('Number of products'),
'havingFilter' => true,
),
));
}
}
You can add your fields like phone_mobile and custom_notes accordingly.
Hope it helps!

Pardot API: Add new prospect to certain list

$prospectData = array(
'user_key' => $user_key,
'api_key' => $api_key,
'first_name' => $firstName,
'last_name' => $lastName,
'city' => $city,
'state' => $state,
'comments' => $comments
);
callPardotApi('https://pi.pardot.com/api/prospect/version/4/do/create/email/'.$email, $prospectData);
I'm able to create a new prospect with a form that I have. It inserts all the data I supplied it (name, city, state, etc), but I need to also add this prospect to a list.
I tried adding to my $prospectData things like list => '1234' or "list_id" => '1234', but that doesn't seem to be working.
Is this possible to do? I know I can assign a prospect to a list via another api route using their ID, but I need this prospect to be added immediately upon form submit
Well it's not exactly ideal, but I had to do a new api call after creating the user.
$addprospect = callPardotApi('https://pi.pardot.com/api/prospect/version/4/do/create/email/'.$email, $prospectData);
$addprospectxml = new SimpleXMLElement($addprospect);
$id = $addprospectxml->prospect->id;
$listData = array(
'user_key' => $user_key,
'api_key' => $api_key,
'list_32106' => "1"
);
$updateProspect = callPardotApi('https://pi.pardot.com/api/prospect/version/4/do/update/id/'.(String)$id[0], $listData);
When creating a prospect, it will return XML with the newly crated prospect's ID. that ID can be used in a new api update call where you can set the list.

Shopify API Updating Fulfillments

I am writing a private app in Shopify with PHP. I have been able to get most of the other access to the json data, however, I am having trouble with Fulfillments - specifically updating a single line-item.
I am using the api-skeleton (phpish)?
Here is my code (the process as described seems so simple):
$orderid = "1350520065";
$itemid = "2338134657";
$quantity = 1;
$arguments = array(
'fulfillment' => array(
'tracking_number' => null,
'notify_customer' => true,
'line_items' => array(array('id' => $itemid, 'quantity' => 1))
)
);
$response = $shopify('POST /admin/orders/' . $orderid . '/fulfillments.json', $arguments);
I am getting [line_items] => Required parameter missing or invalid.
Any help would be appreciated.
Skip the line items unless you are doing a partial fulfillment. If you are, then obviously you need a quantity. You forgot that it seems, hence your error of missing parameter.
Add a header 'Content-Type:application/json' to your POST. That worked for me.

Restricting a category for a certain country in Prestashop 1.5

I need to restrict a category to a set of countries in Prestashop 1.5.
This restriction would prevent the shipping of a product belonging to such a category; as such, the users would still be able to see the products but they would not be able to buy them.
Ideally, I wanted to develop a module that would insert a list of countries (checkbox style, as in the Modules -> Payment page (AdminPayment)) inside a category's edit page, but I haven't been able to do so.
Why can't i simply paste the following code inside the renderForm() function?
Only the description is visible if i do so...
array(
'items' =>Country::getCountries(Context::getContext()->language->id),
'title' => $this->l('Country restrictions'),
'desc' => $this->l('Please mark the checkbox(es) for the country or countries for which you want to block the shipping.'),
'name_id' => 'country',
'identifier' => 'id_country',
'icon' => 'world',
),
EDIT:
I managed to get the list of countries working:
array(
'type' => 'checkbox',
'label' => $this->l('Restricted Countries').':',
'class' => 'sel_country',
'name' => 'restricted_countries',
'values' => array(
'query' => Country::getCountries(Context::getContext()->language->id),
'id' => 'id_country',
'name' => 'name'
),
'desc' => $this->l('Mark all the countries you want to block the selling to. The restrictions will always be applied to every subcategory as well')
),
Now, I can save these values by checking if the value "submitAddcategory" is being submitted in the postProcess function and by running an insert query there. Similarly, I can also load the IDs of the blocked countries from the database, but how can I tick the respective select boxes in the list of countries?
My initial "quick and dirty" idea was to use jQuery selectors inside a document.ready(), but the code gets inserted before everything else and, as such, it won't work because jQuery isn't even loaded yet.
How can this be done?
Cheers
I solved it by using the following code right before the end of the renderForm() function.
The Pièce de résistance was $this->fields_value, as sadly I didn't known of its existence.
public function getRestrictedCountries($obj)
{
// Loading blacklisted countries
$country = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT id_country
FROM `'._DB_PREFIX_.'category_country_restriction`
WHERE id_category = ' . (int)Tools::getValue('id_category') . ';');
$blacklisted_countries = array();
if (is_array($country))
foreach ($country as $cnt)
$blacklisted_countries[] = $cnt['id_country'];
// Global country list
$c_todos = Country::getCountries(Context::getContext()->language->id);
// Crossmatching everything
foreach ($c_todos as $c)
$this->fields_value['restricted_countries_'.$c['id_country']] = Tools::getValue('restricted_countries_'.$c['id_country'], (in_array($c['id_country'], $blacklisted_countries)));
}
PS: The table I am reading from is basically an associative table between 'category' and 'country'