is there a way to batch update products or orders using bigcommerce api?
I need to update multiple products with just one call if possible.
If your using the PHP library which can be downloaded # https://github.com/bigcommerce/auspost-api-php
I first made a local database of products using the following calls...
$filter = array('limit' =>, 'page' =>1);
Bigcommerce::getProducts($filter);
foreach($products as $product){
$sku = $product->SKU;
$id = $product->id;
/* write some code in the loop to add all the products to your DB */
}
Once you have a DB of all your products you can make SQL call with SELECT ALL from your Database and update them with some static content like below(put below in a loop for each product)....
$UpdateQuery = array('description' => 'Some Random Text added to all descriptions')
Bigcommerce::updateProduct($Bicommerce_Product_ID,$UpdateQuery)
This would bulk add 'Some Random Text added to all descriptions' too products in your database. You need to use the Bigcommerce product ID in each loop to target it and update in 'bulk'.
Hope this is useful - can verify it works as use it myself :)
Related
I've got a WooCommerce set up where I currently need to do two things. The first is to move data that is currently in the post.excerpt field to an ACF field that I've created specifically for the purpose while the second is to update the post.excerpt field with new data. All the product data is in SQL-Server Express because the product data came from another website that we're replacing with the WooCommerce one. I exported all the Woocommerce products with basic info like the product ID, SKU, Title and Post_Content and wrote a query in SQL-Server to match the two together. That's been exported as a flat file and imported into MySQL. Now I've writen a query to update the post.excerpt field but what I can't find is a way to update the ACF field in the same query (or another one).
set
'wp.posts'.'post.excerpt' = 'updatelist'.'excerpt'
From 'updatelist'
where
'wp_posts'.'ID' = 'updatelist'.'product_id'
Can anyone help? Please don't suggesting importing a CSV file. There's 180,000 products and using a csv, well it's about 10% of the way through and has taken, so far, 24 hours.
To update ACF fields, first i would usually prepare an aray of key-value pairs of ACF fields to loop over and update them:
# first prepare your array of ACF fields you need to update
acf_fields = [
'field_5f70*********' => 'product_name',
'field_5f80*********' => 'product_color',
'field_5f90*********' => 'product_price'
];
# to find the key values for your own ACF fields, just go to admin dashboard under custom fields, select your group of ACF fields and then on the "Edit Field Group" you see those keys. If you don't see them, choose "screen options" and select "fields keys".
# Now we're going to loop over them and update each field
foreach(acf_fields as $key => $name){
update_field(a, b, c);
# a = $key
# b = value to be updated which comes from your old list (from querying your list)
# c = which post it belongs to (custom query for your custom post type that contains ACF fields)
};
That's how i update my ACF fields, there are other methods using Wordpress REST API too.
I'm a beginner in Prestashop, I'd like to modify my website. I want to delete automatically a product if the promotion end is outdated.
For the special offers (promotions), the end date is written with $product.specific_prices.to.
I want to delete the article where the date of this variable is equal to the current date. But I don't know how to do it... In the templates? For example :
{if ($smarty.now|date_format:'%Y-%m-%d %H:%M:%S' <= $product.specific_prices.to) && ($product.specific_prices.to != '0000-00-00 00:00:00')}
With a trigger in DB?
CREATE EVENT IF NOT EXISTS `Clean_End_Promotion`
DELETE FROM products
WHERE promo_date == NOW() //but I don't which table I can use
With PHP files? I don't know which way is the best.
Thanks!
What about this? Create a new custom PHP file (include init;config.php files to access database or write connection).
$today = date("Y-m-d H:i:s");
$sql = 'SELECT id_product FROM `'._DB_PREFIX_.'specific_price` WHERE to >= '.$today;
$result = Db::getInstance()->execute($sql);
Foreach ($result as $res) {
$prod = new Product($res);
$prod->delete();
}
I dont know I haven`t test it and I have never used delete function but check product class for more info. Product->delete should remove all data from all tables.
I want to replace certain letters inside the product description of every product in my magento shop. There is a way to run a script via phpMyAdmin (SQL). There is a REPLACE function for that:
REPLACE( string1, string_to_replace, replacement_string )
But how would I do the rest of the code? How do I get access to the cells with the description in it?
Thanks in advance!
EDIT: More Detail:
I want to make a SQL Statement that loops through every product and change parts of the product description with the help of the REPLACE function.
You should avoid doing direct SQL on your Magento instance. If you want to update the product descriptions, you can use the catalog model for this - or even the export/import routine. Here's how to do it programmatically - create the below and put it in the root directory of your Magento website.
include_once "app/Mage.php";
Mage::init();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$yourstring = 'The string you want to find';
$newstring = 'The string you want to replace it with';
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->load();
foreach($_productCollection as $_product) {
if (strpos($_product->getDescription(),$yourstring) !== false) {
$newdescription = str_replace($yourstring,$newstring,$_product->getDescription());
$_product->setDescription($newdescription);
$_product->save();
echo 'Updated product: '.$_product->getName().'<br />';
}
}
I am using the following code to load a categorys record:
$res = JTable::getInstance('category');
$res->load(array('id' => $catid));
Now I would like to load the record based on its title which whould be matched against a SQL LIKE-pattern - is it possible to do this in a simple way with JTable, or do I need $dbo?
Far as I know JTable is made to be simple and carry only one element at a time, and through the primary key. If you really want something more advanced, I recomend that you use JDatabaseQuery way.
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all articles for users who have a username which starts with 'a'.
// Order it by the created date.
$query
->select(array('a.*', 'b.username', 'b.name'))
->from('#__content AS a')
->join('INNER', '#__users AS b ON (a.created_by = b.id)')
->where('b.username LIKE \'a%\'')
->order('a.created DESC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects.
$results = $db->loadObjectList();
In your case, instead of "$db->loadObjectList();" you can use "$db->loadObject();" for load just one item.
Source:
http://docs.joomla.org/Accessing_the_database_using_JDatabase/3.1
I am missing the SQL out of this to Bulk update attributes by SKU/UPC.
Running EE1.10 FYI
I have all the rest of the code working but I"m not sure the who/what/why of
actually updating our attributes, and haven't been able to find them, my logic
is
Open a CSV and grab all skus and associated attrib into a 2d array
Parse the SKU into an entity_id
Take the entity_id and the attribute and run updates until finished
Take the rest of the day of since its Friday
Here's my (almost finished) code, I would GREATLY appreciate some help.
/**
* FUNCTION: updateAttrib
*
* REQS: $db_magento
* Session resource
*
* REQS: entity_id
* Product entity value
*
* REQS: $attrib
* Attribute to alter
*
*/
See my response for working production code. Hope this helps someone in the Magento community.
While this may technically work, the code you have written is just about the last way you should do this.
In Magento, you really should be using the models provided by the code and not write database queries on your own.
In your case, if you need to update attributes for 1 or many products, there is a way for you to do that very quickly (and pretty safely).
If you look in: /app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php you will find that this controller is dedicated to updating multiple products quickly.
If you look in the saveAction() function you will find the following line of code:
Mage::getSingleton('catalog/product_action')
->updateAttributes($this->_getHelper()->getProductIds(), $attributesData, $storeId);
This code is responsible for updating all the product IDs you want, only the changed attributes for any single store at a time.
The first parameter is basically an array of Product IDs. If you only want to update a single product, just put it in an array.
The second parameter is an array that contains the attributes you want to update for the given products. For example if you wanted to update price to $10 and weight to 5, you would pass the following array:
array('price' => 10.00, 'weight' => 5)
Then finally, the third and final attribute is the store ID you want these updates to happen to. Most likely this number will either be 1 or 0.
I would play around with this function call and use this instead of writing and maintaining your own database queries.
General Update Query will be like:
UPDATE
catalog_product_entity_[backend_type] cpex
SET
cpex.value = ?
WHERE cpex.attribute_id = ?
AND cpex.entity_id = ?
In order to find the [backend_type] associated with the attribute:
SELECT
backend_type
FROM
eav_attribute
WHERE entity_type_id =
(SELECT
entity_type_id
FROM
eav_entity_type
WHERE entity_type_code = 'catalog_product')
AND attribute_id = ?
You can get more info from the following blog article:
http://www.blog.magepsycho.com/magento-eav-structure-role-of-eav_attributes-backend_type-field/
Hope this helps you.