How to make 2 methods, one by one Bigcommerce? - php

I have problem with bigcommerce API. When I am updating a product, or deleting all images, it works fine. But, together the methods are taking long to load and doing nothing. This is my code:
Bigcommerce_Api::configure(array(
'store_url' => $storeURL,
'username' => $APIuser,
'api_key' => $APIkey
));
Bigcommerce_Api::setCipher('RC4-SHA');
Bigcommerce_Api::verifyPeer(false);
$fields = array(
'name' => $data['title'],
'type' => 'physical',
'description' => $data['description'],
'price' => $data['price'],
'categories' => array(($catCreated ? $catID->id : $catObject[0]->fields->id)),
'availability' => 'available',
'weight' => '0.5',
'sku' => $data['sku'],
'search_keywords' => $data['tags']
);
Bigcommerce_api::updateProduct($id, $fields);
Bigcommerce_api::deleteProductImages($id);
Where is the problem? Why I can't do 2 methods one after another?
documentation: https://github.com/bigcommerce/bigcommerce-api-php

Related

Sugarcrm during Reports generation retrieve data from related fields

I am trying to retrieve data from "Opportunities" Reports.
This is my scenario: Opportunity module, field sales_person is a realated field from users module.
In Bids modules I have a relate field with opportunities.
During report generation, I am trying to retrieve the sales_person name in opportunities. But it is not listing in Bids report field_lists.
My dictionary in Bids
'opportunity_id_c' => array(
'required' => false,
'name' => 'opportunity_id_c',
'vname' => 'LBL_OPPORTUNITY_OPPORTUNITY_ID',
'type' => 'id',
'reportable' => true,
'calculated' => false,
'len' => 36,
'size' => '20',
),
'opportunity' => array(
'required' => false,
'source' => 'non-db',
'name' => 'opportunity',
'vname' => 'LBL_OPPORTUNITY',
'type' => 'relate',
'reportable' => true,
'unified_search' => false,
'merge_filter' => 'disabled',
'len' => '255',
'size' => '20',
'id_name' => 'opportunity_id_c',
'ext2' => 'Opportunities',
'module' => 'Opportunities',
'rname' => 'name',
'quicksearch' => 'enabled',
'studio' => 'visible',
),
Relationship:
$dictionary['Opportunity']['fields']['opportunities_procurements'] = [
'name' => 'opportunities_procurements',
'type' => 'link',
'relationship' => 'opportunities_procurements',
'module' => 'Procurement',
'bean_name' => 'Procurement',
'source' => 'non-db',
'vname' => '',
];
$dictionary['Opportunity']['relationships']['opportunities_procurements'] = [
'lhs_module' => 'Opportunities',
'lhs_table' => 'opportunities',
'lhs_key' => 'id',
'rhs_module' => 'Procurement',
'rhs_table' => 'procurement',
'rhs_key' => 'opportunity_id_c',
'relationship_type' => 'one-to-many',
];
This is what I tried: I tried to create a similar field opportunity in bids module named as opportunity_sales_userand in dictionary instead of 'rname' => 'name', I use 'rname' => 'sales_person', but I didn't get the data as the sales_person is related record.
I couldn't retrieve the vales in Reports.
How can I create a full relationship so I can get the sales_person value in Bids reports generation?
I am facing same problem so , i choose to write a simple SQL query
global $db;
$query = "Your Sql to get Reports";
$re = $db->query($query);
$data = '';
while ($row = $db->fetchByAssoc($re)) {
your code
}

de-dupe array of documents

