�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`�
Warning: session_start(): Session cannot be started after headers have already been sent in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 124

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 131

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 132

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 133

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 134

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 135
0x0x
PHP 8.2.31
Preview: WebflowFetcher.php Size: 11.68 KB
/home/mciraet/www/wp-content/plugins/woocommerce/src/Internal/CLI/Migrator/Platforms/Webflow/WebflowFetcher.php
<?php
/**
 * Webflow Fetcher
 *
 * @package Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow
 */

declare( strict_types=1 );

namespace Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow;

use Automattic\WooCommerce\Internal\CLI\Migrator\Interfaces\PlatformFetcherInterface;

defined( 'ABSPATH' ) || exit;

/**
 * Fetches products (and ecommerce category metadata) from the Webflow v2 API.
 *
 * The Webflow API exposes offset/limit pagination rather than cursors, but the
 * migrator's PlatformFetcherInterface speaks cursors. We use the next offset as
 * a stringified cursor and translate it back to an `offset` query parameter.
 *
 * Webflow does not expose a `/products/categories` endpoint. Categories live in
 * an auto-provisioned CMS collection (slug `category`). We resolve them once
 * via `/sites/{id}/collections` + `/collections/{id}/items` and stash a map of
 * `cms_item_id => { name, slug }` and decorates each fetched product item with a
 * `_resolved_categories` property so the mapper can read categories inline.
 *
 * @internal This class is part of the CLI Migrator feature and should not be used directly.
 */
class WebflowFetcher implements PlatformFetcherInterface {

	/**
	 * Maximum page size allowed by Webflow.
	 *
	 * @var int
	 */
	private const MAX_PAGE_SIZE = 100;

	/**
	 * The Webflow client instance.
	 *
	 * @var WebflowClient
	 */
	private WebflowClient $webflow_client;

	/**
	 * Cached category map: cms_item_id => array{name:string, slug:string}.
	 *
	 * Null until resolved; empty array if the site has no categories collection.
	 *
	 * @var array<string,array{name:string,slug:string}>|null
	 */
	private ?array $category_cache = null;

	/**
	 * Constructor.
	 *
	 * @param array $credentials Platform credentials array.
	 */
	public function __construct( array $credentials ) {
		$this->webflow_client = new WebflowClient( $credentials );
	}

	/**
	 * Fetches a batch of products from the Webflow REST API.
	 *
	 * @param array $args Arguments for fetching. Supported keys:
	 *                    - 'limit': Max number of items per batch (default: 50, capped at 100).
	 *                    - 'after_cursor': Stringified next-offset for pagination (optional).
	 *
	 * @return array{items: array, cursor: ?string, has_next_page: bool}
	 */
	public function fetch_batch( array $args ): array {
		$site_id = $this->webflow_client->get_site_id();
		if ( is_wp_error( $site_id ) ) {
			// @phpstan-ignore-next-line class.notFound
			\WP_CLI::warning( 'Failed to fetch Webflow products: ' . $site_id->get_error_message() );
			return $this->empty_batch();
		}

		$limit  = (int) ( $args['limit'] ?? 50 );
		$limit  = max( 1, min( $limit, self::MAX_PAGE_SIZE ) );
		$offset = 0;
		if ( isset( $args['after_cursor'] ) && is_numeric( $args['after_cursor'] ) ) {
			$offset = max( 0, (int) $args['after_cursor'] );
		}

		$query = array(
			'limit'  => $limit,
			'offset' => $offset,
		);

		$response = $this->webflow_client->rest_request( "/sites/{$site_id}/products", $query );

		if ( is_wp_error( $response ) ) {
			// @phpstan-ignore-next-line class.notFound
			\WP_CLI::warning( 'Failed to fetch products from Webflow: ' . $response->get_error_message() );
			return $this->empty_batch();
		}

		if ( ! is_object( $response ) || ! isset( $response->items ) || ! is_array( $response->items ) ) {
			// @phpstan-ignore-next-line class.notFound
			\WP_CLI::warning( 'Invalid Webflow response: missing items array.' );
			return $this->empty_batch();
		}

		$items    = $response->items;
		$count    = count( $items );
		$total    = isset( $response->pagination->total ) ? (int) $response->pagination->total : ( $offset + $count );
		$next     = $offset + $count;
		$has_next = $count > 0 && $next < $total;

		$this->ensure_category_cache_loaded( $site_id );
		$this->decorate_items_with_categories( $items );

		// The cursor is simply the next offset. Unlike Shopify's stable cursors, offset paging can
		// skip or double-import items if the Webflow catalog changes (a product added or removed)
		// between batches. Acceptable here given Webflow's API offers no stable cursor.
		return array(
			'items'         => $items,
			'cursor'        => $has_next ? (string) $next : null,
			'has_next_page' => $has_next,
		);
	}

	/**
	 * Fetches the total count of products from Webflow.
	 *
	 * @param array $args Filter arguments (unused; Webflow's products endpoint does not accept filters).
	 * @return int Total product count, or 0 on failure.
	 */
	public function fetch_total_count( array $args ): int {
		unset( $args );
		// Webflow does not support filtered count queries here.

		$site_id = $this->webflow_client->get_site_id();
		if ( is_wp_error( $site_id ) ) {
			// @phpstan-ignore-next-line class.notFound
			\WP_CLI::warning( 'Could not fetch Webflow product count: ' . $site_id->get_error_message() );
			return 0;
		}

		$response = $this->webflow_client->rest_request(
			"/sites/{$site_id}/products",
			array(
				'limit'  => 1,
				'offset' => 0,
			)
		);

		if ( is_wp_error( $response ) ) {
			// @phpstan-ignore-next-line class.notFound
			\WP_CLI::warning( 'Could not fetch Webflow product count: ' . $response->get_error_message() );
			return 0;
		}

		if ( ! is_object( $response ) || ! isset( $response->pagination->total ) ) {
			// @phpstan-ignore-next-line class.notFound
			\WP_CLI::warning( 'Unexpected response from Webflow products endpoint - missing pagination.total.' );
			return 0;
		}

		return (int) $response->pagination->total;
	}

	/**
	 * Decorate each product item with a `_resolved_categories` property whose value is an
	 * array of `{name, slug}` for every recognized CMS item id in `product.fieldData.category`.
	 *
	 * This is how the mapper learns about category names without needing access to the
	 * fetcher or making its own API calls. Missing/archived ids are silently dropped.
	 *
	 * @param array<int,object> $items Items array (mutated in place).
	 * @return void
	 */
	private function decorate_items_with_categories( array &$items ): void {
		if ( null === $this->category_cache || empty( $this->category_cache ) ) {
			foreach ( $items as $item ) {
				if ( is_object( $item ) ) {
					// @phpstan-ignore-next-line property.notFound
					$item->_resolved_categories = array();
				}
			}
			return;
		}

		foreach ( $items as $item ) {
			if ( ! is_object( $item ) ) {
				continue;
			}

			$category_ids = array();
			if ( isset( $item->product->fieldData->category ) && is_array( $item->product->fieldData->category ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Webflow API uses camelCase.
				$category_ids = $item->product->fieldData->category; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Webflow API uses camelCase.
			}

			$resolved = array();
			foreach ( $category_ids as $cms_item_id ) {
				$cms_item_id = (string) $cms_item_id;
				if ( isset( $this->category_cache[ $cms_item_id ] ) ) {
					$resolved[] = $this->category_cache[ $cms_item_id ];
				}
			}

			// @phpstan-ignore-next-line property.notFound
			$item->_resolved_categories = $resolved;
		}
	}

	/**
	 * Ensures the category cache has been resolved at most once per fetcher instance.
	 *
	 * @param string $site_id Webflow site ID.
	 * @return void
	 */
	private function ensure_category_cache_loaded( string $site_id ): void {
		if ( null !== $this->category_cache ) {
			return;
		}

		$this->category_cache = array();

		$collections_response = $this->webflow_client->rest_request( "/sites/{$site_id}/collections" );
		if ( is_wp_error( $collections_response ) ) {
			// @phpstan-ignore-next-line class.notFound
			\WP_CLI::debug( 'Could not load Webflow collections list (categories will not be resolved): ' . $collections_response->get_error_message() );
			return;
		}

		$collections = $this->extract_collections_list( $collections_response );
		$category_id = $this->find_category_collection_id( $collections );

		if ( null === $category_id ) {
			// @phpstan-ignore-next-line class.notFound
			\WP_CLI::debug( 'No "category" collection found on Webflow site; product categories will be skipped.' );
			return;
		}

		$this->category_cache = $this->load_collection_items_map( $category_id );
	}

	/**
	 * Webflow's /collections endpoint sometimes returns a bare array and sometimes an envelope.
	 * Normalize to a flat list of collection objects.
	 *
	 * @param mixed $response The raw decoded API response.
	 * @return array<int,object>
	 */
	private function extract_collections_list( $response ): array {
		if ( is_array( $response ) ) {
			return $response;
		}

		if ( is_object( $response ) && isset( $response->collections ) && is_array( $response->collections ) ) {
			return $response->collections;
		}

		return array();
	}

	/**
	 * Find the auto-provisioned Ecommerce Categories collection.
	 *
	 * @param array<int,object> $collections List of collection objects.
	 * @return string|null Collection ID or null if not found.
	 */
	private function find_category_collection_id( array $collections ): ?string {
		foreach ( $collections as $collection ) {
			if ( ! is_object( $collection ) || empty( $collection->id ) ) {
				continue;
			}
			$slug         = isset( $collection->slug ) ? (string) $collection->slug : '';
			$display_name = isset( $collection->displayName ) ? (string) $collection->displayName : ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Webflow API uses camelCase.

			if ( 'category' === $slug || 'Categories' === $display_name ) {
				return (string) $collection->id;
			}
		}

		return null;
	}

	/**
	 * Page through a CMS collection and build an id => {name, slug} map.
	 *
	 * @param string $collection_id The Webflow CMS collection ID.
	 * @return array<string,array{name:string,slug:string}>
	 */
	private function load_collection_items_map( string $collection_id ): array {
		$map       = array();
		$offset    = 0;
		$page_size = self::MAX_PAGE_SIZE;
		$max_pages = 100;
		// Safety net to avoid runaway loops on broken pagination.
		$page_index = 0;

		while ( $page_index < $max_pages ) {
			$response = $this->webflow_client->rest_request(
				"/collections/{$collection_id}/items",
				array(
					'limit'  => $page_size,
					'offset' => $offset,
				)
			);

			if ( is_wp_error( $response ) ) {
				// @phpstan-ignore-next-line class.notFound
				\WP_CLI::debug( 'Could not load Webflow category items: ' . $response->get_error_message() );
				break;
			}

			$items = ( is_object( $response ) && isset( $response->items ) && is_array( $response->items ) ) ? $response->items : array();
			if ( empty( $items ) ) {
				break;
			}

			foreach ( $items as $item ) {
				if ( ! is_object( $item ) || empty( $item->id ) ) {
					continue;
				}
				$field_data = isset( $item->fieldData ) && is_object( $item->fieldData ) ? $item->fieldData : null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Webflow API uses camelCase.
				if ( null === $field_data ) {
					continue;
				}

				$name = isset( $field_data->name ) ? (string) $field_data->name : '';
				$slug = isset( $field_data->slug ) ? (string) $field_data->slug : sanitize_title( $name );

				if ( '' === $name ) {
					continue;
				}

				$map[ (string) $item->id ] = array(
					'name' => $name,
					'slug' => $slug,
				);
			}

			$total   = isset( $response->pagination->total ) ? (int) $response->pagination->total : ( $offset + count( $items ) );
			$offset += count( $items );
			if ( $offset >= $total ) {
				break;
			}

			++$page_index;
		}

		return $map;
	}

	/**
	 * Empty-batch response helper.
	 *
	 * @return array{items: array, cursor: null, has_next_page: false}
	 */
	private function empty_batch(): array {
		return array(
			'items'         => array(),
			'cursor'        => null,
			'has_next_page' => false,
		);
	}
}

Directory Contents

Dirs: 0 × Files: 4
Name Size Perms Modified Actions
4.79 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
11.68 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
27.19 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
1.39 KB lrw-r--r-- 2026-08-11 10:05:48
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI