I need to create a new configurable product via Magento Soap API and add a related product to it.
I use this code that create 2 products ( one simple and one configur. ) then i try to link the simple one to the config one...this don't work..
There is a tutorial for do that??
Any help??
Many thanks.
// Magento login information
$mage_url = 'http://test.de/api/?wsdl';
$mage_user = 'admin';
$mage_api_key = 'admin';
// Initialize the SOAP client
$soap = new SoapClient( $mage_url );
// Login to Magento
$session = $soap->login( $mage_user, $mage_api_key );
$attributeSets = $soap->call($session,'product_attribute_set.list');
$set = current($attributeSets);
$sku = 'iphone-12345';
//configurable
$newProductData = array(
'name' => 'iPhone',
'websites' => array(1),
'short_description' => 'short description',
'description' => 'description',
'price' => 150,
'status' => '1',
'categories' => array(138),
);
$newProductRelated = array(
'name' => 'iPhone',
'websites' => array(1),
'short_description' => 'short description',
'description' => 'description',
'price' => 150,
'status' => '1',
'sku' => '2551464'
);
$productId = $soap->call($session,'product.create',array('configurable', $set['set_id'], $sku ,$newProductData));
$productId2 = $soap->call($session,'product.create',array('simple', $set['set_id'], $newProductRelated['sku'] ,$newProductRelated));
$soap->call($session, 'product_link.assign', array('configurable', $sku, $newProductRelated['sku'], array('position'=>0, 'colore'=> 21, 'qty'=>6)));
mant thx again.
Dealing with a similar issue and resorted to using the CSV import to create the relation for products imported from the API. This may may be a usable approach for a one time import via a generated CSV.
Related
Can we upload multiple image to the variation using API. Single image upload can be possible using below code, but not sure about multiple image upload.
$mediaId ='random string';
$url = $images['url'];
$mediaData = array(
array(
'id' => $mediaId,
'mediaFolderId' => $mediaFolderID,
),
);
$mediaDataArr = array(
'payload' => array(
"action" => "upsert",
"entity" => "media",
'payload' => $mediaData,
),
);
$createMedia = $shopware6HelperObj->post('_action/sync', $mediaDataArr);
$urlArr = array(
'url' => $url,
);
$parts = pathinfo($url);
$params = array(
'extension' => $parts['extension'],
'fileName' => $parts['filename'] . '__' . md5(time()),
);
$uploadImage = $shopware6HelperObj->post('_action/media/' . $mediaId . '/upload', $urlArr, $params);
Please suggest if any idea.
I always recommend to try doing that via the Admin Panel and check the Browser's Dev Tools / Network Tab which requests are made. This can give you a good hint on how do to it programmatically.
$prospectData = array(
'user_key' => $user_key,
'api_key' => $api_key,
'first_name' => $firstName,
'last_name' => $lastName,
'city' => $city,
'state' => $state,
'comments' => $comments
);
callPardotApi('https://pi.pardot.com/api/prospect/version/4/do/create/email/'.$email, $prospectData);
I'm able to create a new prospect with a form that I have. It inserts all the data I supplied it (name, city, state, etc), but I need to also add this prospect to a list.
I tried adding to my $prospectData things like list => '1234' or "list_id" => '1234', but that doesn't seem to be working.
Is this possible to do? I know I can assign a prospect to a list via another api route using their ID, but I need this prospect to be added immediately upon form submit
Well it's not exactly ideal, but I had to do a new api call after creating the user.
$addprospect = callPardotApi('https://pi.pardot.com/api/prospect/version/4/do/create/email/'.$email, $prospectData);
$addprospectxml = new SimpleXMLElement($addprospect);
$id = $addprospectxml->prospect->id;
$listData = array(
'user_key' => $user_key,
'api_key' => $api_key,
'list_32106' => "1"
);
$updateProspect = callPardotApi('https://pi.pardot.com/api/prospect/version/4/do/update/id/'.(String)$id[0], $listData);
When creating a prospect, it will return XML with the newly crated prospect's ID. that ID can be used in a new api update call where you can set the list.
I'm trying to display all images that have a certain custom field from the types plugin set to true. It would also work to filter them by post_content or post_excerpt but none of my attempts have worked so far.
<?
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_content' => 'foo',
'numberposts' => -1
);
?>
<? print_r(get_posts($args)); ?>
This get's all images allthough only one has the post_content foo. My attempt to use WP_Query failed miserably as well.
Any help is appreciated!
WP_Query method :
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'meta_query' => array(
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'LIKE',
),
),
);
$query = new WP_Query( $args );
I am presuming that the reason why you failed with WP_Query is due to the following condition.
Codex states : The default WP_Query sets 'post_status'=>'publish', but attachments default to 'post_status'=>'inherit' so you'll need to explicitly set post_status to 'inherit' or 'any' as well.
http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
get_posts method :
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'meta_key' => 'custom-field',
'meta_value' => 'custom value',
'numberposts' => -1
);
print_r(get_posts($args));
The only draw back with this method is that the meta_value needs to exactly match what was entered in the custom field. If you still like to use get_posts then use the meta_query as shown in WP_Query example above.
Hello I am using bootstrap.widgets.TbSelect2 in Yii.
You can see this link to check my form.
https://www.diigo.com/item/p/qoaqepdzbsbbaqeqdzbcbrsdpa/bc91ebd999371bef68737b8320afed91
How to add the data in TbSelect2?
thank you.
its so simple , just generate an array for this
$this->widget('bootstrap.widgets.TbSelect2', array(
'asDropDownList' => true,
'name' => 'status',
'data' => array( // свои значения для option
'active' => 'Active',
'pending' => 'Pending',
'invited' => 'Invited',
'deleted' => 'Deleted'
),
)
);
i am trying to add product from frontend programatically following this link :
Magento: Adding new products programmatically
but i want to extend it to add custom options too to it .And i added the following code to it
$options = array();
$options[$sku] = array(
'title' => 'Option Title',
'type' => 'radio',
'is_require' => 1,
'sort_order' => 0,
'values' => array()
);
$options[$addvp['product']['sku']]['values'][] = array(
'title' => 'Option Value 1',
'price' => 0.00,
'price_type' => 'fixed',
'sku' => '',
'sort_order' => '1'
);
$options[$sku]['values'][] = array(
'title' => 'Option Value 2',
'price' => 89.00,
'price_type' => 'fixed',
'sku' => '',
'sort_order' => '1'
);
foreach($options as $sku => $option) {
$id = Mage::getModel('catalog/product')->getIdBySku($sku);
$product = Mage::getModel('catalog/product')->load($id);
if(!$product->getOptionsReadonly()) {
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);
//$product->save();
}
}
but it prints this error instead of adding custom option to product.
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`vendor`.`catalog_product_entity`, CONSTRAINT `FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribute_set_id`) ON DEL)
http://www.fontis.com.au/blog/magento/add-product-custom-options
Note:
The above link did what i want it to do. But one thing to be kept in mind that you must add the custom option to a product already exists/saved.
I had a similar issue. Turned out that the auto-generated SKU was somehow invalid or not properly saved on the new product I created for testing. The product was not invalid, as it did save properly on the first go, but when I revisited the product via the CMS and tried to click "save and continue" it suddenly prompted me to enter a SKU. When I re-entered the auto-generated sku it worked!
So the short answer would be: Check that your product exists by that SKU number. If it does, re-check that the SKU is being saved properly.