News:

Looking for documentation? Take a look on our wiki

Main Menu

PRODUCTS ON VIRTUEMART FRONTPAGE WITH CATEGORY NAME [SOLVED]

Started by zinon, March 31, 2013, 01:00:40 AM

Previous topic - Next topic

zinon

USING JOOMLA! 2.5.6 and Virtuemart  2.0.20b on xampp and win7 x64

Okay brothers!
I had a nice time trying to understand the Joomla! framework by reading the docs but I 've realised that the best way to learn something about it is to try an tweak a little the machine!
I needed to put the category name above each product shown in the VirtueMart frontpage.
The easy way was to change all the productnames to begin with the product's category name.
But what if you have a hell of categories already set???
So I tried to tweak a little the output...
BUT after I made some tweaks, I realised that the category name was in plural while the shop was showing one product.
Example :
AIR CONDITIONERS
MSY-09HRDN1

So I needed a special field for the categories which would hold the category name in single. (AIR CONDITIONER)
I added one more column in my database named category_single and I started twisting the admin side so that I can update it through it.
Afterwards I used the paradigm of the $product->product_name and tried to make it running for $product->category_single
In order to do it I had to understand what is a model, a table script, a helper, a component, a view and a template!
I thing it would be a nice exercise for all rookies like me!

Whoever is still wondering what are this tools and what do they really do, I suggest they should try the challenge of solving this problem!

MY SOLUTION:

STEP 0
BACKUP EVERY FILE IN STEPS 2 TO 7

STEP 1
Connect to your Joomla database and add a new column named category_single in the table ????_virtuemart_categories_en_gb
with same attributes as the category_name column

STEP 2
In file: YourSite\administrator\components\com_virtuemart\views\category\tmpl\edit_categoryform.php
under line 46: <?php echo VmHTML::row('input','COM_VIRTUEMART_CATEGORY_NAME','category_name',$this->category->category_name); ?>
insert this line:
<?php echo VmHTML::row('input','COM_VIRTUEMART_CATEGORY_SINGLE','category_single',$this->category->category_single); ?>

STEP 3
In file: YourSite\administrator\components\com_virtuemart\controllers\category.php
under line 50: $data['category_name'] = JRequest::getVar('category_name','','post','STRING',JREQUEST_ALLOWHTML);
insert this line:
$data['category_single'] = JRequest::getVar('category_single','','post','STRING',JREQUEST_ALLOWHTML);

STEP 4
In files :
YourSite\administrator\language\en-gb\en-GB.com_virtuemart.ini
and
YourSite\language\en-gb\en-GB.com_virtuemart.ini
add in alphabetical order this line:
COM_VIRTUEMART_CATEGORY_SINGLE="Category Name in Single"

STEP 5
In file: YourSite\administrator\components\com_virtuemart\tables\categories.php
Change line 92 to look like this:
$this->setTranslatable(array('category_name','category_single','category_description','metadesc','metakey','customtitle'));

STEP 6
In file: YourSite\components\com_virtuemart\views\virtuemart\tmpldefault_products.php
line 51 under <h3> tag insert this lines
<?php // Category Sinlge
echo JHTML::link ( JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $product->virtuemart_category_id), $product->category_single, array ('title' => $product->category_single ) );  ?>
<br/>

STEP 7
In file: YourSite\administrator\components\com_virtuemart\models\product.php
under line 922: $product->category_name = $catTable->category_name;
$product->category_single = $catTable->category_single;

under line 925: $product->category_name = null; 
insert line:
$product->category_single = null;

THE END
I hope I gave you something back bros!!!

PRO

lol,

no


vmart frontpage?

here is what I do to make a link

views/virtuemart/default_products.php

inside the foreach

   <?php // Category Name
               echo JHTML::link ( JRoute::_ ( 'index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $product->virtuemart_category_id ), "View All ".$product->category_name, array ('title' => "View All ".$product->category_name ) ); ?>


for just the name

<?php echo $product->category_name ?>


you are hacking the core for no reason at all

http://forum.virtuemart.net/index.php?topic=90935.0
http://forum.virtuemart.net/index.php?topic=97744.0
http://forum.virtuemart.net/index.php?topic=92756.0

PRO


zinon

The deference is that I display one product (airconditioner)
Category name describes in plural (airconditioners)
The use of a custom field is more difficult for the administrator,
because I suppose he would have to declare it in each product.
Hey Pro 9.000 posts? Respect!
How did you do it man?
Are you plugged in matrix?