private void HandleDropdownChange(int option) { // Change the current variant to what has been selected var variants = (List <Shopify.Unity.ProductVariant>)CurrentProduct.variants(); var variant = variants[VariantsDropdown.value]; Debug.Log("sss"); CurrentVariant = variant; string imageSrc; // If the variant has a particular image try { imageSrc = variant.image().transformedSrc(); } catch (NullReferenceException) { var images = (List <Shopify.Unity.Image>)CurrentProduct.images(); imageSrc = images.First().transformedSrc(); } StartCoroutine(ImageHelper.AssignImage(imageSrc, ProductImage)); ProductPrice.text = variant.price().ToString("C"); ProductTitleDescription.text = CurrentProduct.description(); ProductTitleDescNoVariant.text = CurrentProduct.description(); }
private void Start() { IncreaseQuantity.onClick.AddListener(() => OnVariantLineItemQuantityAdjustment.Invoke(_currentVariant, 1)); DecreaseQuantity.onClick.AddListener(() => OnVariantLineItemQuantityAdjustment.Invoke(_currentVariant, -1)); StartCoroutine( ImageHelper.AssignImage( _imageSrc, ProductImage ) ); }
public void Load() { IsLoaded = true; if (!string.IsNullOrEmpty(_imageSrc)) { StartCoroutine( ImageHelper.AssignImage( _imageSrc, imageHat ) ); } }
public void Load() { IsLoaded = true; if (!string.IsNullOrEmpty(_imageSrc)) { StartCoroutine( ImageHelper.AssignImage( _imageSrc, ProductImage, BrokenImageIcon ) ); } }
private void RenderVariantImages(List <Shopify.Unity.Image> images) { // Clean up the existing thumbnail images foreach (var imageHolder in _imageHolders) { Destroy(imageHolder); } _imageHolders.Clear(); // We only have space for a fixed number of thumbnails, so we render out the first five var offset = 0; var maxImages = 5; if (images.Count < maxImages) { maxImages = images.Count; } foreach (var image in images.GetRange(0, maxImages)) { // Generate instance of thumbail template var instance = Instantiate(ImageHolderTemplate); instance.gameObject.SetActive(true); _imageHolders.Add(instance.gameObject); var instanceImage = instance.ForegroundButton.GetComponent <Image>(); StartCoroutine( ImageHelper.AssignImage( image.transformedSrc(), instanceImage, instance.BrokenImageIcon ) ); instance.transform.SetParent(transform, false); // Shift the thumbail over to the right instance.transform.position += new Vector3(offset, 0, 0); var instanceButton = instance.ForegroundButton.GetComponent <Button>(); instanceButton.onClick.AddListener(() => StartCoroutine(ImageHelper.AssignImage(image.transformedSrc(), ProductImage)) ); offset += 100; } }
public void SetCurrentProduct(Shopify.Unity.Product product) { ProductTitle.text = product.title(); // Reset the variants dropdown VariantsDropdown.ClearOptions(); // Parse variant titles into a list of strings and assign to the dropdown as the new options var options = new List <string>(); var variants = (List <Shopify.Unity.ProductVariant>)product.variants(); foreach (var variant in variants) { options.Add(variant.title()); } VariantsDropdown.AddOptions(options); // Only need to show the variants dropdown if there are more than one variant to choose from VariantsDropdown.gameObject.SetActive(variants.Count > 1); // Show the appropriately positioned description text ProductTitleDescription.gameObject.SetActive(variants.Count > 1); ProductTitleDescNoVariant.gameObject.SetActive(variants.Count <= 1); VariantsDropdown.onValueChanged.AddListener(HandleDropdownChange); // Assign the first product image to the main product image display var images = (List <Shopify.Unity.Image>)product.images(); StartCoroutine(ImageHelper.AssignImage(images[0].transformedSrc(), ProductImage)); RenderVariantImages(images); ProductPrice.text = variants[0].price().ToString("C"); ProductTitleDescription.text = product.description(); ProductTitleDescNoVariant.text = product.description(); CurrentProduct = product; CurrentVariant = variants[0]; }