Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, when I dsm $node I can see stock and SKU (model) but only for the main product, there is nothing in the Attributes->Options. Is there any way to print the attribute option stock level and SKU?
Attributes don't have SKUs. Products have SKUs, and the SKU depends on the *combination* of attributes that the the customer has selected. If Size and Color are attributes, then a Large Green T-Shirt would have a SKU, and a Medium Green T-Shirt could have a different SKU, but Color=Green would not have its own SKU.
You can take a look at uc_attribute_uc_product_alter() to see how internally we decide what SKU to associate with a particular ordered product with a particular set of attributes and options chosen. Or if you are looking at an already-placed order, the correct SKU for the ordered product is stored in the uc_order_products table.
Given a SKU, the stock level may be obtained via uc_stock_level($sku).
Comments
Comment #1
TR CreditAttribution: TR commentedYou generally need to do a node_load() to get all the data attached to a node (product, in this case).
Comment #2
kevin_91 CreditAttribution: kevin_91 commentedHey, thanks for the tip, but still couldn't get the SKU or stock level.
This is what I get in the devel:
Comment #3
TR CreditAttribution: TR commentedAttributes don't have SKUs. Products have SKUs, and the SKU depends on the *combination* of attributes that the the customer has selected. If Size and Color are attributes, then a Large Green T-Shirt would have a SKU, and a Medium Green T-Shirt could have a different SKU, but Color=Green would not have its own SKU.
You can take a look at uc_attribute_uc_product_alter() to see how internally we decide what SKU to associate with a particular ordered product with a particular set of attributes and options chosen. Or if you are looking at an already-placed order, the correct SKU for the ordered product is stored in the uc_order_products table.
Given a SKU, the stock level may be obtained via uc_stock_level($sku).