Cannot return the correct order with GetSellingManagerSaleRecord - ebay-api

I am using the eBay SDK for PHP at devbay.net.
First I am loading GetSellingManagerSoldListings, searching for SaleRecordID=129317:
$service = new TradingService();
$request = new Types\GetSellingManagerSoldListingsRequestType();
$request->Search = new Types\SellingManagerSearchType();
$request->Search->SearchType = 'SaleRecordID';
$request->Search->SearchValue = '129317';
$result = $service->GetSellingManagerSoldListings($request);
print_r($result->SaleRecord[0]);
Which gives the following response:
DTS\eBaySDK\Trading\Types\SellingManagerSoldOrderType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[SellingManagerSoldTransaction] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[TransactionID] => *removed*
[SaleRecordID] => 129242
[ItemID] => *removed*
[QuantitySold] => 1
[ItemTitle] => *removed*
[ListingType] => FixedPriceItem
[Relisted] =>
[SecondChanceOfferSent] =>
[CustomLabel] => *removed*
[SoldOn] => eBay
[ListedOn] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => eBay
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType
[property:DTS\eBaySDK\Types\UnboundType:private] => ListedOn
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => string
)
[CharityListing] =>
[OrderLineItemID] => *removed*
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[1] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[TransactionID] => *removed*
[SaleRecordID] => 129243
[ItemID] => *removed*
[QuantitySold] => 1
[ItemTitle] => *removed*
[ListingType] => FixedPriceItem
[Relisted] =>
[SecondChanceOfferSent] =>
[CustomLabel] => *removed*
[SoldOn] => eBay
[ListedOn] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => eBay
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType
[property:DTS\eBaySDK\Types\UnboundType:private] => ListedOn
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => string
)
[CharityListing] =>
[OrderLineItemID] => *removed*
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\SellingManagerSoldOrderType
[property:DTS\eBaySDK\Types\UnboundType:private] => SellingManagerSoldTransaction
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Trading\Types\SellingManagerSoldTransactionType
)
[ShippingAddress] => DTS\eBaySDK\Trading\Types\AddressType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[Name] => *removed*
[PostalCode] => 2761
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[ShippingDetails] => DTS\eBaySDK\Trading\Types\ShippingDetailsType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[ShippingType] => NotSpecified
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[TotalAmount] => DTS\eBaySDK\Trading\Types\AmountType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[currencyID] => AUD
[value] => 294.95
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[TotalQuantity] => 2
[ActualShippingCost] => DTS\eBaySDK\Trading\Types\AmountType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[currencyID] => AUD
[value] => 0
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[OrderStatus] => DTS\eBaySDK\Trading\Types\SellingManagerOrderStatusType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[CheckoutStatus] => CheckoutComplete
[PaidStatus] => PartiallyPaid
[ShippedStatus] => Shipped
[PaymentMethodUsed] => PayPal
[FeedbackSent] => 1
[TotalEmailsSent] => 3
[ShippedTime] => DateTime Object
(
[date] => 2015-04-06 21:10:09
[timezone_type] => 2
[timezone] => Z
)
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[SalePrice] => DTS\eBaySDK\Trading\Types\AmountType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[currencyID] => AUD
[value] => 589.9
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
[DaysSinceSale] => 5
[BuyerID] => *removed*
[BuyerEmail] => *removed*
[SaleRecordID] => 129317
[CreationTime] => DateTime Object
(
[date] => 2015-04-03 10:19:48
[timezone_type] => 2
[timezone] => Z
)
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
Next I want to load the related GetSellingManagerSaleRecord. The problem is I cannot find a combination of IDs that will load the correct record. Here are my attempts:
loads wrong result, SalesRecordID=129242 .. I need 129317:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$request->OrderLineItemID = $result->SaleRecord[0]->SellingManagerSoldTransaction[0]->OrderLineItemID;
$result2 = $service->GetSellingManagerSaleRecord($request);
loads wrong result, SalesRecordID=129243 .. I need 129317:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$request->OrderLineItemID = $result->SaleRecord[0]->SellingManagerSoldTransaction[1]->OrderLineItemID;
$result2 = $service->GetSellingManagerSaleRecord($request);
ErrorCode 21916340, Sale record doesnt exist:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$transaction = $result->SaleRecord[0]->SellingManagerSoldTransaction[0];
$request->OrderLineItemID = $transaction->ItemID . '-' . $transaction->TransactionID;
$result2 = $service->GetSellingManagerSaleRecord($request);
ErrorCode 21916340, Sale record doesnt exist:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$request->OrderID = $result->SaleRecord[0]->SaleRecordID;
$result2 = $service->GetSellingManagerSaleRecord($request);
ErrorCode 21916340, Sale record doesnt exist:
$service = new TradingService();
$request = new Types\GetSellingManagerSaleRecordRequestType();
$transaction = $result->SaleRecord[0]->SellingManagerSoldTransaction[0];
$request->ItemID = $transaction->ItemID;
$request->TransactionID = $transaction->TransactionID;
$result2 = $service->GetSellingManagerSaleRecord($request);

