News:

Looking for documentation? Take a look on our wiki

Main Menu

Need to output the parent product

Started by JeeT.Birdi, February 24, 2015, 01:36:55 AM

Previous topic - Next topic

JeeT.Birdi

Hi,

Im using a component to display several different colors for a product. I want to link the color button to those child product.

I named my child product like : 'parent product name + label of color button'  .
I write this to make my link.

My question is: is there any function to call the parent product?  Does anyone know?

1 <a href="http://www.mydomain.com/index.php/component/virtuemart/
2             <?php
3                    $(document).ready(function() {                           //so it execute when html is ready
4                              echo "
5                              <script type=\"text/javascript\">
6                                    var  parentproductname.= $parentproductname;
7                                    var  colorlabel = $colorlabel;
8                                    document.write(parentproductname.'-'.colorlabel);
9                              </script>
10                   });
11             ?>
12  ";
13 </a>

My result should look like this:
http://www.mydomain.com/index.php/component/virtuemart/parentproductname-colorlabel

PS: i'm on my child product page using Joomla 3.3.6 and VM 3.0.2

JeeT.Birdi

This should be better but still not working:

<a href="/index.php/component/virtuemart/
   <?php
      $(document).ready(function() {                           //so it execute when html is ready
         function lienjeet() {
            $partie1 = parent::$this->product->product_name;
            $partie2 = $color_label;
            echo '$partie1 . '-' . $partie2';
               }
      });
   ?>";

GJC Web Design

this is a bizarre mix of javascript, jquery and php

check some basic 101 js and php tutorials
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

JeeT.Birdi

Can I write something like this to output the parent product name?

<a href="http://www.mydomain.com/<?php echo (parent::$this->product->product_name . '-' . $color_label)?>">

Milbo

#4
No, you mix inheriting of classes with objects.
The normal way is

$model = VmModel::getModel('product');
$parent = $model->getProduct($product->product_parent_id );
vmdebug('my parent',$parent); //just an output

Btw, it is very, very likely that the parent is already loaded (actually it is already loaded to 100%).
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

GJC Web Design

or if you just want the id of the parent it is available in the children's object as   $this->product->product_parent_id
inside the ajax refresh block
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

JeeT.Birdi

#6
Can I use $this->product->product_parent_name instead?
Milbo can you tell me how to write a query with a WHERE AND??
Find this documentation, but cannot get rid of it...
Like this:

         $monparent= $this->product->product_parent_name;
         $monlabel= $colorbuttonlabel;

         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select($db->quoteName('virtuemart_product_id'));
         $query->from($db->quoteName('#__virtuemart_products_fr_fr'));
         $query->where($db->quoteName('product_name') . ' LIKE '. $db->quote('\'%$monparent%\'') . ' AND '. quoteName('product_name') . ' LIKE '. $db->quote('\'%$monlabel%\''));
         $db->setQuery($query);
         $results = $db->loadObjectList();

         $label_html.='<a href="http://www.mydomain.com/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=';.$results.'"><div class="color_button_inner_value" style="'.$label_style.'"></div></a>';
      }


Example:

Product:                 Ferrari
Color Button label: Red
Child:                     Ferrari Red

So when I click on the color button red on the child product 'ferrari green', i should go on the id of product ('parent product' +  'label').
This way all the products will automatically be linked to child from the color button.

I know that I have very few knowledge...but I keep learning.

Milbo

you should not write your own queries, only if you cannot access it by vm api.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

JeeT.Birdi

How can I do it then?? How to link dynamically the buttons and the child product??
Can you give me a direction?

GJC Web Design

there is afaik no such node as $this->product->product_parent_name

you can't just make up your own objects and wish they were there --

why are you trying to write a query to find the prod id by its name when you already know it by $this->product->product_parent_id ?????

I told u this 3 posts back
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

JeeT.Birdi

#10
Maybe i was not clear enough.

I'm not trying to get the parent products but the parent product NAME.
Because the child product's name are formatted manually like this 'Parent Product Name AND label'

This query is for retrieving ANY others products with the Same Parent Name AND the Label.
So if the label of the button i'm clicking is GREEN, then it should get the product with : parent's name + GREEN
Example:
Parent Name: Ferrari
Child Name: Ferrari Red
Child Name: Ferrari Green
Child Name: Ferrari Yellow

On each product page I have those button and the label of those button is respectively (red, yellow, green).

So if I click on the yellow button, it will query the one product which match the parent product'name  PLUS match also the label.
If you check all my replies code, you will understand that it's the only thing i'm trying to do...

But Milbo advice me to not write my own query. So how can I do it??

Milbo

Quote from: Milbo on February 25, 2015, 10:11:51 AM
No, you mix inheriting of classes with objects.
The normal way is

$model = VmModel::getModel('product');
$parent = $model->getProduct($product->product_parent_id );
vmdebug('my parent',$parent); //just an output

Btw, it is very, very likely that the parent is already loaded (actually it is already loaded to 100%).

DO THAT! and in special the part vmdebug('my parent',$parent); //just an output  and of course enable the vmdebug, then your questions are obsolete.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/