Automattic\WooCommerce\Internal\ProductAttributesLookup

LookupDataStore::get_update_action │ private │ WC 1.0

Determine the type of action to perform depending on the received changeset.

Метод класса: LookupDataStore{}

Хуков нет.

Возвращает

int. One of the ACTION_ constants.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_update_action( $changeset, $is_variation );
$changeset(массив|null) (обязательный)
The changeset received by on_product_changed.
$is_variation(true|false) (обязательный)
True if the changed product is a variation.

Код LookupDataStore::get_update_action() WC 11.3.0

private function get_update_action( $changeset, bool $is_variation ) {
	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 status change of a variation (data regenerated: unpublished variations get no rows).
	// - 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;
		}
	}

	// The "Enabled" checkbox of a variation toggles its status between 'publish' and 'private'.
	// A product's own status isn't stored in the table, so it doesn't trigger anything.
	if ( $is_variation && in_array( 'status', $keys, true ) ) {
		return self::ACTION_INSERT;
	}

	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;
}