Closed zerdmer closed 4 years ago
Hello, you can use the getCreatedAt
method to get a product creation date.
$product = $client->getProductManager()->find(xxx);
$product->getCreatedAt(); // \DateTime object
Or you can use CRUD methods, like this:
$response = $client->get('products/xxx'); // array
$product = $response['product'];
$product['created_at']; // ISO 8601 string
That's perfect. But when I do it:
$products = $client->get('products', [ // Filter your products ]);
it just show arround 20 products, how get all?
You need to use cursor-based pagination, see more in this article. The library supports cursor-based pagination using the paginate
method, but you will not be able to use this method using CRUD, only through a manager. To understand how to use cursor-based pagination with CRUD, see how pagination is implemented in the CursorBasedPagination class.
Can you give me a example how use CursorBasedPagination ? thanks you a lot, and congratulations for this project
See an example in readme: https://github.com/slince/shopify-api-php/blob/master/README.md#use-manager-to-manipulate-your-data
please, can you check it out?
$pagination = $client->getProductManager()->paginate([ // filter your product 'limit' => 3 ]);
$currentProducts = $pagination->current(); //current page
while ($pagination->hasNext()) { $nextProducts = $pagination->next(); foreach ($nextProducts as $product) { $product->getTitle(); } }
don't worry , i got it
$pagination = $client->getProductManager()->paginate([ // filter your product 'limit' => 3 ]);
$currentProducts = $pagination->current(); //current page
while ($pagination->hasNext()) { $nextProducts = $pagination->next(); foreach ($nextProducts as $product) { foreach ($product->getVariants() as $variant) { echo $variant->getPrice(); } exit; } }
now my problem is: $product->getId() doesn't work, so how can i get the id ?
now my problem is: $product->getId() doesn't work, so how can i get the id ?
getId
is the correct method, what error do you get?
To iterate over all products you can use loop like this:
$pagination = $client->getProductManager()->paginate([
'limit' => 250, // max value for limit
]);
$products = $pagination->current();
while (true) {
foreach ($products as $product) {
var_dump($product->getId()); // process product
}
if (!$pagination->hasNext()) {
break;
}
$products = $pagination->next();
}
For example if I do it:
$product = $client->getProductManager()->find(00000000000); $product->getVariants(); echo $product->title;
It doesn't work because title is protected, i know i can use gettitle, but imagine other, for example.... datecreated, i want to now how i can get the object array information