I run a solr query, which returns a result set of jobs.
Some of the jobs are duplicates (but from different sources), which is decided based on if the job title, description and location are the same.
I want to loop through my result set, and combine any duplicated into one job, with that one job having multiple sources... something like:
original result:
$jobs = array(
array(
'id' => 'job1',
'title' => 'test',
'description' => 'test',
'location' => 'test',
'source' => 'source1',
),
array(
'id' => 'job2',
'title' => 'test',
'description' => 'test',
'location' => 'test',
'source' => 'source2',
),
array(
'id' => 'job3',
'title' => 'test',
'description' => 'test',
'location' => 'test',
'source' => 'source3',
),
array(
'id' => 'job4',
'title' => 'testing',
'description' => 'testing',
'location' => 'testing',
'source' => 'source1',
)
);
would become:
$jobs = array(
array(
'id' => 'job1',
'title' => 'test',
'description' => 'test',
'location' => 'test',
'source' => 'source1',
'other_sources' => array(
array(
'id' => 'job2',
'title' => 'test',
'description' => 'test',
'location' => 'test',
'source' => 'source2'
),
array(
'id' => job3,
'title' => 'test',
'description' => 'test',
'location' => 'test',
'source' => 'source3'
),
),
),
array(
'id' => 'job4',
'title' => 'testing',
'description' => 'testing',
'location' => 'testing',
'source' => 'source1'
)
);
how can I achieve this? Either in PHP or perhaps in the Solr query itself (I'm using Solarium to do my Solr querying)
How about something like this?
<?php
$result = array();
foreach ($jobs as $job) {
if (!empty($result[$job['title']])) {
$result[$job['title']]['other_sources'][] = $job;
}
else {
$result[$job['title']] = $job;
}
}
It initializes an empty array($result) and then loops through the job array. The empty array will store the jobs with the title being used as the key. If the job title does not exist in the result array, then it will add it. If the job title does exist in the job array, then it will append the job to an array inside the existing job (under the key 'other_sources')

Auth.net eCheck implementation using John Conde's AuthnetXML Class

I have an existing implementation of this class processing subscriptions by credit card but I now need to add the facility to accept payment by eCheck but I am unsure of how to change this portion of the code:
'payment' => array(
'creditCard' => array(
'cardNumber' => '4111111111111111',
'expirationDate' => '2016-08'
)
),
I have come up with the following from referencing the AIM guide pdf and AIM guide XML pdf
'payment' => array(
'bankAccount' => array( // x_method equivalent ?
'routingNumber' => '', // x_bank_aba_code equivalent ?
'accountNumber' => '', // x_bank_acct_num equivalent ?
'nameOnAccount' => '', // x_bank_acct_name equivalent ?
'bankName' => '', // x_bank_name equivalent ?
'echeckType' => 'WEB' // x_echeck_type equivalent
/*
x_bank_acct_type has no equivalent ?
*/
)
),
but there appears to be some discrepancies between the required fields?
Any pointers before I start on this would be greatly appreciated.
Looking at Authorize.Net's documentation this should work:
'payment' => array(
'bankAccount' => array(
'accountType' => '', // 'checking'
'routingNumber' => '',
'accountNumber' => '',
'nameOnAccount' => ''
)
),
Following on from John's answer this is the complete code I used to solve this for anyone finding this through a google search:
$xml->ARBCreateSubscriptionRequest(array(
'subscription' => array(
'name' => 'SubscriptionName',
'paymentSchedule' => array(
'interval' => array(
'length' => '1',
'unit' => 'months'
),
'startDate' => date('Y-m-d', time()), // Format: YYYY-MM-DD
'totalOccurrences' => '9999' // To submit a subscription with no end date (an ongoing subscription), this field must be submitted with a value of 9999
),
'amount' => $eCart1->GrandTotal(), // total monthly subscription
'payment' => array(
'bankAccount' => array(
'accountType' => ((isset($_POST["accountType"]))?$_POST["accountType"]:""), // options available are checking or businessChecking in this instance
'routingNumber' => ((isset($_POST["routingNumber"]))?$_POST["routingNumber"]:""),
'accountNumber' => ((isset($_POST["accountNumber"]))?$_POST["accountNumber"]:""),
'nameOnAccount' => ((isset($_POST["nameOnAccount"]))?$_POST["nameOnAccount"]:""),
'echeckType' => ((isset($_POST["echeckType"]))?$_POST["echeckType"]:"") // if businessChecking is chosen then 'CCD' else 'WEB'
)
),
'customer' => array(
'id' => "'".$_SESSION['clientID']."'",
'email' => "'".((isset($_POST["email"]))?$_POST["email"]:"")."'"
),
'billTo' => array(
'firstName' => "'".((isset($_POST["firstname"]))?$_POST["firstname"]:"")."'",
'lastName' => "'".((isset($_POST["lastname"]))?$_POST["lastname"]:"")."'",
'company' => "'".((isset($_POST["company"]))?$_POST["company"]:"")."'",
'address' => "'".((isset($_POST["street1"]))?$_POST["street1"]:"")."'",
'city' => "'".((isset($_POST["city"]))?$_POST["city"]:"")."'",
'state' => "'".((isset($_POST["state_province"]))?$_POST["state_province"]:"")."'",
'zip' => "'".((isset($_POST["postcode"]))?$_POST["postcode"]:"")."'"
)
)
));

iOS "corrupting" PHP Session

I have been working on a bug now that has been plaguing me for ages and it is really obscure and difficult to get to the bottom of.
The bug only affects iOS devices (iPhone/iPad)
It won't always affect a device, it seems to be random
Customers who have placed several orders fine may suddenly experience it, then when placing another order minutes later not experience it
We have seen it happen in both very old devices and newer versions of iOS
It only affects users using Safari that we have seen
Theories we have tested:
Something to do with mobile data/switching between cell towers when roaming causes the session to become corrupt. We were unable to reproduce this and customers experiencing it say it has happened while at home on WiFi
When switching between HTTP/HTTPS the session is becoming void, we made the entire site secure and it still happened
Poor code in our cart somewhere, we operate multiple brands and some are using different carts. A similar thing happens in all of them
Server misconfiguration, tried multiple servers with 4 different hosts. They configured the server in 2 instances with the same result.
The payment gateway isn't working correctly (we used to use a HPP & PayPal solution), we switched to an API solution with the same result
Somehow misconfigured product, can't be the case as the same product works fine in almost all cases, except the odd iOS ones
Below I have included a sample of what the array should look like storing the cart, and what it looks like on a corrupt iOS cart
Correct Cart
$_SESSION['cart'] = array(
'items' = array (0 => array(
'product_name' => 'Shirt',
'product_price' => '20.00',
'product_sku' => '801245',
'vat_rate' => '20.0000',
'attributes' => array(
'size' => array('value' => 'large', 'cost' => '+5'),
'qty' => array('value' => 1, 'cost' => '+0'),
'colour' => array('value' => 'blue', 'cost' => '+0'),
),
'delivery_info' => array(
'name' => 'Mr A. Tester',
'line1' => 'Street',
'line2' => 'Off another street',
'company' => 'ACME Ent.',
'postcode' => 'AA1 0AA',
'county' => 'London',
'country' => 'United Kingdom',
'date' => '2015-12-01',
),
)
),
'totals' = array (
'item' => '20.00',
'extras' => '5.00',
'delivery' => '3.00',
'blended_vat' => '20.0000',
'to_pay' => '28.00',
),
'cart_id' = 'fc5e038d38a57032085441e7fe7010b0',
'customer_id' = '102145',
'order_status' = 'Pending',
'paid' = false,
)
Corrupt iOS Cart
$_SESSION['cart'] = array(
'items' = array (
'attributes' => array(
'size' => array('value' => 'large', 'cost' => '+5'),
'qty' => array('value' => 1, 'cost' => '+0'),
'colour' => array('value' => 'blue', 'cost' => '+0'),
),
'delivery_info' => array(
'name' => 'Mr A. Tester',
'line1' => 'Street',
'line2' => 'Off another street',
'company' => 'ACME Ent.',
'postcode' => 'AA1 0AA',
'county' => 'London',
'country' => 'United Kingdom',
'date' => '2015-12-01',
),
)
),
0 => array(
'product_name' => 'Shirt',
'product_price' => '20.00',
'product_sku' => '801245',
'vat_rate' => '20.0000',
'totals' = array (
'item' => '20.00',
'extras' => '5.00',
'delivery' => '3.00',
'blended_vat' => '20.0000',
'to_pay' => '28.00',
),
'cart_id' = 'fc5e038d38a57032085441e7fe7010b0',
'customer_id' = '102145',
'order_status' = 'Pending',
'paid' = false,
)
I would love to hear anyone's thoughts on this and any possible suggestions. As I say the cart works fine with every OS/Browser combination. It only randomly seems to affect iPhones/iPads, and could work fine on the same device several times, then not work, then work again.
It seems random as to when it won't work.

Magento: create bundle order programmatically

I have this code: http://pastebin.com/iFwyKM7G
Inside an event-observer class which executes after the customer registered. It creates an order automatically and it works for simple products. However I cannot figure out for the life of me how to make it work with Bundled product!
How can I make this work with a bundled product?
I DID IT!
I changed my code to the following:
$customer = Mage::getSingleton('customer/customer')->load($observer->getCustomer()->getId());
$session = Mage::getSingleton('adminhtml/session_quote');
$order_create_model = Mage::getSingleton('adminhtml/sales_order_create');
Mage::log($customer->debug(), null, 'toszodj_meg.log');
//$transaction = Mage::getModel('core/resource_transaction');
$storeId = $customer->getStoreId();
Mage::log($customer->getDefaultBillingAddress()->debug(), null, 'toszodj_meg.log');
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);
$session->setCustomerId((int) $customer->getId());
$session->setStoreId((int) $storeId);
$orderData = array(
'session' => array(
'customer_id' => $customer->getId(),
'store_id' => $storeId,
),
'payment' => array(
'method' => 'banktransfer',
'po_number' => (string) '-',
),
// 123456 denotes the product's ID value
'add_products' =>array(
'2' => array(
'qty' => 1,
'bundle_option' => array(
2 => 2,
1 => 1,
),
'bundle_option_qty' => array(
2 => 1,
1 => 1,
),
),
),
'order' => array(
'currency' => 'EUR',
'account' => array(
'group_id' => $customer->getGroupId(),
'email' => (string) $customer->getEmail(),
),
'comment' => array('customer_note' => 'API ORDER'),
'send_confirmation' => 1,
'shipping_method' => 'flatrate_flatrate',
'billing_address' => array(
'customer_address_id' => $customer->getDefaultBillingAddress()->getEntityId(),
'prefix' => $customer->getDefaultBillingAddress()->getPrefix(),
'firstname' => $customer->getDefaultBillingAddress()->getFirstname(),
'middlename' => $customer->getDefaultBillingAddress()->getMiddlename(),
'lastname' => $customer->getDefaultBillingAddress()->getLastname(),
'suffix' => $customer->getDefaultBillingAddress()->getSuffix(),
'company' => $customer->getDefaultBillingAddress()->getCompany(),
'street' => $customer->getDefaultBillingAddress()->getStreet(),
'city' => $customer->getDefaultBillingAddress()->getCity(),
'country_id' => $customer->getDefaultBillingAddress()->getCountryId(),
'region' => $customer->getDefaultBillingAddress()->getRegion(),
'region_id' => $customer->getDefaultBillingAddress()->getRegionId(),
'postcode' => $customer->getDefaultBillingAddress()->getPostcode(),
'telephone' => $customer->getDefaultBillingAddress()->getTelephone(),
'fax' => $customer->getDefaultBillingAddress()->getFax(),
),
'shipping_address' => array(
'customer_address_id' => $customer->getDefaultShippingAddress()->getEntityId(),
'prefix' => $customer->getDefaultShippingAddress()->getPrefix(),
'firstname' => $customer->getDefaultShippingAddress()->getFirstname(),
'middlename' => $customer->getDefaultShippingAddress()->getMiddlename(),
'lastname' => $customer->getDefaultShippingAddress()->getLastname(),
'suffix' => $customer->getDefaultShippingAddress()->getSuffix(),
'company' => $customer->getDefaultShippingAddress()->getCompany(),
'street' => $customer->getDefaultShippingAddress()->getStreet(),
'city' => $customer->getDefaultShippingAddress()->getCity(),
'country_id' => $customer->getDefaultShippingAddress()->getCountryId(),
'region' => $customer->getDefaultShippingAddress()->getRegion(),
'region_id' => $customer->getDefaultShippingAddress()->getRegionId(),
'postcode' => $customer->getDefaultShippingAddress()->getPostcode(),
'telephone' => $customer->getDefaultShippingAddress()->getTelephone(),
'fax' => $customer->getDefaultShippingAddress()->getFax(),
),
),
);
$order_create_model->importPostData($orderData['order']);
$order_create_model->getBillingAddress();
$order_create_model->setShippingAsBilling(true);
$order_create_model->addProducts($orderData['add_products']);
$order_create_model->collectShippingRates();
$order_create_model->getQuote()->getPayment()->addData($orderData['payment']);
$order_create_model
->initRuleData()
->saveQuote();
$order_create_model->getQuote()->getPayment()->addData($orderData['payment']);
$order_create_model->setPaymentData($orderData['payment']);
$order_create_model
->importPostData($orderData['order'])
->createOrder();
$session->clear();
Mage::unregister('rule_data');
Mage::log('Order Successfull', null, 'siker_bammer.log');
And it works! thought the customer doesn't get notified. which iam trying to figure out now.

Categories