/// <summary>
        /// Used internally by the SDK to construct a CartLineItem.
        /// </summary>
        /// <param name="variant">The variant this CartLineItem will be associated to</param>
        /// <param name="onChange">This function will be called whenever the CartLineItem is modified</param>
        /// <param name="quantity">The count of items to be ordered</param>
        /// <param name="customAttributes">Custom attributes for this line item used to customize and add meta data</param>
        public CartLineItem(ProductVariant variant, LineItemChangeHandler onChange, long quantity = 1, IDictionary <string, string> customAttributes = null)
        {
            _VariantId = variant.id();
            _Quantity  = quantity;
            _Price     = variant.priceV2().amount();
            OnChange   = onChange;

            if (customAttributes != null)
            {
                CustomAttributes = new ObservableDictionary <string, string>(customAttributes, () => { OnChange(CartLineItems.LineItemChangeType.Update, this); });
            }
        }
Exemple #2
0
        public void TestCustomScalarMoney()
        {
            string json = @"{
                ""priceV2"":{
                    ""amount"": 3.23,
                    ""currencyCode"": ""CAD""
                }
            }";

            ProductVariant variant = new ProductVariant((Dictionary <string, object>)Json.Deserialize(json));

            Assert.AreEqual(3.23M, variant.priceV2().amount());
        }
        public void SetCurrentProduct(Product product, ProductVariant variant, int quantity)
        {
            gameObject.SetActive(true);

            ProductTitle.text = product.title();
            VariantTitle.gameObject.SetActive(variant.title() != "Default Title");
            VariantTitle.text = variant.title();
            Quantity.text     = quantity.ToString();
            Price.text        = variant.priceV2().amount().ToString("C");

            try {
                _imageSrc = variant.image().transformedSrc();
            } catch (NullReferenceException) {
                var images = (List <Shopify.Unity.Image>)product.images();
                _imageSrc = images[0].transformedSrc();
            }

            _currentVariant = variant;
        }
 private void UpdateDetailsUsingVariant(ProductVariant variant)
 {
     Price.text = "$" + variant.priceV2().amount().ToString();
 }