I want to add a product in a particular website.

I am using below code for add to cart product programmatically.

try {
    $params = array();
    $params['qty'] = 1;//product quantity
    $_product = $this->product->loadByAttribute('sku', $getsku);

    if ($_product) {

        $additionalOptions = [];
        $additionalOptions[] = array(
           'label' => "yyyy",
           'value' => $this->getRequest()->get('attendeename'),
        $additionalOptions[] = array(
            'label' => "zzzzz",
            'value' => $this->getRequest()->get('relationship'),
        $_product->addCustomOption('additional_options', serialize($additionalOptions));

        $this->cart->addProduct($_product, $params);
        $errmsz['success'] = "1";


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.