The product
module
- class magento.models.product.Product(data, client)[source]View on GitHub
Bases:
Model
Wrapper for the
products
endpoint- STATUS_ENABLED = 1
- STATUS_DISABLED = 2
- VISIBILITY_NOT_VISIBLE = 1
- VISIBILITY_CATALOG = 2
- VISIBILITY_SEARCH = 3
- VISIBILITY_BOTH = 4
- DOCUMENTATION: str = 'https://adobe-commerce.redoc.ly/2.3.7-admin/tag/products/'
Link to the Official Magento 2 API documentation for the endpoint wrapped by the Model
- __init__(data, client)[source]View on GitHub
Initialize a Product object using an API response from the
products
endpoint
- property excluded_keys
API response keys that shouldn’t be set as object attributes by
set_attrs()
- Returns
list of API response keys that shouldn’t be set as attributes
- update_stock(qty)[source]View on GitHub
Updates the stock quantity
- update_status(status)[source]View on GitHub
Update the product status
- Parameters
status (int) – either 1 (for
STATUS_ENABLED
) or 2 (forSTATUS_DISABLED
)- Return type
- update_price(price)[source]View on GitHub
Update the product price
- update_special_price(price)[source]View on GitHub
Update the product special price
- update_name(name, scope=None)[source]View on GitHub
Update the product name
- Parameters
name (str) – the new name to use
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- update_description(description, scope=None)[source]View on GitHub
Update the product description
- Parameters
description (str) – the new HTML description to use
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- update_metadata(metadata, scope=None)[source]View on GitHub
Update the product metadata
- Parameters
metadata (dict) – the new
meta_title
,meta_keyword
and/ormeta_description
to usescope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- add_categories(category_ids)[source]View on GitHub
Adds the product to an individual or multiple categories
- remove_categories(category_ids)[source]View on GitHub
Removes the product from an individual or multiple categories
- update_attributes(attribute_data, scope=None)[source]View on GitHub
Update top level product attributes with scoping taken into account
Note
Product attributes can have a
Global
,Store View
orWebsite
scope- Global Attributes
Values are updated on all store views and the admin
- Website Attributes
Values are updated on all store views
- Store View Attributes
Values are updated on the store view specified in the request
scope
A second request will be made to update
Store View
andWebsite
attributes on the admin, depending on how manyStore
views
you have:1 View: admin values are updated for all attributes, regardless of scope
2+ Views: admin values are updated only for
website_product_attributes
- Parameters
attribute_data (dict) – a dictionary of product attributes to update
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- update_custom_attributes(attribute_data, scope=None)[source]View on GitHub
Update custom attributes with scoping taken into account
See
update_attributes()
for detailsImportant
This method only supports updating custom attributes
- Parameters
attribute_data (dict) – a dictionary of custom attributes to update
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- get_orders()[source]View on GitHub
Searches for orders that contain the product
If the product is configurable, returns orders containing any of its child products
- get_order_items()[source]View on GitHub
Searches for order items that contain the product
If the product is configurable, returns order items containing any of its child products
- get_invoices()[source]View on GitHub
Searches for invoices that contain the product
If the product is configurable, returns invoices containing any of its child products
- delete()[source]View on GitHub
Deletes the product
Hint
If you delete a product by accident, the
Product
object’sdata
attribute will still contain the raw data, which can be used to recover it.Alternatively, don’t delete it by accident.
- Return type
- get_children(refresh=False, scope=None)[source]View on GitHub
Retrieve the child simple products of a configurable product
- property children: List[Product]
If the Product is a configurable product, returns a list of its child products
- property categories: Optional[Category | List[Category]]
Categories the product is in, returned as a list of
Category
objects
- property media_gallery_entries: List[MediaEntry]
The product’s media gallery entries, returned as a list of
MediaEntry
objects
- property thumbnail: MediaEntry
The
MediaEntry
corresponding to the product’s thumbnail
- get_media_by_id(entry_id)[source]View on GitHub
Access a
MediaEntry
of the product by id- Parameters
entry_id (int) – the id of the media gallery entry
- Return type
- property option_skus: List[str]
The full SKUs for the product’s customizable options, if they exist
- property stock_item_id: int
Item id of the StockItem, used to
update_stock()
- class magento.models.product.MediaEntry(product, entry)[source]View on GitHub
Bases:
Model
Wraps a media gallery entry of a
Product
- MEDIA_TYPES = ['base', 'small', 'thumbnail', 'swatch']
- DOCUMENTATION: str = 'https://adobe-commerce.redoc.ly/2.3.7-admin/tag/productsskumediaentryId'
Link to the Official Magento 2 API documentation for the endpoint wrapped by the Model
- __init__(product, entry)[source]View on GitHub
Initialize a MediaEntry object for a
Product
- query_endpoint()[source]View on GitHub
No search endpoint exists for media gallery entries
- property excluded_keys: List[str]
API response keys that shouldn’t be set as object attributes by
set_attrs()
- Returns
list of API response keys that shouldn’t be set as attributes
- property is_enabled
- property is_thumbnail
- property link
Permalink to the image
- disable(scope=None)[source]View on GitHub
Disables the MediaEntry on the given scope
- Parameters
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided- Return type
- enable(scope=None)[source]View on GitHub
Enables the MediaEntry on the given scope
- Parameters
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided- Return type
- add_media_type(media_type, scope=None)[source]View on GitHub
Add a media type to the MediaEntry on the given scope
Caution
If the media type is already assigned to a different entry, it will be removed
- Parameters
media_type (str) – one of the
MEDIA_TYPES
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- remove_media_type(media_type, scope=None)[source]View on GitHub
Remove a media type from the MediaEntry on the given scope
- Parameters
media_type (str) – one of the
MEDIA_TYPES
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- set_media_types(types, scope=None)[source]View on GitHub
Set media types for the MediaEntry on the given scope
- Parameters
types (list) – a list containing all
MEDIA_TYPES
to assignscope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- set_position(position, scope=None)[source]View on GitHub
Set the position of the MediaEntry on the given scope
- Parameters
position (int) – the position to change to
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- set_alt_text(text, scope=None)[source]View on GitHub
Set the alt text (
label
) of the MediaEntry on the given scope- Parameters
text (str) – the alt text to use
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided
- Return type
- update(scope=None)[source]View on GitHub
Uses the
data
dict to update the media entryNote
Some updates alter the data of other entries; if the update is successful, the associated
Product
will be refreshed on the same scope to keep the data consistentTip
If there’s only 1 store view, the admin will also be updated
- Parameters
scope (Optional[str]) – the scope to send the request on; will use the
Client.scope
if not provided- Return type
- class magento.models.product.ProductAttribute(data, client)[source]View on GitHub
Bases:
Model
Wrapper for the
products/attributes
endpoint- DOCUMENTATION: str = 'https://adobe-commerce.redoc.ly/2.3.7-admin/tag/productsattributes/'
Link to the Official Magento 2 API documentation for the endpoint wrapped by the Model
- __init__(data, client)[source]View on GitHub
Initialize a ProductAttribute object using an API response from the
products/attributes
endpoint
- property excluded_keys: List[str]
API response keys that shouldn’t be set as object attributes by
set_attrs()
- Returns
list of API response keys that shouldn’t be set as attributes
- property options