Bigcommerce API getOrders() returns empty array - api

There is already a question posted on this topic, but no answer that works for me.
Bigcommerce PHP API - No data returned
I can connect to the online store from my PHP code, but GetOrders() returns an empty array
A json_encode gives me [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
getOrdersCount() returns 47317, so I know there are orders in there.
Any ideas?
Thanks. Here's my code:
<?php
require '...../bigcommerce.php';
use Bigcommerce\Api\Client as Bigcommerce;
Bigcommerce::configure(array(
'store_url' => 'https://store-xxxx.mybigcommerce.com',
'username' => 'xxxxx',
'api_key' => 'xxxxx'
));
Bigcommerce::setCipher('RC4-SHA');
Bigcommerce::verifyPeer(false);
$count = Bigcommerce::getOrdersCount();
echo 'number of orders:' . $count;
$orders = Bigcommerce::getOrders();
foreach($orders as $order) {
echo $order->name;
echo $order->price;
}
?>

Your problem is that "name" and "price" are not fields that belong to orders. That is why it is returning that data. For each order it is echoing empty (non existent) fields,
Instead try:
$orders = Bigcommerce::getOrders();
foreach($orders as $order) {
echo $order->id;
echo $order->total_inc_tax;
}

Related

Yii count total members and show on landing page

Hi I have an application that I would like to show total number of members on the landing page
I have tried adding
$connection = new \yii\db\Connection([
'username' => $username,
'password' => $password,
]);
$connection->open();
$users = $connection->createCommand('SELECT * FROM user')->queryAll();
but the application just throws an error :
yii\base\ErrorException: Undefined variable: connection in index.php
do I need to create the connection first and then run the command?
This is what I used in the end
<?php $users = Yii::$app->db->createCommand('SELECT COUNT(*) FROM user') ->queryScalar(); ?>
and then this to display the results
<? echo $users;?>

Wordpress orderby title using menu_order instead

I want to retrive custom post and want to sort it by title. However when i made a dump of what exact SQL request is sent, i found out the orderby is using menu_order instead of title
Here's the code:
$args=array(
'post_type' => 'custom_post',
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => '-1',
);
Heres the dump
"SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'custom_post' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.menu_order ASC "
Hence when i retrive the custom posts, its not in the order i want it to be.
Your help is appreciated
You can create new WP_Query instance to achieve the exact expected result.
<?php
$args = array(
'post_type' => 'custom_post_type',
'order' => 'ASC',
'orderby' => 'title',
);
$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) :
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<div class="smal-sec">
<h3><?php the_title();?></h3>
<?php the_content();?>
</div>
<?php
endwhile;
endif;
wp_reset_query(); // Restore global post data stomped by the_post().
?>
This query will help you to display all posts order by title (A -> Z). Please make sure no such plugins are there, which is actually overwriting the WP_Query instance.

Magento Soap api get all products sku, names, short description and image

My code is working fine but take so much time for show result because i have above 1500 products.
So any one modify my code or best way to show results
$results = $proxy->catalogProductList($sessionId);
$productData = new stdClass();
$productData->additional_attributes = array('short_description','cost');
foreach($results as $value){
$results_product = $proxy->catalogProductInfo($sessionId,$value->product_id,null,$productData);
$pro_imag = $proxy->catalogProductAttributeMediaList($sessionId, $value->product_id);
echo "";
echo "".$sno++."".$value->product_id."".$value->sku."".$value->name."".$results_product->additional_attributes[0]->value."".abs($results_product->additional_attributes[1]->value)."".abs($results_product->price)." url."' width='80px' height='80px'> ";
echo "";
}
Try the following code and use magento site for easy api examples like following, example SOAP V2 (Complex Filter)
<?php
$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$complexFilter = array(
'complex_filter' => array(
array(
'key' => 'type',
'value' => array('key' => 'in', 'value' => 'simple,configurable')
)
)
);
$result = $client->catalogProductList($session, $complexFilter);
var_dump ($result);

Auth::attempt() does not return anything

I'm using laravel 4.
This is my Seeder
User::create(array(
'name' => 'Rubber Gajulu',
'username' => 'awesome',
'email' => 'awesome#awe.com',
'password' => Hash::make('awesome'),
));
And this is where I am testing the Auth::attempt() function
Route::get('testlogin',function(){
$userdata = ['email'=> 'awesome#awe.com','password'=> 'awesome'];
echo Auth::attempt($userdata);
if (Auth::attempt($userdata))
echo 'SUCCESS!';
else
echo 'FAILURE!';
});
It just returns FAILURE. The first echo does not return anything.
Your controller code is wrong. It should be this:
Route::get('testlogin',function(){
$userdata = ['email'=> 'awesome#awe.com','password'=> 'awesome'];
if (Auth::attempt($userdata))
echo 'SUCCESS!';
else
echo 'FAILURE!';
});
Otherwise in your current code you are trying to login the user twice, so the second one fails.
Check if logs/laravel.log shows any error on hitting this url.
Share that.
Okay I found my mistake
Thanks to Isabell Knauers answer
My model had
$table->string('password',32)
Data was being truncated to 32 characters. Now I changed it to
$table->string('password',100)
and everything works as intended

Accessing magento's checkout/cart using REST API

I'm trying to integrate a cart-synchronisation-solution for my rest-clients.
The goal should be that I can have the same cart wherever I access my store from.
So I'll have to first of all deliver the existing items out to the client using the authenticated api-user.
But I get stuck at the very beginning:
protected function _retrieveCollection()
{
$cart = Mage::getSingleton('checkout/cart')->getQuote();
$cart->setCustomerId($this->getApiUser()->getUserId());
$cart->setStoreId(4);
$cart->load();
return $cart->getAllItems();
}
returns an empty array even though I have products in my cart.
Anyone any hints? Have that feeling I'm totally on the wrong side...
Found a solution. Getting the quote by Customer which is the other way around worked pretty well:
Mage::app()->setCurrentStore(4);
$cart = Mage::getModel('sales/quote')->loadByCustomer($this->getApiUser()->getUserId());
$items = array();
foreach ($cart->getAllVisibleItems() as $key => $item) {
$items[] = array(
'name' => $item->getName(),
'entity_id' => $item->getProductId(),
'description' => $item->getDescription(),
'final_price_with_tax' => $item->getBasePriceInclTax(),
'qty' => $item->getQty()
);
}