1

So I'm developing j2store plugin to calculate price for item based on product's width and height (these values are entered by the user). The form is rendered as following:

function onJ2StoreBeforeAddToCartButton($product)
    {
        $html = "";
        if($product->variants->pricing_calculator === "square"){
            JFormHelper::addFormPath(__DIR__ . '/forms');
            $form = new JForm('dimmensions');
            $form->loadFile('dimmensions');
            $width_field = $form->getField('drobe_width');
            $heigth_field = $form->getField('drobe_heigth');

            $width_field->__set('id', 'drobe_width_'. $product->j2store_product_id);
            $heigth_field->__set('id', 'drobe_heigth_'. $product->j2store_product_id);

            $width_field->__set('onchange', "doAjaxPrice($product->j2store_product_id, '#add-to-cart-$product->j2store_product_id')");
            $heigth_field->__set('onchange', "doAjaxPrice($product->j2store_product_id, '#add-to-cart-$product->j2store_product_id')");

            $html .= $width_field->renderField();
            $html .= $heigth_field->renderField();

            $js = "<script type=\"text/javascript\">";
            $js .= "doAjaxPrice($product->j2store_product_id, '#add-to-cart-$product->j2store_product_id');";
            $js .= "</script>";

            $html .= $js;
        }

        return $html;
    }

The price on the product page is calculated correctly (the calculator class can see width and height parameters passed by the user). The problem is in the cart page. It is not getting these values, so I'm getting zeros in price. What is correct way of getting these values?

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.