Documentation
¶
Index ¶
- Constants
- type Attribute
- type AttributeOption
- type AttributeSet
- type CMSBlock
- type CMSPage
- type CartRule
- type CatalogRule
- type Category
- type CategoryProduct
- type Client
- func (c *Client) GetAttribute(ctx context.Context, code string) (*Attribute, error)
- func (c *Client) GetAttributeOptions(ctx context.Context, code string) ([]AttributeOption, error)
- func (c *Client) GetCMSBlock(ctx context.Context, id int) (*CMSBlock, error)
- func (c *Client) GetCMSPage(ctx context.Context, id int) (*CMSPage, error)
- func (c *Client) GetCartRule(ctx context.Context, id int) (*CartRule, error)
- func (c *Client) GetCatalogRule(ctx context.Context, id int) (*CatalogRule, error)
- func (c *Client) GetCategory(ctx context.Context, id int) (*Category, error)
- func (c *Client) GetCategoryProducts(ctx context.Context, categoryID int) ([]CategoryProduct, error)
- func (c *Client) GetCategoryTree(ctx context.Context, rootID int, depth int) (*Category, error)
- func (c *Client) GetConfigEntries(ctx context.Context, storeCode string) ([]ConfigEntry, error)
- func (c *Client) GetConfigurableChildren(ctx context.Context, sku string) ([]Product, error)
- func (c *Client) GetConfigurableOptions(ctx context.Context, sku string) ([]ConfigurableOption, error)
- func (c *Client) GetCoupon(ctx context.Context, id int) (*Coupon, error)
- func (c *Client) GetProduct(ctx context.Context, sku string) (*Product, error)
- func (c *Client) GetProductMedia(ctx context.Context, sku string) ([]MediaEntry, error)
- func (c *Client) GetStockStatus(ctx context.Context, sku string) (*StockItem, error)
- func (c *Client) GetStoreConfigRaw(ctx context.Context) ([]map[string]any, error)
- func (c *Client) HTTP() *httpx.Client
- func (c *Client) ListAttributeSets(ctx context.Context, search *SearchCriteria) (*SearchResult[AttributeSet], error)
- func (c *Client) ListCMSBlocks(ctx context.Context, search *SearchCriteria) (*SearchResult[CMSBlock], error)
- func (c *Client) ListCMSPages(ctx context.Context, search *SearchCriteria) (*SearchResult[CMSPage], error)
- func (c *Client) ListCartRules(ctx context.Context, search *SearchCriteria) (*SearchResult[CartRule], error)
- func (c *Client) ListCatalogRules(ctx context.Context, search *SearchCriteria) (*SearchResult[CatalogRule], error)
- func (c *Client) ListCoupons(ctx context.Context, search *SearchCriteria) (*SearchResult[Coupon], error)
- func (c *Client) ListProducts(ctx context.Context, search *SearchCriteria) (*SearchResult[Product], error)
- func (c *Client) ListStoreConfigs(ctx context.Context) ([]StoreConfig, error)
- func (c *Client) ListStoreGroups(ctx context.Context) ([]StoreGroup, error)
- func (c *Client) ListStoreViews(ctx context.Context) ([]StoreView, error)
- func (c *Client) ListWebsites(ctx context.Context) ([]Website, error)
- type ClientOptions
- type ConfigEntry
- type ConfigurableOption
- type ConfigurableValue
- type Coupon
- type CustomAttribute
- type InventorySourceItem
- type MediaEntry
- type OptionValue
- type Product
- type ProductLink
- type ProductOption
- type SearchCriteria
- type SearchResult
- type StockItem
- type StoreConfig
- type StoreGroup
- type StoreLabel
- type StoreView
- type TierPrice
- type Website
Constants ¶
const MaxPageSize = 10000
MaxPageSize is the upper bound for results per page to prevent accidental resource exhaustion on large catalogs.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
type Attribute struct {
AttributeID int `json:"attribute_id"`
AttributeCode string `json:"attribute_code"`
FrontendInput string `json:"frontend_input"`
FrontendLabel string `json:"default_frontend_label"`
IsRequired bool `json:"is_required"`
IsUserDefined bool `json:"is_user_defined"`
Options []AttributeOption `json:"options,omitempty"`
EntityTypeID string `json:"entity_type_id"`
}
Attribute represents a Magento 2 EAV attribute.
type AttributeOption ¶
type AttributeSet ¶
type AttributeSet struct {
AttributeSetID int `json:"attribute_set_id"`
AttributeSetName string `json:"attribute_set_name"`
SortOrder int `json:"sort_order"`
EntityTypeID int `json:"entity_type_id"`
}
AttributeSet represents a Magento 2 attribute set.
type CMSBlock ¶
type CMSBlock struct {
ID int `json:"id"`
Identifier string `json:"identifier"`
Title string `json:"title"`
Content string `json:"content"`
Active bool `json:"active"`
CreationTime string `json:"creation_time"`
UpdateTime string `json:"update_time"`
}
CMSBlock represents a Magento 2 CMS static block.
type CMSPage ¶
type CMSPage struct {
ID int `json:"id"`
Identifier string `json:"identifier"`
Title string `json:"title"`
Content string `json:"content"`
ContentHeading string `json:"content_heading"`
Active bool `json:"active"`
SortOrder string `json:"sort_order"`
PageLayout string `json:"page_layout"`
MetaTitle string `json:"meta_title"`
MetaKeywords string `json:"meta_keywords"`
MetaDescription string `json:"meta_description"`
CreationTime string `json:"creation_time"`
UpdateTime string `json:"update_time"`
}
CMSPage represents a Magento 2 CMS page.
type CartRule ¶
type CartRule struct {
RuleID int `json:"rule_id"`
Name string `json:"name"`
Description string `json:"description"`
IsActive bool `json:"is_active"`
StopRulesProcessing bool `json:"stop_rules_processing"`
SortOrder int `json:"sort_order"`
SimpleAction string `json:"simple_action"`
DiscountAmount float64 `json:"discount_amount"`
DiscountQty float64 `json:"discount_qty"`
DiscountStep int `json:"discount_step"`
ApplyToShipping bool `json:"apply_to_shipping"`
TimesUsed int `json:"times_used"`
IsRSS bool `json:"is_rss"`
CouponType string `json:"coupon_type"`
UseAutoGeneration bool `json:"use_auto_generation"`
UsesPerCoupon int `json:"uses_per_coupon"`
UsesPerCustomer int `json:"uses_per_customer"`
FromDate string `json:"from_date"`
ToDate string `json:"to_date"`
CustomerGroupIDs []int `json:"customer_group_ids"`
WebsiteIDs []int `json:"website_ids"`
StoreLabels []StoreLabel `json:"store_labels,omitempty"`
ExtensionAttrs map[string]any `json:"extension_attributes,omitempty"`
}
CartRule represents a Magento 2 cart price rule (sales rule).
type CatalogRule ¶
type CatalogRule struct {
RuleID int `json:"rule_id"`
Name string `json:"name"`
Description string `json:"description"`
IsActive bool `json:"is_active"`
StopRulesProcessing bool `json:"stop_rules_processing"`
SortOrder int `json:"sort_order"`
SimpleAction string `json:"simple_action"`
DiscountAmount float64 `json:"discount_amount"`
FromDate string `json:"from_date"`
ToDate string `json:"to_date"`
CustomerGroupIDs []int `json:"customer_group_ids"`
WebsiteIDs []int `json:"website_ids"`
ExtensionAttrs map[string]any `json:"extension_attributes,omitempty"`
}
CatalogRule represents a Magento 2 catalog price rule.
type Category ¶
type Category struct {
ID int `json:"id"`
ParentID int `json:"parent_id"`
Name string `json:"name"`
IsActive bool `json:"is_active"`
Position int `json:"position"`
Level int `json:"level"`
ProductCount int `json:"product_count"`
ChildrenData []Category `json:"children_data,omitempty"`
CustomAttributes []CustomAttribute `json:"custom_attributes,omitempty"`
}
Category represents a Magento 2 category.
type CategoryProduct ¶
type CategoryProduct struct {
SKU string `json:"sku"`
Position int `json:"position"`
CategoryID string `json:"category_id"`
}
CategoryProduct represents a product assignment within a category.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides access to the Magento 2 REST API.
func (*Client) GetAttribute ¶
GetAttribute retrieves a product attribute by code.
func (*Client) GetAttributeOptions ¶
GetAttributeOptions retrieves the option values for an attribute.
func (*Client) GetCMSBlock ¶
GetCMSBlock retrieves a single CMS block by ID.
func (*Client) GetCMSPage ¶
GetCMSPage retrieves a single CMS page by ID.
func (*Client) GetCartRule ¶
GetCartRule retrieves a single cart price rule by ID.
func (*Client) GetCatalogRule ¶
GetCatalogRule retrieves a single catalog price rule by ID.
func (*Client) GetCategory ¶
GetCategory retrieves a single category by ID.
func (*Client) GetCategoryProducts ¶
func (c *Client) GetCategoryProducts(ctx context.Context, categoryID int) ([]CategoryProduct, error)
GetCategoryProducts retrieves products assigned to a category.
func (*Client) GetCategoryTree ¶
GetCategoryTree retrieves the full category tree from a root ID.
func (*Client) GetConfigEntries ¶
GetConfigEntries retrieves store configuration and returns it as a flat list of ConfigEntry values with Magento config paths. If storeCode is non-empty, results are filtered to that store.
func (*Client) GetConfigurableChildren ¶
GetConfigurableChildren returns the simple product variants of a configurable product.
func (*Client) GetConfigurableOptions ¶
func (c *Client) GetConfigurableOptions(ctx context.Context, sku string) ([]ConfigurableOption, error)
GetConfigurableOptions returns the configurable options for a product.
func (*Client) GetProduct ¶
GetProduct retrieves a single product by SKU.
func (*Client) GetProductMedia ¶
GetProductMedia retrieves media gallery entries for a product.
func (*Client) GetStockStatus ¶
GetStockStatus retrieves the stock/inventory status for a product SKU.
func (*Client) GetStoreConfigRaw ¶
GetStoreConfigRaw retrieves store configuration as raw maps to capture all fields returned by the API, including any not mapped in our struct.
func (*Client) ListAttributeSets ¶
func (c *Client) ListAttributeSets(ctx context.Context, search *SearchCriteria) (*SearchResult[AttributeSet], error)
ListAttributeSets retrieves attribute sets matching the search criteria.
func (*Client) ListCMSBlocks ¶
func (c *Client) ListCMSBlocks(ctx context.Context, search *SearchCriteria) (*SearchResult[CMSBlock], error)
ListCMSBlocks retrieves CMS blocks matching search criteria.
func (*Client) ListCMSPages ¶
func (c *Client) ListCMSPages(ctx context.Context, search *SearchCriteria) (*SearchResult[CMSPage], error)
ListCMSPages retrieves CMS pages matching search criteria.
func (*Client) ListCartRules ¶
func (c *Client) ListCartRules(ctx context.Context, search *SearchCriteria) (*SearchResult[CartRule], error)
ListCartRules retrieves cart price rules (sales rules) matching search criteria.
func (*Client) ListCatalogRules ¶
func (c *Client) ListCatalogRules(ctx context.Context, search *SearchCriteria) (*SearchResult[CatalogRule], error)
ListCatalogRules retrieves catalog price rules matching search criteria.
func (*Client) ListCoupons ¶
func (c *Client) ListCoupons(ctx context.Context, search *SearchCriteria) (*SearchResult[Coupon], error)
ListCoupons retrieves coupons matching search criteria.
func (*Client) ListProducts ¶
func (c *Client) ListProducts(ctx context.Context, search *SearchCriteria) (*SearchResult[Product], error)
ListProducts retrieves products matching the search criteria.
func (*Client) ListStoreConfigs ¶
func (c *Client) ListStoreConfigs(ctx context.Context) ([]StoreConfig, error)
ListStoreConfigs retrieves store configuration for all store views.
func (*Client) ListStoreGroups ¶
func (c *Client) ListStoreGroups(ctx context.Context) ([]StoreGroup, error)
ListStoreGroups retrieves all store groups.
func (*Client) ListStoreViews ¶
ListStoreViews retrieves all store views.
type ClientOptions ¶
type ClientOptions struct {
BaseURL string
Token string
StoreCode string
EnableCache bool
Retry httpx.RetryPolicy
Debug bool
}
ClientOptions configures a Magento client.
type ConfigEntry ¶
type ConfigEntry struct {
Path string `json:"path"`
Value string `json:"value"`
Scope string `json:"scope"`
}
ConfigEntry represents a single configuration path and its value.
func FilterConfigEntries ¶
func FilterConfigEntries(entries []ConfigEntry, filter string) []ConfigEntry
FilterConfigEntries returns entries whose path starts with prefix or contains the search term (case-insensitive).
type ConfigurableOption ¶
type ConfigurableOption struct {
ID int `json:"id"`
AttributeID string `json:"attribute_id"`
Label string `json:"label"`
Position int `json:"position"`
Values []ConfigurableValue `json:"values"`
ProductID int `json:"product_id"`
}
ConfigurableOption represents a configurable product attribute option.
type ConfigurableValue ¶
type ConfigurableValue struct {
ValueIndex int `json:"value_index"`
}
type Coupon ¶
type Coupon struct {
CouponID int `json:"coupon_id"`
RuleID int `json:"rule_id"`
Code string `json:"code"`
UsageLimit int `json:"usage_limit"`
UsagePerCustomer int `json:"usage_per_customer"`
TimesUsed int `json:"times_used"`
IsPrimary bool `json:"is_primary"`
Type int `json:"type"`
CreatedAt string `json:"created_at"`
ExpirationDate string `json:"expiration_date"`
}
Coupon represents a Magento 2 coupon.
type CustomAttribute ¶
type InventorySourceItem ¶
type InventorySourceItem struct {
SKU string `json:"sku"`
SourceCode string `json:"source_code"`
Quantity float64 `json:"quantity"`
Status int `json:"status"`
}
InventorySourceItem represents MSI (Multi-Source Inventory) source items.
type MediaEntry ¶
type OptionValue ¶
type Product ¶
type Product struct {
ID int `json:"id"`
SKU string `json:"sku"`
Name string `json:"name"`
Price float64 `json:"price"`
Status int `json:"status"`
Visibility int `json:"visibility"`
TypeID string `json:"type_id"`
Weight float64 `json:"weight"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
AttributeSetID int `json:"attribute_set_id"`
CustomAttributes []CustomAttribute `json:"custom_attributes,omitempty"`
ExtensionAttrs map[string]any `json:"extension_attributes,omitempty"`
MediaGallery []MediaEntry `json:"media_gallery_entries,omitempty"`
ProductLinks []ProductLink `json:"product_links,omitempty"`
Options []ProductOption `json:"options,omitempty"`
TierPrices []TierPrice `json:"tier_prices,omitempty"`
}
Product represents a Magento 2 catalog product.
type ProductLink ¶
type ProductOption ¶
type SearchCriteria ¶
type SearchCriteria struct {
// contains filtered or unexported fields
}
SearchCriteria builds Magento 2 REST API search query parameters.
func (*SearchCriteria) AddFilter ¶
func (s *SearchCriteria) AddFilter(expr string) error
AddFilter adds a filter to a new filter group (AND with other groups). Format: "field operator value" e.g. "name like %shirt%", "price gt 50"
func (*SearchCriteria) AddSort ¶
func (s *SearchCriteria) AddSort(expr string) error
AddSort adds a sort order. Format: "field:direction" e.g. "price:ASC"
func (*SearchCriteria) Encode ¶
func (s *SearchCriteria) Encode() string
Encode returns the search criteria as URL query parameters.
func (*SearchCriteria) SetCurrentPage ¶
func (s *SearchCriteria) SetCurrentPage(page int)
SetCurrentPage sets the page number (1-based).
func (*SearchCriteria) SetPageSize ¶
func (s *SearchCriteria) SetPageSize(size int)
SetPageSize sets the number of results per page (capped at MaxPageSize).
type SearchResult ¶
type SearchResult[T any] struct { Items []T `json:"items"` TotalCount int `json:"total_count"` SearchCriteria struct { FilterGroups []struct { Filters []struct { Field string `json:"field"` Value string `json:"value"` ConditionType string `json:"condition_type"` } `json:"filters"` } `json:"filter_groups"` PageSize int `json:"page_size"` CurrentPage int `json:"current_page"` } `json:"search_criteria"` }
SearchResult is the standard Magento 2 paginated response.
type StockItem ¶
type StockItem struct {
ItemID int `json:"item_id"`
ProductID int `json:"product_id"`
StockID int `json:"stock_id"`
Qty float64 `json:"qty"`
IsInStock bool `json:"is_in_stock"`
IsQtyDecimal bool `json:"is_qty_decimal"`
MinQty float64 `json:"min_qty"`
MinSaleQty float64 `json:"min_sale_qty"`
MaxSaleQty float64 `json:"max_sale_qty"`
}
StockItem represents Magento 2 inventory data.
type StoreConfig ¶
type StoreConfig struct {
ID int `json:"id"`
Code string `json:"code"`
WebsiteID int `json:"website_id"`
Locale string `json:"locale"`
BaseCurrencyCode string `json:"base_currency_code"`
DefaultDisplayCurrency string `json:"default_display_currency_code"`
Timezone string `json:"timezone"`
WeightUnit string `json:"weight_unit"`
BaseURL string `json:"base_url"`
BaseLinkURL string `json:"base_link_url"`
BaseStaticURL string `json:"base_static_url"`
BaseMediaURL string `json:"base_media_url"`
SecureBaseURL string `json:"secure_base_url"`
SecureBaseLinkURL string `json:"secure_base_link_url"`
SecureBaseStaticURL string `json:"secure_base_static_url"`
SecureBaseMediaURL string `json:"secure_base_media_url"`
}
StoreConfig represents Magento 2 store configuration.
type StoreGroup ¶
type StoreGroup struct {
ID int `json:"id"`
WebsiteID int `json:"website_id"`
Name string `json:"name"`
RootCategoryID int `json:"root_category_id"`
DefaultStoreID int `json:"default_store_id"`
Code string `json:"code"`
}
StoreGroup represents a Magento 2 store group.
type StoreLabel ¶
StoreLabel represents a label for a specific store view.
type StoreView ¶
type StoreView struct {
ID int `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
WebsiteID int `json:"website_id"`
StoreGroupID int `json:"store_group_id"`
IsActive int `json:"is_active"`
}
StoreView represents a Magento 2 store view.