I want to add products in bigcommerce store using bigcommerce Api PHP.
My code is like below:
$fields = array( "name" => "Apple" );
BigCommerce_Api::createBrand($fields);
store is connected successfully but products are not creating.Please help...
It looks like you are creating a brand and not a product. If you want to create a product, you can do something like below -
$filter = array('name' => 'iPhone sticker', 'price' => '12.99', 'categories' => array(2), 'type' => 'physical', 'availability' => 'available', 'weight' => 0);
$product = Bigcommerce_Api::createProduct($filter);
$new_product = new Bigcommerce_Api_Product();
$new_product->name = $_POST['name'];
$new_product->type= "type";
$product = $new_product->create();
You can create brand by using xml,please check below code :
BigCommerce_Api::useXml();
$xml = '<brand>
<name>'.$product[brand_name].'</name>
</brand>';
$brand_exe = BigCommerce_Api::createBrand($xml);
Related
i have a ParentItem model
$parentItem = ParentItem::get()->first();
I have this array
$items = array(
array(
'title' => 'test1',
'desc' => 'test1'
),
array(
'title' => 'test2',
'desc' => 'test2'
)
);
i want to add it as a has many relationship.
so i can do:
foreach($items as $item) {
$parentItem->items()->create($item)
}
is there any way way to create all at once..?
something like:
$parentItem->items()->createMany($items);
You can tryout two path.
Using saveMany method:
$parentItem = ParentItem::first();
$items = array(
new Item(['title' => 'test1','desc' => 'test1']),
new Item(['title' => 'test2','desc' => 'test2'])
);
$parentItem->items()->saveMany($items)
For further info you can read here.
https://laravel.com/docs/5.1/eloquent-relationships#inserting-related-models
Using insert method:
$parentItem = ParentItem::first();
$items = array(
array('title' => 'test1','desc' => 'test1','parent_item_id' => $parentItem->id),
array('title' => 'test2','desc' => 'test2','parent_item_id' => $parentItem->id)
);
Item::insert($items);
Remember in insert created_at and updated_at won't be inserted automatically, you have to provide them in the array if you have them in your table. For further info you can read here.
https://laravel.com/docs/5.1/queries#inserts
As of right now, you may use the createMany Eloquent method to achieve this.
Details here: https://laravel.com/docs/9.x/eloquent-relationships#the-create-method
I'm new on Magento and I have problems to show stock of configurable product. I have tried a lot of things that I found on Google, Stackoverflow, Magento Forums, but I failed. Here is the only solution that I cannot try:
$_product is your configurable product.
To get all its simple use :
$_product->getTypeInstance(true)->getUsedProducts ( null, $_product);
So you might have something like :
foreach ($_product->getTypeInstance(true)->getUsedProducts ( null,
$_product) as $simple) {
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($simple)->getQty();
echo $simple->getName()." with size ".$simple->getSize()." have a stock of $stock";
echo ''; } I let you adapt to your precise needs and ask question if needed
My problem is: I don't know where I can apply this solution!
()
You need to perform two step to get this working however I have checked this with version 1.8 but hope it will work in your case also
step 1. copy file app/code/core/mage/catalog/block/product/view/type/configurable.php
And create a folder under app/code/local with same directory structure mage/catalog/block/product/view/type/configurable.php
Now find function name getJsonConfig in configuration.php file.
Go to following code
$info['options'][] = array(
'id' => $value['value_index'],
'label' => $value['label'],
'price' => $configurablePrice,
'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
'products' => $productsIndex,
);
Before this code place below two lines of code
$simpleproduct = Mage::getModel('catalog/product')->load($productsIndex);
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
Here you can see that i'm getting product stock by product id, now in info option array code you have to add one parameter
$info['options'][] = array(
'id' => $value['value_index'],
'label' => $value['label'],
'price' => $configurablePrice,
'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
'products' => $productsIndex,
'qty' => $qty, // we are sending stock parameter so we can use it latter in drop down field
);
step 2. Now go js/varian/configuration.js
find the following line
if(allowedProducts.size()>0){
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
Place following line under this
element.options[index].innerHTML += " Stock is :"+options[i].qty;
that's it all about cheer
Let me know if you have any query
with app/code/local/Mage/Catalog/Block/Product/View/Type/Configurable.php
$simpleproduct = Mage::getModel('catalog/product')->load($productsIndex);
$qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($simpleproduct)->getQty();
$info['options'][] = array(
'id' => $value['value_index'],
'label' => $value['label'],
'price' => $configurablePrice,
'oldPrice' => $this->_prepareOldPrice($value['pricing_value'], $value['is_percent']),
'products' => $productsIndex,
'qty' => $qty, // we are sending stock parameter so we can use it latter in drop down field
);
$optionPrices[] = $configurablePrice;
}
}
and at js/varien/configurable.js
if(allowedProducts.size()>0){
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
if (typeof options[i].price != 'undefined') {
element.options[index].setAttribute('price', options[i].price);
}
element.options[index].innerHTML += " Stock is :"+options[i].qty;
element.options[index].config = options[i];
index++;
}
isn't working at 1.9.4... is it something wrong?
I'm getting the below error while building taxonomy voccabulary and terms using the following code
FieldException: Attempt to create an instance of a field field_my_custom_vocab002 that doesn't exist or is currently inactive. in field_create_instance() (line 476 of C:\wamp\www\pur_theme\modules\field\field.crud.inc).
I checked the voccabulary and it is created, the problem is only with term creation
code
<?php
$new_vocab = (object) array(
'name' => 'My custom vocabulary002',
'description' => 'Test',
'machine_name' => 'my_custom_vocab002',
);
taxonomy_vocabulary_save($new_vocab);
$vocab = taxonomy_vocabulary_machine_name_load('my_custom_vocab002');
$term1 = (object) array(
'name' => 'Term 1',
'description' => 'This is term 1',
'vid' => $vocab->vid,
);
taxonomy_term_save($term1);
What/where did I wrong?
I think it's because you try to create a term with more fields than the 2 basical ones (name and vid). You have a "description" field in addition.
Try this code instead:
$term = new stdClass();
$term->name = 'Term 1';
$term->vid = $vocab->vid;
$term->field_description[LANGUAGE_NONE][0]['value'] = 'This is term 1';
taxonomy_term_save($term);
Source: http://www.lightrains.com/blog/programmatically-create-taxonomy-term-drupal
I found the only solution to this was to create the field it's looking for before creating the vocabulary. Personally I did this with a custom function:
function MY_MODULE_create_new_taxonomy($taxonomy_name, $taxonomy_machine_name, $taxonomy_description){
//Add field you know is going to cause trouble
$field = array(
'field_name' => 'field_'.$taxonomy_machine_name,
'type' => 'text',
'label' => 'Label'
);
field_create_field($field);
//create the vocab
$new_vocabulary = new stdClass();
$new_vocabulary->name = $taxonomy_name;
$new_vocabulary->machine_name = $taxonomy_machine_name;
$new_vocabulary->description = t($taxonomy_description);
$new_vocabulary->module = 'taxonomy';
taxonomy_vocabulary_save($new_vocabulary);
}
I'm working on a module where I need to save the records based on the scope of website and store. For that I need to have the select box as its in the system->configuration.
How can I get that select box in my form and save the website/store value in database so that it can be displayed in the specific store/website? Any suggestions on it?
Now I'm trying it breaking into two fields -> website and store. Now, how can I change the options in store based on the website selected?
Finally, I'd written my own code for this.
$scope = array('default' => 'default');
foreach (Mage::app()->getWebsites() as $website) {
$scope['website_' . $website->getCode()] = $website->getName();
foreach ($website->getGroups() as $group) {
$stores = array();
foreach ($group->getStores() as $store) {
$stores[] = array(
'label' => $store->getName(),
'value' => 'store_' . $store->getCode()
);
}
$scope[] = array(
'label' => $website->getName(),
'value' => $stores
);
}
}
$fieldset->addField('website', 'select', array(
'label' => Mage::helper('designer')->__('Website'),
'name' => 'website',
'values' => $scope
));
Thanks to this post by Marius
I've been looking all over the web but I can't seem to find any examples and I've tried it but failed. I am using version 2 of the api and I want to find product that filters by a customer attribute like so...
$filter = array(
array(
'key'=>'custom_attribute',
'value'=>"463"
)
);
$products = $client->catalogProductList($session,array(
'filter'=>$filter
));
But I am getting all the products and not the specific product I am looking for. Is there anything I am doing wrong ? Is there anything I am missing ??
Try following code.
$complexFilter = array (
'complex_filter' => array(
array(
'key' => 'custom_attribute',
'value' => array(
'key' => 'eq',
'value' => '463'
)
)
)
);
$products = $client->catalogProductList($session, $complexFilter);