Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Adding product to cart through QR code? #601

Description

@Sterling-Malory-Archer

I have a client that would like to add a product to the cart by scanning a QR code.

Is this possible? How can I achieve this? I have a QR code scanner script and I know I should reference cartPanel script and it's method .AddToCart, but how can I reference product and variant?

   if (cameraManager.TryGetLatestImage(out XRCameraImage image))
                        {
                            // 'image' is an acquired resource that must be diposed when we are done.
                            using (image)
                            {
                                // - Convert the image to RGBA. This takes considerable time, so there are also asynchronous
                                //   options. It's easier to understand the synchronous code for this example, though.
                                //
                                // - It's /much/ faster to convert to a single channel format, e.g., TextureFormat.R8, if
                                //   your 'BarcodeReader' can accept that. But if it only accepts an RGBA image, then this
                                //   should work too.
                                var conversionParams = new XRCameraImageConversionParams(image, TextureFormat.RGBA32, CameraImageTransformation.MirrorY);

                                // Get the size (number of bytes) of the buffer required to hold the RGBA pixel data.
                                var dataSize = image.GetConvertedDataSize(conversionParams);
                                var bytesPerPixel = 4; // because we chose an RGBA format.

                                // Since the 'BarcodeReader' code you posted accepts a managed
                                // array, that's what I've used here. It would be more efficient
                                // to use a NativeArray if the BarcodeReader can use that.
                                var pixels = new Color32[dataSize / bytesPerPixel];
                                fixed (void* ptr = pixels)
                                {
                                    image.Convert(conversionParams, new IntPtr(ptr), dataSize);
                                }

                                IBarcodeReader barcodeReader = new BarcodeReader();
                                // The 'pixels' array now contains the image data.
                                var result = barcodeReader.Decode(pixels, image.width, image.height);
                                if (result != null)
                                {
                                    if (result.Text.Contains("productID"))
                                    {
                                           //Add product to cart
                                           cartPanel.AddToCart(productID);
                                    }
                                }
                            }
                        }

Any help is kindly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions