VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: Picklehead on January 08, 2023, 18:39:36 PM

Title: New To Plugins
Post by: Picklehead on January 08, 2023, 18:39:36 PM
Hi,
New to creating plugins and just after a little help.

Have created my xml installation file and my plugin php file and all works as expected.

Also created my tmpl/default.php which all works, but from this file I need to be able to access $this->product->product_box but I cannot seem to get this to work,

I am using boxQ = '.$this->product->product_box.';

Any help would be much appreciated!

Thanks


Using Joomla! 3.10.11 and VirtueMart 3.8.7

Title: Re: New To Plugins
Post by: GJC Web Design on January 08, 2023, 18:48:08 PM
QuoteboxQ = '.$this->product->product_box.';

is there anything set for $this->product->product_box?

print 'Debug Line '.__LINE__.' $this->product <pre>'; print_r ($this->product); print "</pre><br />\n";

as for the syntax ... echo 'boxQ = '.$this->product->product_box; is that what u mean?

or

$boxQ = $this->product->product_box;
echo $boxQ;

hard to know what your trying to display...
Title: Re: New To Plugins
Post by: Picklehead on January 08, 2023, 19:30:21 PM
Thanks for the reply!

Yes, under Product Dimensions and Weight i have a value for Units in Box for all products.

My default.php adds a single input box on the product details page as a custom field and on keyup a function is called. I am simply trying to use the value of the product Units In Box for calculations within this function.

I have added an extra field to the params of my plugin as a temporary holder for a Units in Box value to test my calculations and all works exactly as I want.

I just need to avoid having to enter a Units in Box value into the custom field for all products when it already exists on each product

Hope that makes sense.

Thanks again
Title: Re: New To Plugins
Post by: Picklehead on January 08, 2023, 19:59:05 PM
Chopped abbreviated version of the function


$j = 'function setQuantity(myElem,inVal,sVal){

if(sVal > 0.0){
    quantity = Math.ceil(inVal/sVal);
    tempQuant = Math.ceil(quantity / '.$this->params->in_box.');
    tempOut = tempQuant * '.$this->params->in_box.'
    quantity = tempOut;
outQuant = quantity * sVal ;
}

myElem.val(outQuant);

return true;
};


Where '.$this->params->in_box.' needs to be the value of $this->product->product_box
Title: Re: New To Plugins
Post by: Picklehead on January 09, 2023, 13:52:29 PM
Thanks for the help, I found this worked for me.


$productModel = VmModel::getModel('Product');
$product = $productModel->getProduct($viewData[1]->virtuemart_product_id);