Bigcommmere Api create product with images link - php

I want to create product in bigcommerce store using bigcommerce Api. Following code works fine to create product in Bc store
$product = array('name' => 'ABC Blocks', 'type' => 'physical', 'price' => '19.99', 'weight' => 2.3, 'categories' => array(26), 'availability' => 'available', 'is_visible' => true));
Bigcommerce_Api::createProduct($product);
How can I pass images url ? I am trying following codes but unable to create
$image = array('image_file'=>'https://developer.bigcommerce.com/assets/hero-image.png','is_thumbnail'=>false,'sort_order'=>1,'description'=>'');
$product = array('name' => 'ABC Blocks', 'type' => 'physical', 'price' => '19.99', 'weight' => 2.3, 'categories' => array(26), 'availability' => 'available', 'is_visible' => true,'images' => array('image_file' => $image));
Bigcommerce_Api::createProduct($product);
Any help will be greatly appreciated!!thanks

Here's an example structure from the api about how primary image data should look.
"primary_image": {
"id": 247,
"zoom_url": "https://cdn.url.path/bcapp/et7xe3pz/products/32/images/247/in_123__14581.1393831046.1280.1280.jpg?c=1",
"thumbnail_url": "https://cdn.url.path/bcapp/et7xe3pz/products/32/images/247/in_123__14581.1393831046.220.290.jpg?c=1",
"standard_url": "https://cdn.url.path/bcapp/et7xe3pz/products/32/images/247/in_123__14581.1393831046.386.513.jpg?c=1",
"tiny_url": "https://cdn.url.path/bcapp/et7xe3pz/products/32/images/247/in_123__14581.1393831046.44.58.jpg?c=1"
}
Use this to figure out your array structure.

Related

Importing image from external URL using Magmi datapump

I am using Magmi datapump to import some products into Magento.
So far i have this:
require_once("../../magmi/inc/magmi_defs.php");
require_once("../../magmi/integration/inc/magmi_datapump.php");
$dp = Magmi_DataPumpFactory::getDataPumpInstance("productimport");
$dp->beginImportSession("Default","create");
$newProductData = array(
'type' => 'simple',
'sku' => "test-simple",
'qty' => 1000,
'color' => 'Brown',
'price' => 10,
'name' => 'test simple',
'tax_class_id' => 1,
'is_in_stock' => 1,
'store' => 'admin',
'economic_productgroup' => 700,
'image' => '+http://blogs.smh.com.au/entertainment/getflickd/44655_native.jpeg.jpg',
'small_image' => 'http://blogs.smh.com.au/entertainment/getflickd/44655_native.jpeg.jpg',
'thumbnail' => 'http://blogs.smh.com.au/entertainment/getflickd/44655_native.jpeg.jpg'
);
$dp->ingest($newProductData);
$dp->endImportSession();
All attributes are getting imported correctly, except image. This does not work.
This is screenshot from "Default" profile.
Magmi is installed here: http://www.example.com/import/magmi/web/magmi.php
Why are import of my images not working?
Problem solved by creating new profile in webinterface with exact same settings as i had in "default" profile. Not sure why though.

"101: Product not exists." (Magento API) product.update

I saw the documentation but I still not finding the error on my code.
I am trying to add a product from excel file to Magento System, and then update it on each Store View (multi language shop).
For that, I've done the following PHP script. On this code, I'm reading only one Excel row (just to show you how it works) and then i am adding it to Magento (actually that's working) and then I am trying to Update stuff (gives the error). Be aware that $col[9] is the var that saves the SKU.
Note: I am using SOAP, but not V2.
$rowdata=$sheet->rangeToArray('A' . $row.':'.$maxcol . $row, NULL, TRUE, FALSE);
$col=$rowdata[0];
//$soap is the client. $session_id is the logged in SOAP session.
$attributeSets = $soap->call($session_id, 'product_attribute_set.list');
$attributeSet = current($attributeSets);
$result = $soap->call($session_id, 'catalog_product.create', array('simple', $attributeSet['set_id'], $col[9], array(
'categories' => array(2),
'websites' => array(1),
'name' => $col[1],
'description' => $col[10],
'short_description' => $col[13],
'weight' => '10',
'status' => '1',
'url_key' => 'product-url-key',
'url_path' => 'product-url-path',
'visibility' => '4',
'price' => $col[20],
'tax_class_id' => 1,
'meta_title' => 'Product meta title',
'meta_keyword' => 'Product meta keyword',
'meta_description' => 'Product meta description'
)));
var_dump ($result);
$updatearray= array(
'name' => $col[2],
'description' => $col[11],
'short_description' => $col[14]
);
$update = $soap->call($session_id, 'catalog_product.update', array($col[9], $updatearray, 'fr'));
var_dump ($update);
I would appreciate any help you guys can give!
I just found the fix for this problem but it really makes no sense.
So, when we are sending the SKU by call, we need to send with an extra space. It means the $update needs to be like this:
$soap->call($session_id, 'catalog_product.update', array($col[9].' ', $updatearray, 'fr'));

programmatically update bundle product magento?

I have created a script in magento which create the bundle product and it is working fine. But i want to also update the created bundle product with new products of selection. Here it is my code and it is not working:
public function updateBundleProduct($pro_id,$cPrdcts){
$bundleProduct = Mage::getModel('catalog/product');
$bundleProduct->load($pro_id);
$bundleProduct->setName('test product bundle bundlea');
$bundleSelections = array();
$bundleSelections = array(
'0' => array( //option ID
'0' => array(
'product_id' => '70',
'delete' => '',
'selection_price_value' => '10',
'selection_price_type' => 0,
'selection_qty' => 1,
'selection_can_change_qty' => 0,
'position' => 0,
'is_default' => 1,
'selection_id' => 71,
'option_id' => 14
),
'1' => array(
'product_id' => '84',
'delete' => '',
'selection_price_value' => '10',
'selection_price_type' => 0,
'selection_qty' => 1,
'selection_can_change_qty' => 0,
'position' => 0,
'is_default' => 1,
'selection_id' => 72,
'option_id' => 14
)
) //get all selected products list and data
);
$bundleOptions = array();
$bundleOptions = array(
'0' => array(
'title' => 'All Items2',
'option_id' => 14,
'delete' => '',
'type' => 'multi',
'required' => '1',
'position' => '1'
)
);
$bundleProduct->setData('_edit_mode', true);
//flags for saving custom options/selections
$bundleProduct->setCanSaveCustomOptions(true);
$bundleProduct->setCanSaveBundleSelections(true);
$bundleProduct->setAffectBundleProductSelections(true);
//registering a product because of Mage_Bundle_Model_Selection::_beforeSave
Mage::register('product', $bundleProduct);
//setting the bundle options and selection data
$bundleProduct->setBundleOptionsData($bundleOptions);
$bundleProduct->setBundleSelectionsData($bundleSelections);
// echo ''.print_r($bundleProduct,true).''; exit;
$bundleProduct->save();
}
But instead of adding the product items it is deleted my previous options.
Researching this for some time, I found that it was certainly common to build some arrays of product info and "manually build" the bundle product from these arrays, just like you do.
It was surprising, and seems unsophisticated, so it was time to check how Magento handles updating when using the standard Magento Admin Panel. And fact is, Magento actually uses the same technique of building up an array of data. You can edit a bundle product, fire up your Web console, and take a look at the data POSTed in when you save it.
Magento bundle products consist of groups, called options, that contain products, called selections.
To update some bundle product options with new selections, you could create an array like this:
$selectionData = array(
//'selection_id' => 'not set, so Magento will create a new one',
'option_id' => $option->getId(),
'product_id' => $product->getId(),
'delete' => '',
'selection_price_value' => '0.00',
'selection_price_type' => '0',
'selection_qty' => '1.0000',
'selection_can_change_qty' => '1',
'position' => '0',
);
The array structure is a copy of what is POSTed when updating a bundle product in Magento Admin Panel.
You can then use that data to build a new selection, as done in app/code/core/Mage/Bundle/Model/Product/Type.php
$resource = Mage::getResourceModel('bundle/bundle');
$bundleProduct = YOUR_BUNDLE_PRODUCT;
// app/code/core/Mage/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php
$optionCollection = $bundleProduct->getTypeInstance(true)->getOptionsCollection($bundleProduct);
$selectionCollection = $bundleProduct->getTypeInstance(true)->getSelectionsCollection(
$bundleProduct->getTypeInstance(true)->getOptionsIds($bundleProduct),
$bundleProduct
);
$options = $optionCollection->appendSelections($selectionCollection);
// needed because of app/code/core/Mage/Bundle/Model/Selection.php:73
Mage::register('product', $bundleProduct);
// process each option
foreach ($options as $option) {
$selections = $option->getSelections();
// process each selection
foreach ($selections as $selection) {
$usedProductIds = array();
$productCollection = YOUR_PRODUCT_COLLECTION;
foreach ($yourProductCollection as $product) {
$selectionData = array(
//'selection_id' => 'not set, so Magento will create a new one',
'option_id' => $option->getId(),
'product_id' => $product->getId(),
'delete' => '',
'selection_price_value' => '0.00',
'selection_price_type' => '0',
'selection_qty' => '1.0000',
'selection_can_change_qty' => '1',
'position' => '0',
);
// app/code/core/Mage/Bundle/Model/Product/Type.php:315
$selectionModel = Mage::getModel('bundle/selection')
->setData($selectionData)
->setOptionId($option->getId())
->setParentProductId($bundleProduct->getId());
$selectionModel->isDeleted((bool)$selectionData['delete']);
$selectionModel->save();
$selectionData['selection_id'] = $selectionModel->getSelectionId();
if ($selectionModel->getSelectionId()) {
$excludeSelectionIds[] = $selectionModel->getSelectionId();
$usedProductIds[] = $selectionModel->getProductId();
}
}
$resource->dropAllUnneededSelections($bundleProduct->getId(), $excludeSelectionIds);
$resource->saveProductRelations($bundleProduct->getId(), array_unique($usedProductIds));
}
}
Mage::unregister('product');
It is very possible to adapt this to add bundle options as well. I recommend taking a look in the files mentioned in the comments above.

Import product with attributes magento

im using an import script that import's simple and configurable product to magento from xml.
The problem is that, imported simple products are i magento but they don't have attributes values assigned.
Import via APIv2 is working well bu it is to slow, that why i need to do this on model.
my question is:
Is This (code below) correct ? Meybe you have better, different metod to assigne attribute value to product :-)
$product->setData('rozmiar',$Products['sizeId']);
$product->setData('kolor',$Products['colorId']);
my code:
$productCheck = Mage::getModel('catalog/product')->loadByAttribute('sku', $products['sku']);
if ($productCheck) {
$productCheck->delete();
//print_r('true !');
}
$color = attributeValueExists1('kolor',$Products['color']);
$size = attributeValueExists1('rozmiar',$Products['size']);
$product = Mage::getModel('catalog/product');
$product->setCreatedAt(strtotime('now'));
$product->setTypeId($products['type']);
$product->setTaxClassId(0);
$product->setWebsiteIds(array(1));
$product->setAttributeSetId($products['attrset']);
$product->setSku($products['sku']);
$product->setName($products['name']);
$product->setDescription($products['description']);
$product->setInDepth('');
$product->setPrice($products['price']);
$product->setShortDescription($products['description']);
$product->setWeight(0);
$product->setStatus(1);
$product->setVisibility(1);
//$product->setMetaDescription($products['name']);
//$product->setMetaTitle($products['name']);
//$product->setMetaKeywords($products['name']);
$product->setCategoryIds($products['categories']);
$product->setKolor($color);
$product->setRozmiar($size);
//$product->setData('rozmiar',$Products['size']);
//$product->setData('kolor',$Products['color']);
$product->setStockData(array(
'use_config_manage_stock' => 0,
'manage_stock'=>1,
'min_sale_qty'=>1,
//'max_sale_qty'=>2,
'is_in_stock' => 1,
'qty' => $products['qty']
)
);
$product->save();
Importing products via Soap APIv2 im using
$result = $this->client2->catalogProductCreate($this->session, $type, /*$attributeSet['set_id']*/ '4', $kod, array(
'categories' => $kategorie, // array !!!!
'websites' => array(1),
'name' => $nazwa,
'description' => $opis,
'short_description' => $opis,
'weight' => '1',
'status' => '1',
'url_key' => $nazwa,
'url_path' => $nazwa,
'visibility' => '1',
'price' => $cena,
'tax_class_id' => 1,
'meta_title' => '',
'meta_keyword' => '',
'meta_description' => '',
'stock_data' => array( 'manage_stock' => '1',
'manage_stockSpecified' => False,
'is_in_stock' => '1',
'is_in_StockSpecified' => False,
'qty' => $ilosc
),
'additional_attributes' => $additionalattr
));
return $result;
Is additional_attributes different from $product->setData('rozmiar',$Products['sizeID']); ?
If it's not the same how can i add additional_attributes when importing products via catalog/product model ?
First you need to assign corresponding attributes to products. Then after you can use import script to save those attributes value to products.

