@@ -415,6 +415,51 @@ public function includeFallback()
415415 return $ this ->queryObject ;
416416 }
417417
418+ /**
419+ * Scope entry requests to one or more entry variants.
420+ *
421+ * Pass a single variant UID (string) or multiple variant UIDs (array).
422+ * Optionally pass a branch name to scope the request to that branch;
423+ * when omitted, the stack-level branch (if set) is used.
424+ *
425+ * @param string|array $variantUidOrUids - Variant UID or list of variant UIDs
426+ * @param string $branchName - Optional branch name for the request
427+ *
428+ * @example
429+ * use Contentstack\Contentstack;
430+ * $stack = Contentstack::Stack("API_KEY", "DELIVERY_TOKEN", "ENVIRONMENT");
431+ * $result = $stack->ContentType('product')->Entry('ENTRY_UID')->variants('VARIANT_UID', 'branch_name')->toJSON()->fetch();
432+ * $entries = $stack->ContentType('product')->Entry()->variants(array('variant1', 'variant2'), 'branch_name')->toJSON()->find();
433+ *
434+ * @return Query|Entry
435+ */
436+ public function variants ($ variantUidOrUids = '' , $ branchName = '' )
437+ {
438+ if (Utility::isEmpty ($ variantUidOrUids )) {
439+ throw contentstackCreateError (ErrorMessages::VARIANT_UIDS_REQUIRED );
440+ }
441+ if (is_array ($ variantUidOrUids )) {
442+ if (count ($ variantUidOrUids ) === 0 ) {
443+ throw contentstackCreateError (ErrorMessages::VARIANT_UIDS_REQUIRED );
444+ }
445+ foreach ($ variantUidOrUids as $ variantUid ) {
446+ if (Utility::isEmpty ($ variantUid ) || !is_string ($ variantUid )) {
447+ throw contentstackCreateError (ErrorMessages::INVALID_VARIANT_UIDS );
448+ }
449+ }
450+ } elseif (!is_string ($ variantUidOrUids )) {
451+ throw contentstackCreateError (ErrorMessages::INVALID_VARIANT_UIDS );
452+ }
453+ if (!Utility::isEmpty ($ branchName ) && !is_string ($ branchName )) {
454+ throw contentstackCreateError (ErrorMessages::INVALID_VARIANT_UIDS );
455+ }
456+ $ this ->queryObject ->variantUid = $ variantUidOrUids ;
457+ if (!Utility::isEmpty ($ branchName )) {
458+ $ this ->queryObject ->variantBranch = $ branchName ;
459+ }
460+ return $ this ->queryObject ;
461+ }
462+
418463 /**
419464 * To include branch of publish content.
420465 *
0 commit comments