I'm not to familiar with the after sales side of the eBay API but depending on what you are trying to achieve the following may work.
Since GetSellingManagerSaleRecord won't allow you to pass a known SaleRecordID you can send it an OrderID instead. As each SaleRecord has an associated Order you can get it's ID by using GetOrders.
$service = new TradingService();
$request = new Types\GetSellingManagerSoldListingsRequestType();
$request->Search = new Types\SellingManagerSearchType();
$request->Search->SearchType = 'SaleRecordID';
$request->Search->SearchValue = '129317';
$response = $service->GetSellingManagerSoldListings($request);
/**
* Get the OrderLineItemID of the first transaction in the Sale Record.
* This would work as well as all the transactions will come from the same order.
* $orderLineItemID = $response->SaleRecord[0]->SellingManagerSoldTransaction[1]->OrderLineItemID;
*/
$orderLineItemID = $response->SaleRecord[0]->SellingManagerSoldTransaction[0]->OrderLineItemID;
/**
* Now look up the order.
*/
$request = new Types\GetOrdersRequestType();
$request->OrderIDArray = new Types\OrderIDArrayType();
$request->OrderIDArray->OrderID[] = $orderLineItemID;
$response = $service->getOrders($request);
$orderID = $response->OrderArray->Order[0]->OrderID;
/**
* Now use the OrderID to call GetSellingManagerSaleRecord.
*/
$request = new Types\GetSellingManagerSaleRecordRequestType();
$request->OrderID = $orderID;
$response = $service->getSellingManagerSaleRecord($request);
/**
* Check we got the correct SaleRecord.
*/
$saleRecordID = $response->SellingManagerSoldOrder->SaleRecordID;
assert('$saleRecordID === 129317');
In addition to calling GetSellingManagerSoldListings you can also call GetOrders to obtain a list of SaleRecordIDs. For example:
$request = new Types\GetOrdersRequestType();
$request->NumberOfDays = 30;
$response = $service->getOrders($request);
foreach ($response->OrderArray->Order as $order) {
printf("SaleRecordID %s\n", $order->ShippingDetails->SellingManagerSalesRecordNumber);
}

Related

How to simplify my result in Cakephp 3