Magento Cart_Product.Add Custom Options File Upload via Soap API

Can not achieve to upload a file via soap api to Cart. I want user to add a product to cart with a required custom option which is an image.
So spent hours, can not find any resource/documentation/same problem anywhere but actually figure out, soap api requires array (ok, but what are the parameters?) And It does not throw any error if something goes wrong (weird?)
So in practice what I am willing to achieve:
// Prepare image
$newImage = array(
'file' => array(
'name' => $_FILES['uploadedfile']['name'],
'content' => base64_encode(file_get_contents($_FILES['uploadedfile']['tmp_name'])),
'mime' => 'image/png'
),
'label' => $_FILES['uploadedfile']['name']
);
// Prepare product & Custom options
$arrProducts = array(
array(
'product_id' => '7',
'qty' => 1,
'options' => array ( '30' => $newImage ) // optionId_1 => optionValue_1
)
);
// lets do adding
$resultCartProductAdd = $client->call(
$session,
'cart_product.add',
array(
$quoteId,
$arrProducts
)
);
The problem is, the image is not uploaded to /media/custom_options/quote folder where should belongs to and when order complete can not see anywhere. As I mentioned, there is no error thrown while this process..
Thanks for helping me out.
Please try this....
$arrProducts = array(
array(
'product_id' => '7',
'qty' => 1,
'options' => array ( 'options_30_file' => $newImage,'options_30_file_action'=>'save_new' )
)
);
or
$arrProducts = array(
array(
'product_id' => '7',
'qty' => 1,
'options_30_file' => $newImage,
'options_30_file_action'=>'save_new'
)
);
Let me if any issue

Categories