We know in Virtuemart we can make child product leaving some of its parameters that will be taken from parent product. We can understand this with an example like:
First we create one Parent product with name Parent and its two child products Child1 and Child2
Now we set some basic attributes of them:
Parent => Price = $100, Manufacturer = ‘xyz’.
Child1 => Price = not set, Manufacturer = not set
Child2 => Price = $250, Manufacturer = ‘abc’
The buyer will finally get to see
Child1 => Price = $100, Manufacturer = ‘xyz’, taken from its parent.
Child2 => Price = $250, Manufacturer = ‘abc’.
Use of functions and return data:
To use the listed function we must have included vmconfig.php and initialized its loadConfig() method, as
require(JPATH_ADMINISTRATOR.'/components/com_virtuemart/helpers/config.php'); VmConfig::loadConfig();
then call respective methods after taking instance of product model as
$productModel = VmModel::getModel('Product');
now you can simple call any of the method as
$product = $productModel->getProduct ('$virtuemart_product_id'); $productSingle = $productModel->getProductSingle ('$virtuemart_product_id');
getproduct()
will return data with attributes of parent product, while
getproductSingle()
will not only return data for a single product but it contains the attribute of the same product regardless of it being a child or a parent.
So, from the above cases
for Child1: getProductSingle()
, returns Manufacturer = ”, on the same hand getProduct()
, returns Manufacturer = ‘xyz’.
for Child2: both getProductSingle()
and getProduct()
returns Manufacturer = ‘abc’ as it is directly set onto that product.
There are other differences in return parameters of both of these functions, as you get basePrice and salesPrice using
getProduct()
but have to evaluate final price if you usegetProductSingle()
For any query regarding virtuemart plugins and add-ons you can communicate with us by creating a ticket at:
https://webkul.uvdesk.com/en/customer/create-ticket/
Be the first to comment.