2

Array :-

 foreach ($relatedProducts as $relatedProduct) {
        $_product = $objectManager->create('Magento\Catalog\Model\Product')->load($relatedProduct->getId());
        $skus = $_product->getSku(); //get name
        $array[] = $skus;
    }
$str = serialize($array);
$strenc = urlencode($str);

URL :-

<script>
    function onTryonClick(argument) {
var url = "https://modakatech.com/camweara_vaibhav/index.php?skus=<?php echo $strenc; ?>&lengths=<?php echo $lengths;?>&cat=<?php echo $catlast;?>";
alert(url);
</script>

1 Answer 1

2

You can use this code:

foreach ($relatedProducts as $relatedProduct) {
        $_product = $objectManager->create('Magento\Catalog\Model\Product')->load($relatedProduct->getId());
        $skus = $_product->getSku(); //get name
        $array[] = "sku[]=".$skus;
    }

Now in your script, use this:

<script>
    function onTryonClick(argument) {
var url = "https://modakatech.com/camweara_vaibhav/index.php?<?php echo $implode("&",$array); ?>&lengths=<?php echo $lengths;?>&cat=<?php echo $catlast;?>";
alert(url);
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.