Create product with assign collection in shopify - shopify

I have tried to create product in myshopify with help of below parameter.Product is creating in myshopify admin but the collection is not assign so kindly let met know how can I assign collection with this.
"product"=> array(
"title"=> $product->getName(),
"body_html"=> $product->getDescription(),
"vendor"=> "Troupe",
"product_type"=>"",
"collection_ids" => array('31231','231312'),
"published"=> true ,
"variants"=> array(
array(
"price"=> ($product->getPrice()),
"sku"=> $product->getsku()
)
),
"images"=> $images
)
);

You can't create a product and assign it to a collection in a single REST API call.
The best you can do is create the product first and upon its success, create a "collect", which is a mapping between a collection and a product.
See this API page for info on how to do that, Custom collection update.

Related

Create a PODIO item with relationship with podio api for PHP

How can we create an item and relate it to other items (setting the values on a relationship field)? I found no examples regarding those fields.
Just found how to do it.
1) Get the 'item_id' value for the app item you want to relate to in the parent application.
$item_id = $item->item_id;
2) Use the item_id on the child application relationship field.
new PodioAppItemField(array("external_id" => "my_rel_field", "values" => array( 'item_id' => $item_id)))

Get multiple items of multiple apps in podio api

Can i retrieve all the items in my filter which is under multiple apps which has same app name in podio api.
Example scenario:
I have two work space. Both work space have Deliverable app. I want to get all items in Deliverable from both work space, and i want to filter through it.
I can get items in an app by :
PodioItem::filter( $app_id, $attributes = array(), $options = array() );
is there a way like:
PodioItems::filter(array($multiple_app_id), $attributes = array(), $options = array() );
No. The API filter operation doesn't support passing multiple app ids. You'll have to make a separate call for each app that you'd like to retrieve items, regardless of the workspace.

How to show product quantity in the cart on custom page

I'm using Prestashop 1.5 and created page with list of grouped products. I want to show quantity of each product in the cart. At shopping cart page exist $product.cart_quantity property, but on my page it doesn't. Please, explain me, how to show product quantity in the cart on my page.
Easyest way I can think of is to access the data via cookies since cart data is stored in them.
You can get cookies data like this:
$context = Context::getContext();
echo '<pre>',print_r($context->cookie, true).'</pre>';
Prestashop Context is a registry for PHP variables that were previously accessed as globals. It aims to standardize the way these variables are accessed, and to make the code more robust by getting rid of global vars.
And our echo is just for example to show what info you can get from cookies.
When costumer adds something to the shopping-cart it automatically gives it a cart id (id_cart) and from there it's fairly easy to access to access that value to get all the info.
To get a cart id ( assuming you already got context ) use this
$Cart = $context->cart;
This returns you a ID of a current cart.
Now you want to return the current products in the cart ( with all the information it includes ). For that you have to use the public function located in prestashop_main_folder/classes/cart.php
So to return all the current products just use the following line
$Cart->getProducts($refresh = false, $id_product = false, $id_country = null)
And then it returns you a array with all the variables what you can easily then access.
BR's
You can do the following:
$context=Context::getContext();
$id_cart=$context->cookie->id_cart;
if($id_cart=='') $id_cart=Tools::getValue('id_cart');
$theCart = new Cart($id_cart);
$products = $theCart->getProducts(true);
$nbTotalProducts = 0;
foreach ($products as $product)
{
$nbTotalProducts += (int)$product['cart_quantity'];
}

How to create configurable product using magento api?

How can I create a configurable product using the Magento api?
Your question of creating a configurable product using the API - the answer is: You can't. It doesn't support it (yet at least.)
This is possible with the magento-improve-api plugin. If you need to control which attributes your configurable product is configurable across, you'll need one of the forks of that plugin in
goodscloud/magento-improve-api
jdurand/magento-improve-api
dexteradeus/magento-improve-api
Here's a really good tutorial that walks you through patching the API, so you can use the API directly to create the configurable product, and assign simple products to it as well.
Good luck
Copy/pasted from http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#example_2._product_createviewupdatedelete
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
// default attribute set in my install is 4
$attribute_set_id = 4;
// configurable product to create
$product_sku = 123456789012;
$newProductData = array(
'name' => 'name of product',
// websites - Array of website ids to which you want to assign a new product
'websites' => array(1), // array(1,2,3,...)
'short_description' => 'short description',
'description' => 'description',
'price' => 12.05
);
$proxy->call($sessionId, 'product.create', array(
'configurable',
$attribute_set_id,
$product_sku,
$newProductData
));
The hard part is assigning simple products to your configurables (not supported via the api). Here's a method for assigning simples to configurables directly

Is it possible to set certain product attributes for a different store view using the Magento API?

We are currently using the Magento API for importing a bunch of products into the store.
But we now run into a problem where some product attributes should be translated into a different language.
And I was wondering if it is possible to do this using the Magento API, because I can't seem to find anything related to that problem.
We currently have 2 store views, 1 for the Dutch version of the site and one for the French version of the site.
Our current import code looks something like this:
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('nl'));
echo("store_id: $store_id");
$new_product_data = array(
'name' => 'NameInDutch',
'short_description' => 'DescriptionInDutch',
'price' => $price,
'weight' => $weight,
'websites' => array('base'),
'status' => '1'
);
$new_product_id = $soapClient->call($soapSession, 'catalog_product.create', array('simple', 4, $sku, $new_product_data)); // 4 => 'Default' attribute set
$localized_product_data = array(
'name' => 'NameInFrench',
'short_description' => 'DescriptionInFrench'
);
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('fr'));
echo("store_id: $store_id");
$soapClient->call($soapSession, 'catalog_product.update', array($sku, $localized_product_data ));
Now, the output of the echo statements differs, the first time it's 1 and the second time it's 2, so that doesn't seem to be problem. But apparently it doesn't matter for the API if we set that value.
The result is that on the 'catalog_product.update' call, the name 'NameInFrench' overwrites the default name 'NameInDutch'.
So my question is if something like this is possible using the Magento API, and how one would accomplish this?
Ok, I found the answer, apparently I overlooked a certain line in the Magento API docs, because the solution was right there.
So: you don't need to set the currentStore each time, you just need to append the store id or code to the update array:
$soapClient->call(
$soapSession,
'catalog_product.update',
array($sku, $localized_product_data, 'fr')
);
This works perfectly.