My code is:
$costSheetQuery = $this->CostSheets->find('all')->where(['id IN' => $criteria]);;
$costSheetData = $costSheetQuery->all();
I print the array $costSheetData and it gives me the following relust:
Cake\ORM\ResultSet Object
(
[items] => Array
(
[0] => App\Model\Entity\CostSheet Object
(
[id] => 5
[key_value] => {"sample_date":"10-03-2018","mh_sc":"mh-sc","buyer":"buyer","season":"season","style":"styel","style_detail":"Style Details","sample_img":[[""]],"fab_category":[["FABRIC CATEGORY","FABRIC CATEGORY","FABRIC CATEGORY","FABRIC CATEGORY","FABRIC CATEGORY","FABRIC CATEGORY"]],"patt":[["PATT","PATT","PATT","PATT","PATT","PATT"]],"size":[["SIZE","SIZE","SIZE","SIZE","SIZE","SIZE"]],"ship_date":[[{"year":"2018"},{"month":"01"},{"day":"01"}]],"piece":[["10","20","30","40","50","60"]],"fabric_usage":[["USAGE"]],"fabric_yds":[["yds"]],"fabric_body":[["Body","Body","Body","Body","Body","Body"]],"cm":[["embrotery"]],"cm_value":[[" 10 ","12.00","","15","",""]],"trims":[["thread"]],"trims_value":[["10","","10","20","",""]]}
[created] => Cake\I18n\FrozenTime Object
(
[time] => 2018-03-10T16:47:52+00:00
[timezone] => UTC
[fixedNowTime] =>
)
[modified] => Cake\I18n\FrozenTime Object
(
[time] => 2018-03-10T16:47:52+00:00
[timezone] => UTC
[fixedNowTime] =>
)
[[new]] =>
[[accessible]] => Array
(
[key_value] => 1
[created] => 1
[modified] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[invalid]] => Array
(
)
[[repository]] => CostSheets
)
)
)
Whats hell is going on. I just start hating cakephp. My additional bullshit in my array? I also try to separate as : $items->costSheetData as item is an object of $costSheetData. But it gives me an arrow. Any idea?

DataTables. How to access what is filtered and by what order in response?

