Finditemsadvanced call in Ebay webservices and in the SDK for PHP includes the possibility to getHistograms for categories.
FindingServices.php display the following code:
public function getHistograms(\DTS\eBaySDK\Finding\Types\GetHistogramsRequest $request)
{
return $this->callOperation(
'getHistograms',
$request,
'\DTS\eBaySDK\Finding\Types\GetHistogramsResponse'
);
}
public function findItemsAdvanced(\DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest $request)
{
return $this->callOperation(
'findItemsAdvanced',
$request,
'\DTS\eBaySDK\Finding\Types\FindItemsAdvancedResponse'
);
}
In my controller I try two version to call FindingItemsAdvanced including GetHistograms.
/** Create the service object.*/
$service = new DTS\eBaySDK\Finding\Services\FindingService(array(
'appId' => $config['production']['appId'],
'apiVersion' => $config['findingApiVersion'],
'globalId' => DTS\eBaySDK\Constants\GlobalIds::US
));
/** Create the request object.*/
$request = new DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest();
$request->keywords = 'ipod nano';
$request->categoryId = array('73839');/** Search across two categories. * DVDs & Movies > DVDs & Blue-ray (617) * Books > Fiction & Literature (171228)*/
$request->outputSelector = array('AspectHistogram','CategoryHistogram','SellerInfo');
$itemFilter = new DTS\eBaySDK\Finding\Types\ItemFilter();/** Filter results to only include auction items or auctions with buy it now. */
$itemFilter->name = 'ListingType';
$itemFilter->value[] = 'FixedPrice';
$itemFilter->value[] = 'AuctionWithBIN';
$request->itemFilter[] = $itemFilter;
/** Get Histograms */
check below option 1 and option 2 and its errors
/** response */
$response = $service->findItemsAdvanced($request);
using option 1:
$request->getHistograms = new DTS\eBaySDK\Finding\Types\GetHistogramsRequest();
$request->getHistograms = (array('73839'));
but its giving me the following error: Unknown property: DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest::getHistograms
using option 2:
$request1 = new DTS\eBaySDK\Finding\Types\GetHistogramsRequest();
$histograms = $service->getHistograms($request1);
$request->$histograms = (array('73839'));
but its giving me the following error: "Unknown property: DTS\eBaySDK\Finding\Types\FindItemsAdvancedRequest::Object"
I know that in the SDK getHistograms() is not part of FindItemsAdvanced() but its a part of FindingService.php consequently I assume it could be called in the same action. Any help or example code using finditems with histograms in same call appreciated.
The category that you are using is Consumer Electronics > Portable Audio & Headphones > iPods & MP3 Players (73839). While this is a valid category ID, both getHistograms and findItemsAdvanced will not return a categoryHistogram element. The reason for this is explained in the documentation for getHistograms
This container is returned only when the specified category has
children categories.
And also in the findItemsAdvanced documentation.
The category IDs returned for items in search results are for the leaf
categories in which the items are listed. If you use these category
IDs as input, the response will not return a category histogram.
In other words the categoryHistogram element will not be returned by either service if a leaf category is specified in the request. A leaf category is just a category that has no children. Since the category 73839 is a leaf category you will instead have to use its parent Consumer Electronics > Portable Audio & Headphones (15052).
The links below should return the categoryHistogram. You just need to replace <YOUR APP ID> in the URL.
http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=<YOUR APP ID>&OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.13.0&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&categoryId(0)=15052&outputSelector(0)=AspectHistogram&outputSelector(1)=CategoryHistogram&outputSelector(2)=SellerInfo
http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=<YOUR APP ID>&OPERATION-NAME=getHistograms&SERVICE-VERSION=1.13.0&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&categoryId(0)=15052
Related
I'm pretty new to PrestaShop - so sry if i ask basic thing
I'm currently working on a module which should display products you chose in the backend as additional section in the default products template - like "highly recommended products"
I finish the whole Backend part, and get the ID's as an array of the chosen products.
As I mentioned I wanna use the default templates which are available after a fresh installation and what I found is placed here themes\classic\templates\catalog\_partials\products.tpl.
Now my big problem is: I'm not able to get the data like it should be ...
If I debug e.g. the products which are displayed in the default search behaviour (this uses this template too) I see something like
object(PrestaShop\PrestaShop\Adapter\Presenter\Product\ProductListingLazyArray)#323 (11) { ["imageRetriever":"Pr .....
but as I get my products with
new Product($productId, true);
it is no ProductListingLazyArray ... its just an array with products ... and i dont see anything in the frontend (of course I dont, cause e.g. {$product.id_product} doesnt look like this in my array ...
Have you any ideas what I can do to "transform" my array of products to an ProductListingLazyArray ??
Or is my thinking wrong ?
THANKS to you all!
Solution
I just "faked" a search and check if the data is in my array:
/**
* creates relevant product information for frontend output
*
* #param array $allSelectedProductIds array with all id's of the selected products
* #param int $languageId language id of the shop you are in
*
* #return array all product information we need for our frontend rendering
*/
public function getFrontendProductInformation($allSelectedProductIds, $languageId)
{
// set default category Home
$category = new Category((int)2);
// create new product search proider
$searchProvider = new CategoryProductSearchProvider(
$this->context->getTranslator(),
$category
);
// set actual context
$context = new ProductSearchContext($this->context);
// create new search query
$query = new ProductSearchQuery();
$query->setResultsPerPage(PHP_INT_MAX)->setPage(1);
$query->setSortOrder(new SortOrder('product', 'position', 'asc'));
$result = $searchProvider->runQuery(
$context,
$query
);
// Product handling - to get relevant data
$assembler = new ProductAssembler($this->context);
$presenterFactory = new ProductPresenterFactory($this->context);
$presentationSettings = $presenterFactory->getPresentationSettings();
$presenter = new ProductListingPresenter(
new ImageRetriever(
$this->context->link
),
$this->context->link,
new PriceFormatter(),
new ProductColorsRetriever(),
$this->context->getTranslator()
);
$products = array();
foreach ($result->getProducts() as $rawProduct) {
$productId = $rawProduct['id_product'];
if(in_array($productId, $allSelectedProductIds)) {
$product = $presenter->present(
$presentationSettings,
$assembler->assembleProduct($rawProduct),
$this->context->language
);
array_push($products, $product);
}
}
return $products;
}
I don't know why, but in order to use the API update to update the description of a video in your library you have to provide more than just the ID, you have to provide: the title, the ID, and the category ID. Why you need more than just the unique video ID is beyond me.
When I request a list of videos using the following parameters:
$queryParams = [
'forMine' => true,
'q' => $q,
// 'fields' => 'items(id,snippet/title,snippet/description)', <- would like to specify categoryId here
'type' => 'video',
'maxResults' => 50
];
$response = $service->search->listSearch('snippet', $queryParams);
The returned list provides the Title and the ID but not the Category ID. Actually I don't know of any way of getting the category ID besides opening the video in your YouTube dashboard, looking at the category, and the comparing it to a list like this one
So, is their a way of updating a video's description without needing the category ID, or is there a way of acquiring that category ID using the API?
Here is how I am attempting to update the description.
// Auth the client
$service = new Google_Service_YouTube($client);
// Define the $video object, which will be uploaded as the request body.
$video = new Google_Service_YouTube_Video();
// Set the ID
$video->setId($video_id);
// Add 'snippet' object to the $video object.
$videoSnippet = new Google_Service_YouTube_VideoSnippet();
$videoSnippet->setCategoryId('<HOW TO GET THIS?>');
$videoSnippet->setDescription('Test Description');
$videoSnippet->setTitle($video_title);
$video->setSnippet($videoSnippet);
$response = $service->videos->update('snippet', $video);
PS, can someone who has the right privilege add the youtube-php-api tag?
UPDATE:
You cannot retrieve the Category ID using the SEARCH api, you must use the LIST api. What this means is that if you want to update the description of a video that you searched for, you need use 3 separate APIs. Here is how I used the LIST api to retrieve the category id:
$client = google_authenticate();
$service = new Google_Service_YouTube($client);
$queryParams = [
'id' => $video_id,
'fields'=>'items(snippet/categoryId)'
];
$response = $service->videos->listVideos('snippet', $queryParams);
return $response['items'][0]['snippet']['categoryId'];
According to the docs, indeed you have to set categoryId for each video that you intend to update its snippet part.
Use VideoCategories endpoint to obtain a list of categories (along with corresponding IDs) available for your region.
Update:
If needing to get the category ID of a given (already existing) video, use the Videos endpoint, and lookup for the property items[].snippet.categoryId.
Is it possible to get the asset details using asset name with Azure PHP sdk. I can get all the asset list, but it's loading first 1000 assets only.
getAssetList();
I can get single asset details using asset id.
getAsset($asset);
But in my case, I don't have asset id with me. I just have asset name alone. Now how do I get the asset details using this?
EDIT:
I got some help from Azure support saying that, we can use $skip parameter for pagination. I got code snippet in c#
for (int i = 0; i < _context.Assets.Count(); i += 1000 )
{
var assets = _context.Assets.Skip(i);
foreach (IAsset objIAsset in assets)
{
Console.WriteLine(objIAsset.Name.ToString());
}
}
How can I use this param in PHP SDK.
It seem that Azure SDK for PHP don't support skip method. However, I used the fiddler to monitor C# skip method and got the URL like this:
https://***-hs.cloudapp.net/api/Assets()?$skip=1000
So I think we can bulid up the request path like above in our PHP project and we can modify the getAssetList method in "MediaServicesRestProxy" file.
I add a function named "getAssetListBySkip($number)" into "MediaServicesRestProxy" class, the code like this:
/**
* Get asset list using skip number
*
* */
public function getAssetListBySkip($number)
{
$propertyList = $this->_getEntityList("Assets()?".'$skip='.$number);
$result = array();
foreach ($propertyList as $properties) {
$result[] = Asset::createFromOptions($properties);
}
return $result;
}
We can call this method like this:
$mediaServiceProxy = ServicesBuilder::getInstance()->createMediaServicesService(
new MediaServicesSettings("**","**/**="));
$result=$mediaServiceProxy->getAssetListBySkip(1000);
Azure Media services supports filtering by name. You can construct web request to be like
/api/assets()?$filter=Name%20eq%20'Your Name'&$top=1
You can also filter by other properties
Have you tried REST API that are used when creating, processing, managing, and delivering Assets. https://msdn.microsoft.com/en-us/library/azure/hh974277.aspx#list_an_asset but I do think we can list asset via a name directly since id is an unique indentifier of asset entity. PHP Azure SDK leverages assetId to get an Asset as well:
public function getAsset($asset)
{
$assetId = Utilities::getEntityId(
$asset,
'WindowsAzure\MediaServices\Models\Asset'
);
return Asset::createFromOptions($this->_getEntity("Assets('{$assetId}')"));
}
But in my case, I don't have asset id with me. I just have asset name
alone. Now how do I get the asset details using this?
Here are some test function code snippets for your reference:
public function testListAllAssets(){
// Setup
$asset1 = new Asset(Asset::OPTIONS_NONE);
$asset1->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
$asset2 = new Asset(Asset::OPTIONS_NONE);
$asset2->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
// Test
$asset1 = $this->createAsset($asset1);
$asset2 = $this->createAsset($asset2);
$result = $this->restProxy->getAssetList();
// Assert
$this->assertCount(2, $result);
$names = array(
$result[0]->getName(),
$result[1]->getName()
);
$id = array(
$result[0]->getId(),
$result[1]->getId()
);
$this->assertContains($asset1->getName(), $names);
$this->assertContains($asset2->getName(), $names);
$this->assertContains($asset1->getId(), $id);
$this->assertContains($asset2->getId(), $id);
}
public function testGetAnAssetReference(){
// Setup
$assetName = TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix();
$asset = new Asset(Asset::OPTIONS_NONE);
$asset->setName($assetName);
$asset = $this->createAsset($asset);
// Test
$result = $this->restProxy->getAsset($asset);
// Assert
$this->assertEquals($asset->getId(), $result->getId());
$this->assertEquals($asset->getName(), $result->getName());
}
From: https://github.com/Azure/azure-sdk-for-php/blob/master/tests/functional/WindowsAzure/MediaServices/MediaServicesFunctionalTest.php
According to my testing, it seems that we can’t use Asset’s name to get the information of asset in Media Service.
$mediaServiceProxy = ServicesBuilder::getInstance()->createMediaServicesService(
new MediaServicesSettings("**","******"));
$asset = new Asset(Asset::OPTIONS_NONE);
$asset->setName('For-Test-wmv-Source');
//$asset don't have the value of id,
// unless execute ‘createAsset($asset)’, "$asset1" will be set the ID
$asset1 =$mediaServiceProxy->createAsset($asset);
$result2=$mediaServiceProxy->getAsset($asset1);
PHP SDK support the method named “getAsset($asset)”. Actually, the method get the Asset information by Asset id, just like the Aka's reference code.And Azure REST API don’t support the method queried by Asset’s name.
Please refer to the official document.
Alternative approach is that you can store your assets information (such as Id,URl,name and ect.) into Azure table storage when you upload them into media service. If you want to use it, you can fetch and filter the data of Asset’s name you wants from table storage.
I'm trying to display the subscriber count from a MailChimp mailing list using their API, and I've got it partially working, except the code below is currently spitting out the subscriber count for all lists, rather than for one specific list. I've specified the list id in the line $listId ='XXX'; but that doesn't seem to be working. Because I have five lists in total, the output from the PHP below shows this:
10 0 0 1 9
What do I need to do in my code below to get the subscriber count from a specific list id?
<?php
/**
This Example shows how to pull the Members of a List using the MCAPI.php
class and do some basic error checking.
**/
require_once 'inc/MCAPI.class.php';
$apikey = 'XXX';
$listId = 'XXX';
$api = new MCAPI($apikey);
$retval = $api->lists();
if ($api->errorCode){
echo "Unable to load lists()!";
echo "\n\tCode=".$api->errorCode;
echo "\n\tMsg=".$api->errorMessage."\n";
} else {
foreach ($retval['data'] as $list){
echo "\t ".$list['stats']['member_count'];
}
}
?>
I just came across this function (see below) that let's me return a single list using a known list_id. The problem is, I'm not sure how to add the list_id in the function.
I'm assuming I need to define it in this line? $params["filters"] = $filters;
The MailChimp lists() method documentation can be referred to here: http://apidocs.mailchimp.com/rtfm/lists.func.php
function lists($filters=array (
), $start=0, $limit=25) {
$params = array();
$params["filters"] = $filters;
$params["start"] = $start;
$params["limit"] = $limit;
return $this->callServer("lists", $params);
}
I'd strongly recommend not mucking with the internals of the wrapper as it's not going to be nearly as helpful as the online documentation and the examples included with the wrapper. Using the wrapper means the line you tracked down will effectively be filled when make the proper call.
Anywho, this is what you want:
$filters = array('list_id'=>'XXXX');
$lists = $api->lists($filters);
Mailchimp provides a pre-built php wrapper around their api at http://apidocs.mailchimp.com/downloads/#php. This api includes a function lists() which, according to its documentation, returns among other things:
int member_count The number of active members in the given list.
It looks like this is the function which you are referring to above. All you should have to do is iterate through the lists that are returned to find the one with the proper id. From there you should be able to query the subscriber count along with a number of other statistics about the list.
How can I find out, if a simple product is part of a configurable product and then get the master product? I need this for the product listing.
Just found out:
$_product->loadParentProductIds();
$parentIds = $_product->getParentProductIds();
Let's say that you have your simple product's Product ID.
To get all the parent configurable product IDs of this simple product, use the following code:-
<?php
$_product = Mage::getModel('catalog/product')->load(YOUR_SIMPLE_PRODUCT_ID);
$parentIdArray = $_product->loadParentProductIds()
->getData('parent_product_ids');
if(!empty($parentIdArray)) {
// currently in the master configurable product
print_r($parentIdArray); // this prints all the parent product IDs using your simple product.
}
?>
I suppose this should get you going.
For Magento 1.4.2 and above use the following method instead:
$configurable_product_model = Mage::getModel(‘catalog/product_type_configurable’);
$parentIdArray = $configurable_product_model->getParentIdsByChild($simple_product_id);
After version 1.4.2.0 the loadParentProductIds() and getParentProductIds() methods are deprecated. Don't ask me why. Personally I kind of liked those methods. So I've reintroduced them to my local Mage classes. This is how:
Copy
app/code/core/Mage/Catalog/Model/Product.php
to
app/code/local/Mage/Catalog/Model/Product.php
and change the loadParentProductIds() method, found around line 1349 to:
public function loadParentProductIds()
{
return $this->_getResource()->getParentProductIds($this);
}
This piece of code will query its resource for its parent product ids. For this to work we'll need to rewrite the getParentProductIds() method in the resource class.
So copy:
app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product.php
to
app/code/local/Mage/Catalog/Model/Resource/Eav/Mysql4/Product.php
Find the deprecated getParentProductIds() method. Should be somewhere around line 535. Overwrite it with the pre 1.4.2.0 code:
public function getParentProductIds($object){
$childId = $object->getId();
$groupedProductsTable = $this->getTable('catalog/product_link');
$groupedLinkTypeId = Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED;
$configurableProductsTable = $this->getTable('catalog/product_super_link');
$groupedSelect = $this->_getReadAdapter()->select()
->from(array('g'=>$groupedProductsTable), 'g.product_id')
->where("g.linked_product_id = ?", $childId)
->where("link_type_id = ?", $groupedLinkTypeId);
$groupedIds = $this->_getReadAdapter()->fetchCol($groupedSelect);
$configurableSelect = $this->_getReadAdapter()->select()
->from(array('c'=>$configurableProductsTable), 'c.parent_id')
->where("c.product_id = ?", $childId);
$configurableIds = $this->_getReadAdapter()->fetchCol($configurableSelect);
return array_merge($groupedIds, $configurableIds);
}
Now you once again can do this:
$_product->loadParentProductIds()->getData('parent_product_ids');
Hope this helps you out!