Mass Stock Update allows you to update all your product stocks in Magento in no time thanks to CSV and XML files available from your website's server, from remote servers through FTP or HTTP.
How to configure Mass Stock Update
To use Mass Stock Update, you have to go in:
SystemConfigurationWyominDMass Stock Update
Configure Mass Stock Update in a general way
Email reporting
Mass Stock Update includes a reporting tool that notifies you each time a cron task runs, and so if any error happens.
For more details about the cron tasks, look at the below section:
Configure the cron tasks in a profile
Enable reporting
Send the reports to
For several email addresses, you must use the comma as a separator.
Report title
List ignored products in the report
Settings
Mass Stock Update also includes a log file that you can enable.
Enable log file
The file is named Wyomind_MassStockUpdate.log.
System Configuration Advanced Developer Logs settings
Create an update profile in Mass Stock Update
To update all your stocks in Magento you can update or create a new profile by clicking on Create a new profile from:
SystemImport/ExportMass Stock Update
Black box
The black-box is a tool that will help you configure your mapping seamlessly. It is composed of 3 major features.
Input Data Preview
To get a preview of the input data, click on Input data.
Output Data Preview
Clicking on Output data will give you a preview of the data as they'll be updated.
Library
The library allows you to check what values you can use for each attribute.
Settings
In this section, you will be able to define the source of the data.
Profile Settings
- Profile name:
Only alphabetic and numbers are allowed + hyphens (-) and underscores (_).
Profile's name must be unique. - SQL mode:
Note that when SQL mode is enabled, data are not updated and a SQL file is generated.
If you activate SQL mode, you'll need to fill in several fields:
- SQL file path:
is where the SQL file will be generated (relative to Magento root folder). - SQL file name:
is the name of the SQL file to generate.
File Location
This section allows you to specify where the source data file is stored. You have many options:
- Magento File System
The file is stored in the Magento root directory or a subdirectory of the Magento root directory. - FTP server
The file is stored on a remote server available from FTP or SFTP - Url
The file is stored on a remote server available from HTTP or HTTPS.
If you're using the authentication, add the login and password directly in the corresponding fields. - Dropbox
The file is stored in a dropbox. You can generate your token from your Dropbox account https://www.dropbox.com/developers/apps - Webservice
The file can be stored in any web service.
File Type
- File type
You have the choice between CSV and XML files.
For CSV files:
- Field separator
Define the field separator. - Field enclosure
Select the field enclosure.
For XML files:
- Xpath to products
In case of an update from an XML file, fill in the XPath that targets the products. The Xpath is case sensitive.
File sample
The XPath that targets the products in the above file is /Import/PRODUCTS/product<Import> <PRODUCTS> <product> <name>Product A</name> <sku>001A</sku> <qty>864</qty> </product> <product> <name>Product B</name> <sku>002B</sku> <qty>594</qty> </product> </PRODUCTS> </Import>
- XML structure
You have two options; the Automatic detection or the Predefined structure. The automatic detection fits for simple files made of only one nesting level such as the above file sample. - Predefined structure
If you've selected the Predefined structure, you have the possibility to define your own file structure. When the structure of your file is quite complex, the info may be dispatched in deep nodes and sometimes in tag attributes such as url="something".
Below is an example of a complex file where you need a predefined structure:
The XPath that targets the products in the above file is /products/item<products> <item> <sku><![CDATA[XYZ]]></sku> <qty value="150"/> <options> <option name="backorders">2</option> <option name="minimal_in_cart">10</option> </options> </item> </products>
The JSON syntax you need to use is:{ "sku":"sku", "qty":"qty/@value", "backorders":"option[@name='backorders']", "minimal_qty":"option[@name='minimal_in_cart']" }
DIRECTIONS FOR USE IN THE PREDEFINED XML STRUCTURE FIELD
- Use a valid Json string made of a key/value list that defines the column names and the Xpath associated with the columns.
- Use @ to access the attribute values.
@price - Use [@attribute=value] to access a node from which the attribute is value.
[@name='ean'] - Use [number] to access another node that has the same name.
category - Use Xpath axis to represent a relationship to the current node, and locate nodes.
child::item
Post Process Action
You have the possibility to define an action after the file is processed, between:
- Do nothing
- Delete the import file
- Move the import file
You need to define the file path where you want to move the import file, relative to your Magento root folder.
Advanced Settings
System Settings
- The first line is a header
For CSV files, you need to specify when the first line is a header. - Filter lines
Leave empty to export all lines:
e.g:
means all lines will be imported
Type the numbers of the lines you want to import, making sure to separate each line or range with a comma (,):
e.g: 2,4,6,8,10
means lines 2,4,6,8,10 will be imported
Use a dash (-) to denote a range of lines:
e.g: 8-10
means lines 8,9,10 will be imported
Use a plus (+) to import all lines from a line number:
e.g: 4+
means all lines from line 4 will be imported
Stock Settings
Automatic stock status update
You can choose to automatically update the stock status (in stock / out of stock).
Mapping & Rules
In this section, you can map each column of the file with one of the stock attributes.
Column Mapping
- Target Attribute
Select the target attribute from the ones available in your system (the first line is where you define the identifier of your products). You can find all the attributes grouped by type in our documentation. - Data source
In the Data source, you can define the attribute source that matches with the target attribute from your source file. - Custom value
Sometimes, some columns can be missing. For example, when updating all stocks, the file does not necessarily include all stock attributes (backorders, minimum quantity in the cart...). In that case, you can choose a custom value in the Data source and apply a default value.
QUICK OVERVIEW OF THE INTERFACE
- Add as many columns as you want by clicking on +. In many cases, the update file may contain more columns than necessary; you don't need to add these columns and match them.
- Delete a row easily.
- Change the order of each row using the drag and drop.
- Deactivate a line while conserving the settings by clicking on the link symbol.
- Add your own custom script </>. These scripts can be previewed in the output. Check How to use the API.
Note that when there is a script filled in </> is underlined. - Apply the color of your choice to the row.
- Apply a label to the row.
- Preview your file by clicking INPut Data.
- Find all the attributes grouped by type in the Library.
- Check the data as they'll be updated by clicking Output Data.
Scheduled tasks
You can schedule the profile to be executed each day of the week and with an interval of 30 minutes (by default) between each execution.
You can change the cron task interval from:
SystemConfigurationWyomindMass Stock UpdateSettings
Run a Mass Stock Update profile
You have several ways to run your profiles.
From the profiles grid
To run the profile from the grid, you just need to click on RUN Profile in the action menu on the right column. Then the status will be updated with a progress bar.
From the profile page
Open the profile by clicking on the edit option in the action menu in the right column of the profile, and then click on RUN Profile
With the cron tasks
When the scheduled tasks are configured for the profile, then the profile will be automatically run at the day and the time selected.
For a good working of the scheduled tasks in Mass Stock Update, the main cron task in Magento must be configured properly.
Look at the official Magento user guide for more details about how to configure the cron tasks in Magento:
http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html
You will receive an email each time the cron task is run if you have enabled the reporting in:
system configuration Mass Stock Update
With the Command Lines Interface
Mass Stock Update includes command lines available from the terminal.
php -f shell/wyomind_massstockupdate.php -- [options]
The parameters to use are:
- -h
Short alias for help - --run id1,id2,...,
idN
Generate profile from the given list - --sql id1,id2,...,idN
Execute the sql file generated by the profile from the given list - --list
List all profiles
SQL option usage
Updating stocks massively may keep your server busy for a while, especially when the update includes lot of data.
For better performances Mass Stock Update splits the process into two distinct steps:
- Source file analysis: the data are collected and the SQL queries for the update are built.
- The SQL file execution: the database is updated with the new data. This step may be executed asynchronously when SQL mode is enabled.
Generate the SQL file
If you prefer to generate the SQL file without executing it, you must enable the SQL mode in your profile configuration.
Then run the profile by clicking on RUN Profile NOW.
Execute the SQL file
Once the file is generated in the working directory (see Settings), you only need to update the database with the generated file from the command line as follows:
mysql -h host -p DbPassword -u DbLogin DatabaseName < path/to/mysql/file.sql
You can also use the command line:
php -f shell/wyomind_massstockupdate.php --sql id1
Advanced Use
The event "mass_update_success" is triggered when the profile is run and the data successfully updated or imported.
The event is dispatched when the profile is successfully run and can be used in your custom observers. The parameter given in the observer is the running profile.
Event dispatch:
Mage::dispatchEvent("mass_update_success", array("profile" => $this));
Example of use in an observer:
class Editor_Module_Model_Observer
{
/**
* @param $observer
*/
public function execute($observer)
{
return var_dump($observer->getProfile()->getData());
}
}
Attribute specifications
Stock attributes
All these attributes must be updated with numeric values or boolean values.
- Multi-stock enabled (Advanced Inventory only, boolean)
- Qty (float or integer)
- Min Qty (float or integer)
- Use Config Min Qty (boolean)
- Is Qty Decimal (boolean)
- Backorders (integer)
- Use Config Backorders (boolean)
- Min Sale Qty (float or integer)
- Use Config Min Sale Qty (boolean)
- Max Sale Qty (float or integer)
- Use Config Max Sale Qty (boolean)
- Is In Stock (boolean)
- Notify Stock Qty (boolean)
- Use Config Notify Stock Qty (boolean)
- Manage Stock (boolean)
- Use Config Manage Stock (boolean)
- Stock Status Changed Automatically (boolean)
- Use Config Qty Increments (boolean)
- Qty Increments (float or integer)
- Use Config Enable Qty Increments (boolean)
- Enable Qty Increments (boolean)
- Is Divided into Multiple Boxes for Shipping (boolean)
Boolean values
- 1 / 0
- yes / no
- true / false
- enable / disable
- enabled / disabled
- in stock / out of stock
Numeric values
- Integer number (no white space)
- Float number (decimal separated by a dot)
Advanced Inventory attributes
All attributes related to the stock management in Advanced Inventory are available in this section.
All these attributes must be updated with numeric values or boolean values.
- Warehouse - Qty (float or integer)
- Warehouse - Manage stock (boolean)
- Warehouse - Backorders allowed (integer)
- Warehouse - Use config settings for backorders (boolean)
Boolean values
- 1 / 0
- yes / no
- true / false
- enable / disable
- enabled / disabled
- in stock / out of stock
Numeric values
- Integer number (no white space)
- Float number (decimal separated by a dot)
PHP API for Mass Stock Update
Mass Stock Update allows you to fully customize and control the data output by using PHP scripts in different ways.
API coding standards
For each line in the Mapping & Rules tab of your profile, you can add your own custom script based on a PHP syntax.
To add your custom script, click on </> at the end of the line you want to edit. You can then update on the file the value of each column.
Note that the </> button may be hidden by the black box.
Opening and closing tags
<?php
/* Your custom script */
return $self;
Outputting a value
return
Any value that you want to output in your profile, must be returned with the return instruction.
$this object
$this->skip() or return false (boolean false)
To ignore the pending line (all the columns of the line).
$this->skipRow() or $this->skip() or return false;
To ignore the pending cell as well as all the following cells.
$this->skipCell() or return true;
To ignore the pending cell.
Variable $cell
You can call any column of the source file using $cell. It is an array that indexes each column numerically (1,2,3,...) and with a key corresponding to the name of the column header ("name","description","price"...).
$cell["name of the column"] or $cell[INDEX]
For example:
return $cell["description"]. " ".$cell["name"]
Variable $self
$self
to retrieve the current value of the column and manipulate the data:
<?php return $self;
For example:
<?php return strtolower($self);
Examples of use
Below are some examples of use with the PHP API.
Change the separator
Transform a number with a floating value separated with a dot instead of a comma.
For example:
<?php return number_format(str_replace(",",".",$self),2,".",""); ?>
Change a text to lowercase or capital letters
Change a text in lowercase and add a capital letter as the first letter of each word.
For example:
<?php return ucwords(strtolower($self)); ?>
Retrieve images
Retrieve only one image from a list of images.
For example:
<?php return array_pop(explode(",",$self)); ?>
Group several columns
Put together several columns to create a description.
For example:
<?php return $self." ".$cell["product_name"].", starting at $".$cell["price"]; ?>
Define the visibility of a product
Define the visibility of a product depending on the type column.
For example:
<?php
switch($self){
case "parent":
return "Catalog, Search";
break;
default:
return "Not visible individually";
}
?>
Map value to other ones
Map values to other ones.
For example:
<?php
if($self=="something"){
return "something else";
}
else if($self=="foo"){
return "bar";
}
else{
return "default value";
}
?>