I'm using DataTables in project not implemented by me, and I'm trying to figure out how to get filter and order data from Response.
In .php file that is defined in Ajax:
var table = $('#table').DataTable({
ajax: {
url: "../admin/ajax/product.php",
data: function (d) {
... I have access to $_GET variable with data about what is filtered and what order is in use (print_r):
Array
(
[draw] => 2
[columns] => Array
(
[0] => Array
(
[data] => 0
[name] =>
[searchable] => false
[orderable] => false
[search] => Array
(
[value] =>
[regex] => false
)
)
[1] => Array
(
[data] => 1
[name] =>
[searchable] => true
[orderable] => true
[search] => Array
(
[value] =>
[regex] => false
)
)
[5] => Array
(
[data] => 5
[name] =>
[searchable] => false
[orderable] => true
[search] => Array
(
[value] => 5
[regex] => false
)
)
)
[order] => Array
(
[0] => Array
(
[column] => 2
[dir] => asc
)
)
[start] => 0
[length] => 10
[search] => Array
(
[value] =>
[regex] => false
)
[method] => getList
)
Now I need these information (what is filtered and by what order) in response to do something with this data in next Request but this time without ajax and DataTable.
How to access what is filtered and by what order in response?

how to execute stored procedure in cakephp 3?

This is my function for login i call a stored procedure login for match user name and password, but it doesn't work for me it give me all the rows:
public function login($email,$password)
{
$consumers = TableRegistry::get('Consumers');
$result=$consumers->query("Call login('".$email."','".$password."')");
pr($result->toArray());die;
}
My stored procedure in phpmyadmin is below:
BEGIN
SELECT * FROM consumers WHERE email = email_id AND password = md_password;
END
When i am executing query it give me object but after converting this object into array it give me all the row of table.output is:
<pre class="pr">Array
(
[0] => Cake\ORM\Entity Object
(
[_properties:protected] => Array
(
[id] => 1
[name] => jeevan
[email] => j#gmail.com
[password] => asdf
[phone_no] => 8447726137
[ota] => cde
[status] => 0
[created_on] => Cake\I18n\FrozenTime Object
(
[date] => 2016-07-08 17:28:52
[timezone_type] => 3
[timezone] => UTC
)
[token_access] =>
[device_type] => 1
[push_id] => abc
[want_news] => 1
[postal_code] => 263136
[registration_type] => 1
)
[_original:protected] => Array
(
)
[_hidden:protected] => Array
(
)
[_virtual:protected] => Array
(
)
[_className:protected] =>
[_dirty:protected] => Array
(
)
[_new:protected] =>
[_errors:protected] => Array
(
)
[_invalid:protected] => Array
(
)
[_accessible:protected] => Array
(
[*] => 1
)
[_registryAlias:protected] => Consumers
)
[1] => Cake\ORM\Entity Object
(
[_properties:protected] => Array
(
[id] => 2
[name] => jack
[email] => jack#gmail.com
[password] => 123
[phone_no] => 7409757656
[ota] => chb
[status] => 1
[created_on] => Cake\I18n\FrozenTime Object
(
[date] => 2016-07-20 06:10:14
[timezone_type] => 3
[timezone] => UTC
)
[token_access] => ghcvhgv
[device_type] => 0
[push_id] => hgnjh
[want_news] => 1
[postal_code] => 263136
[registration_type] => 1
)
[_original:protected] => Array
(
)
[_hidden:protected] => Array
(
)
[_virtual:protected] => Array
(
)
[_className:protected] =>
[_dirty:protected] => Array
(
)
[_new:protected] =>
[_errors:protected] => Array
(
)
[_invalid:protected] => Array
(
)
[_accessible:protected] => Array
(
[*] => 1
)
[_registryAlias:protected] => Consumers
)
)</pre>
that mean the stored procedure not working, any idea really help me, thanks in advance!
You can call a stored procedure using the ConnectionManager's execute() method. It's important to remember to prepare the query so that you remove the risk of SQL injection:-
$this->connection = ConnectionManager::get('default');
$results = $this->connection->execute(
'CALL login(?, ?)',
[$email, md5($password)]
)->fetchAll('assoc');
When CakePHP runs execute() it will substitute the ? with the escaped and quoted values of $email and md5($password). For further details check out the official docs on Preparing a statement.
step 1:use the class as use Cake\Datasource\ConnectionManager;
step 2: then execute the procedure-
$this->connection = ConnectionManager::get('default');
$consumer = $this->connection->execute("CALL login('".$email."','".md5($password)."')")->fetchAll('assoc');
now it will give an array.
finally i got this answer in cakephp cookbook.

How to foreach model to views on fuelphp

i have Model_User
// Get Exams by User
public static function get_exam_by_user($user_id) {
$query = "SELECT e.exam_id, e.exam_code, e.exam_name, e.description, e.creator, e.password,
e.max_attempt, e.random_order, e.max_time, e.max_score, e.min_score, e.grading,
e.created_at, e.updated_at
FROM exam e, user_exam ue
WHERE ue.exam_id = e.exam_id
AND ue.status = 1
AND ue.user_id = :user_id";
$result = DB::query($query)->bind('user_id', $user_id)->execute();
return $result->as_array();
}
and this controller
public function action_index() {
$data = array();
//$data['user_id'] = \Auth\Auth::get('id');
//$data['username'] = \Auth\Auth::get('username');
$user_id = Auth\Auth::get('id');
//$data['exams'] = Model_Exam::find('all');
$data['exams'] = Model_Exam::get_exam_by_user($user_id);
$this->template->title = "Exams";
$this->template->content = View::forge('admin/exam/index', $data);
}
How to foreach to views ?i try to printr_r
Array ( [0] => Array ( [exam_id] => 2 [exam_code] => SD_K1S1_MAT [exam_name] => Ujian Matematika SD Kelas 1 Sem 1 [description] => [creator] => RF [password] => [max_attempt] => 3 [random_order] => 1 [max_time] => 60 [max_score] => 100 [min_score] => 0 [grading] => [created_at] => 2013 [updated_at] => 2013 ) [1] => Array ( [exam_id] => 2 [exam_code] => SD_K1S1_MAT [exam_name] => Ujian Matematika SD Kelas 1 Sem 1 [description] => [creator] => RF [password] => [max_attempt] => 3 [random_order] => 1 [max_time] => 60 [max_score] => 100 [min_score] => 0 [grading] => [created_at] => 2013 [updated_at] => 2013 ) )
if you can help solve this problem
I think that you can do something like this :
<?php foreach ($exams as $exam):
echo $exam['exam_id'];
echo $exam['exam_code'];
echo $exam['exam_name']; .... and so on....
Hope is what you need.

Kohana ORM Relationships

I'm trying to get to grips with the Kohana ORM but I'm a bit stuck.
I have created category and post models, with a relationship based on category_id.
I can fetch post and category models separately, however I cannot seem to fetch them using the relationship. For example:
// Get first category
$category = ORM::factory('category', 1);
foreach ($category->posts as $post)
{
echo $post->title;
}
The above just gives me a blank screen (I know I shouldn't be outputting anything in the controller, just trying to get it working first).
print_r($category);
Gives me this:
Model_Category Object ( [_has_many:protected] => Array ( [posts] => Array ( [model] => post [foreign_key] => category_id [through] => [far_key] => post_id ) ) [_has_one:protected] => Array ( ) [_belongs_to:protected] => Array ( ) [_load_with:protected] => Array ( ) [_validate:protected] => [_rules:protected] => Array ( ) [_callbacks:protected] => Array ( ) [_filters:protected] => Array ( ) [_labels:protected] => Array ( ) [_object:protected] => Array ( [id] => 1 [title] => [description] => ) [_changed:protected] => Array ( ) [_related:protected] => Array ( ) [_loaded:protected] => [_saved:protected] => 1 [_sorting:protected] => Array ( [id] => ASC ) [_foreign_key_suffix:protected] => _id [_object_name:protected] => category [_object_plural:protected] => categories [_table_name:protected] => categories [_table_columns:protected] => Array ( [id] => Array ( [type] => int [min] => 0 [max] => 65535 [column_name] => id [column_default] => [data_type] => smallint unsigned [is_nullable] => [ordinal_position] => 1 [display] => 6 [comment] => [extra] => auto_increment [key] => PRI [privileges] => select,insert,update,references ) [title] => Array ( [type] => string [character_maximum_length] => 65535 [column_name] => title [column_default] => [data_type] => text [is_nullable] => [ordinal_position] => 2 [collation_name] => latin1_swedish_ci [comment] => [extra] => [key] => [privileges] => select,insert,update,references ) [description] => Array ( [type] => string [character_maximum_length] => 65535 [column_name] => description [column_default] => [data_type] => text [is_nullable] => [ordinal_position] => 3 [collation_name] => latin1_swedish_ci [comment] => [extra] => [key] => [privileges] => select,insert,update,references ) ) [_ignored_columns:protected] => Array ( ) [_updated_column:protected] => [_created_column:protected] => [_primary_key:protected] => id [_primary_val:protected] => name [_table_names_plural:protected] => 1 [_reload_on_wakeup:protected] => 1 [_db:protected] => Database_MySQL Object ( [_connection_id:protected] => d6ad44aa068ae69071b9614f2a4a760bf55d9307 [_identifier:protected] => [last_query] => SHOW FULL COLUMNS FROMcategories` [_instance:protected] => default [_connection:protected] => Resource id #36 [_config:protected] => Array ( [type] => mysql [connection] => Array ( [hostname] => localhost [database] => cms_test_kohana [persistent] => ) [table_prefix] => [charset] => utf8 [caching] => [profiling] => 1 ) ) [_db_applied:protected] => Array ( ) [_db_pending:protected] => Array ( ) [_db_reset:protected] => 1 [_db_builder:protected] => [_with_applied:protected] => Array ( ) [_preload_data:protected] => Array ( ) )
Can anyone help?
Any advice appreciated.
Thanks.
Posts is a relationship, not a collection. Use find_all() or find() on a relationship to return a collection of records.
foreach ($category->posts->find_all() as $post) {
echo $post->title;
}
You can also apply various other methods to the relationship to filter the returned results using orderby, where, etc...