Automattic\WooCommerce\Internal\ProductAttributesLookup
LookupDataStore::get_update_action
Determine the type of action to perform depending on the received changeset.
Method of the class: LookupDataStore{}
No Hooks.
Returns
Int. One of the ACTION_ constants.
Usage
// private - for code of main (parent) class only $result = $this->get_update_action( $changeset );
- $changeset(array|null) (required)
- The changeset received by on_product_changed.
LookupDataStore::get_update_action() LookupDataStore::get update action code WC 10.8.1
private function get_update_action( $changeset ) {
if ( is_null( $changeset ) ) {
// No changeset at all means that the product is new.
return self::ACTION_INSERT;
}
$keys = array_keys( $changeset );
// Order matters:
// - The change with the most precedence is a change in catalog visibility
// (which will result in all data being regenerated or deleted).
// - Then a change in attributes (all data will be regenerated).
// - And finally a change in stock status (existing data will be updated).
// Thus these conditions must be checked in that same order.
if ( in_array( 'catalog_visibility', $keys, true ) ) {
$new_visibility = $changeset['catalog_visibility'];
if ( CatalogVisibility::VISIBLE === $new_visibility || CatalogVisibility::CATALOG === $new_visibility ) {
return self::ACTION_INSERT;
} else {
return self::ACTION_DELETE;
}
}
if ( in_array( 'attributes', $keys, true ) ) {
return self::ACTION_INSERT;
}
if ( array_intersect( $keys, array( 'stock_quantity', 'stock_status', 'manage_stock' ) ) ) {
return self::ACTION_UPDATE_STOCK;
}
return self::ACTION_NONE;
}