News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

The Feature MultiAuthor

Started by lysov, March 25, 2012, 12:35:24 PM

Previous topic - Next topic

lysov

In many cases (books, music, etc.) must specify the number of authors for the product. This ability to easily integrate into VM (g.e. VM 203E).
First of all, we need to make some core changes:
- to the product model (administrator/components/com_virtuemart/models/product.php) add two functions

//<-- LYV 2012-03-11
/**
* Load the product manufacturers id
*
* @author LYV
* @return array list of Manufacturers ID
*/
private function getProductManufacturers($virtuemart_product_id=0) {

$manufacturers = array();
if ($virtuemart_product_id > 0) {
$q = 'SELECT `virtuemart_manufacturer_id` FROM `#__virtuemart_product_manufacturers` WHERE `virtuemart_product_id` = "'.(int)$virtuemart_product_id.'"';
$this->_db->setQuery($q);
$manufacturers = $this->_db->loadResultArray();
}

return $manufacturers;
}

/**
* Load the product manufacturers list
*
* @author LYV
* @return array list of Manufacturers for this product
*/
public function getProductManufacturersList($virtuemart_product_id=0) {

if ($virtuemart_product_id > 0) {
$query  = 'SELECT DISTINCT l.`mf_name`,l.`virtuemart_manufacturer_id` FROM `#__virtuemart_manufacturers_'.VMLANG.'` as l';
$query .= ' JOIN `#__virtuemart_manufacturers` AS m using (`virtuemart_manufacturer_id`)';
$query .= ' JOIN `#__virtuemart_product_manufacturers` AS pm using (`virtuemart_manufacturer_id`)';
$query .= ' WHERE m.`published`=1 AND pm.`virtuemart_product_id` ='.(int)$virtuemart_product_id;
$query .= ' ORDER BY l.`mf_name`';
$this->_db->setQuery($query);
return $this->_db->loadObjectList();
}
return array();
}
// LYV -->

After that, you need to make a couple of changes to this file
-- into the function getProductSingle()

// Load the shoppers the product is available to for Custom Shopper Visibility
$product->shoppergroups = $this->getProductShoppergroups($this->_id);

//<-- LYV 2012-03-11: add some manufacturers
$product->manufacturers = $this->getProductManufacturers($this->_id);
// LYV -->
$ppTable = $this->getTable('product_prices');


-- into the function fillVoidProduct()

$product->categories = array();
$product->shoppergroups= array();
//<-- LYV 2012-03-11: add some manufacturers
$product->manufacturers = array();
// LYV -->

if($front){


- to the Manufacturer model (administrator/components/com_virtuemart/models/manufacturer.php) add the function getManufacturerList() (it was commented):

//<-- LYV 2012-03-11: for MultiManufacturer = MultiAuthor
    /**
     * Select the Manufacturers to list on the product list page
     */
public function getManufacturerList() {
$db = JFactory::getDBO();
$q = "SELECT `virtuemart_manufacturer_id`, `mf_name` AS `text` FROM `#__virtuemart_manufacturers_".VMLANG."` ORDER BY `mf_name`";
$db->setQuery($q);
return $db->loadObjectList();
}
// LYV -->

- the next step, we need to make changes in the BE product view (at least) - administrator/components/com_virtuemart/views/product/view.html.php
-- into the function display()

/* Load the manufacturers*/
// $config = VmConfig::loadConfig();
$mf_model = VmModel::getModel('manufacturer');
//<-- LYV replaced for MA (combox -> listbox) -->
// $manufacturers = $mf_model->getManufacturerDropDown($product->virtuemart_manufacturer_id);
$manufacturers = $mf_model->getManufacturerList();
//<-- LYV 2012-03-11 add multiAuthor
if(!isset($product->virtuemart_manufacturer_id)) {
$product->virtuemart_manufacturer_id = 1; // As defined at the database
}
// LYV -->
if(count($manufacturers)>0 ){
//<-- LYV --> $lists['manufacturers'] = JHTML::_('select.genericlist', $manufacturers, 'virtuemart_manufacturer_id', 'class="inputbox"', 'value', 'text', $product->virtuemart_manufacturer_id );
$lists['manufacturers'] = JHTML::_('select.genericlist', $manufacturers, 'virtuemart_manufacturer_id[]', 'multiple="multiple"', 'virtuemart_manufacturer_id', 'text', $product->manufacturers);
}

$lists['product_weight_uom'] = ShopFunctions::renderWeightUnitList('product_weight_uom',$task=='add'? VmConfig::get('weight_unit_default'): $product->product_weight_uom);


- the next step is editing FE view and layout - components/com_virtuemart/views/productdetails/view.html.php and components/com_virtuemart/views/productdetails/tmpl/default_manufacturer.php
-- view.html.php - edit the function display()

/* Load the product */
// $product = $this->get('product'); //Why it is sensefull to use this construction? Imho it makes it just harder
$product_model = VmModel::getModel('product');

$virtuemart_product_idArray = JRequest::getInt('virtuemart_product_id', 0);
if (is_array($virtuemart_product_idArray)) {
    $virtuemart_product_id = $virtuemart_product_idArray[0];
} else {
    $virtuemart_product_id = $virtuemart_product_idArray;
}

$product = $product_model->getProduct($virtuemart_product_id);
//<-- LYV 2012-03-11
$manufacturers = $product_model->getProductManufacturersList($virtuemart_product_id);
// LYV -->
        ...
        ...
$this->assignRef('min_order_level', $min_order_level);

//<-- LYV 2012-03-11
$this->assignRef('manufacturers', $manufacturers);
// LYV -->
        ...


-- the layout default_manufacturer.php

<div class="manufacturer">
<?php
$i 0;
/* Avoid JavaScript on PDF Output */
if (strtolower(JRequest::getWord('output')) == "pdf") {
foreach ($this->manufacturers as $author) {
if ($i++ > 0) echo ', ';
$link JRoute::_('index.php?option=com_virtuemart&view=manufacturer&virtuemart_manufacturer_id=' $author->virtuemart_manufacturer_id '&tmpl=component');
echo JHTML::_('link'$link$author->mf_name);
}
} else {
?>

<span class="bold"><?php echo JText::_('COM_VIRTUEMART_PRODUCT_DETAILS_MANUFACTURER_LBL'); ?></span>
<?php
foreach ($this->manufacturers as $author) {
if ($i++ > 0) echo ', ';
$link JRoute::_('index.php?option=com_virtuemart&view=manufacturer&virtuemart_manufacturer_id=' $author->virtuemart_manufacturer_id '&tmpl=component');
?>

<a class="modal" rel="{handler: 'iframe', size: {x: 700, y: 550}}" href="<?php echo $link?>"><?php echo $author->mf_name?></a>
<?php
}
?>

</div>

Now we can check the performance of this feature!
And for completeness, we need more to make small changes to the BE view for the list of the products (column Manufacturer).

Paul66

Hi lysov,
I needed the multi-manufacturer option that you have described in your post for a website, so I went through the process of adding the code to virtuemart files as you instructed. It all seems to have went well untill I click on a product and I get multiples of this error coming up:
....................\libraries\joomla\html\html\select.php on line 85

I also don't see how to choose multiple manufacturers in the virtuemart product control panel.

Can you please help?

Thanks

lysov

I did not complete this development. For books are very important order of authors. In my case, this is achieved by the output order FIFO. The patch for versions 2.0.15a - 2.0.15e for applying is attached. Lack of my decision is the wrong display of authors in the BE list of products.
To apply the patch please follow next steps:
1. Unpack VM 215e to the /var/www/html/tempo/vm/215a/ (this is important, this path is written in the patch file!!!)
2. Copy the patch for example to your html folder (/var/www/html/<your-site>/)
3. Run next shell commands:
$  cd /var/www/html/<your-site>/
$  patch -p0 -i manufacturers-215.patch
4. Replace FE template to the attached version (components/com_virtuemart/views/productdetails/default_manufacturer.php)

[attachment cleanup by admin]

bobchain

Hi lysov,
after much research and finding answer to my problem in your post.

my problem is the same that you have show in the first post:
how can I assign an article to more manufacturers?

the problem arises since my shop is selling books and managing manufactures such as writers, poets, authors,  I need to be able to assign certain items (books) that are written by more manufaturers simultaneously.

I tried manipulating the association table article_manufactures manually [myid_virtuemart_product_manufacturers].
the creation of the report allows me to associate more rightly [virtuemart_manufacturer_id] same [virtuemart_product_id].
Search filters keep track of the relationship and I relate in the same book page: items list for manufacturers, and other pages of search or filters.

The problem remains, however, in the management: for each item I can not associate multiple manufacturers.

How can I change the management page of the article to allow the assignment to multiple manufacturers? Maybe the same method that is used to assign an item to multiple categories.

I read your guide but I have a problem when I need to execute the patch.
Is not possible modify every file in the manually mode? could you send me the index of step to do?

Then in the next update of VM2 I could have problem with this management?

my actually environment is: joomla 2.5.8 + VM 2018

thank you very much for every your answer, hopeful for your help!

Roberto

bobchain

Hi Lysov,
I was able to make the changes that you specified in the patch manually.

Only problem is still reflected in the view: List products, manufaturers column shows only an "author" as I was expecting to see the field as the column categories.
Where can I be wrong?

thank you for your help.

Roberto

tobisagt

#5
Thx for your instructions! It works like a charm!!! :)

But one i really want to know. How to show the manufacturers description of each author in product details?
I hope you can help me!

EDIT: And a second question. Is it possible to show alle authors on category view?

Thx
-Tobi

penart

Hi,

Could you please help me with the procedure of the Feature MultiAuthor at vm2.  I cannot understand how to do this.  I have a site for a school, and I have to add many teachers (manufacturers) in on product (course).

Thanks in advance
Penelope

bobchain

dear,
I wish I could use the same function (multi-combination) on the category view.
who I know how to modify the core files "category" to use the same query to display into override of  the category view?

@VM DEV: whi not include this feature in the next release?
would be very useful to be able to assign a single product more "manufacturer" (make management much more flexible and usable) my case: book (multiple authors for each book), or training courses (more professors / teachers or schools)
or if we have a parent product and No. variants products, check more producers to the father, and son is just one specific

Roberto

Adam Bazaroff

Any solution for 2.6.6? Don't understand, why Developers don't add multiple manufacturers? It strongly need for bookstores (2-3 authors on once book), music stores (CD compilations) and other.
/Adam'B ... Poor english mode [ON] ;D

Milbo

Because it is added in vm3 and it takes a day to implement and test it. If you pay the day, we can do it.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

balai

Have you tried custom fields?

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

vm_ASL

Hello there,

i was looking forward to the multiple manufacturer option  in vm3 resp. 2.9.9. and i'm happy we're able to select multiple mf to one product.

BUT how can i achieve to really show these manufacturers on the productdetailspage?

what do i have to change here? (components/com_virtuemart/views/productdetails/default.php)


      <?php
      // Manufacturer of the Product
      if (VmConfig::get('show_manufacturers', 1) && !empty($this->product->virtuemart_manufacturer_id)) {
         echo $this->loadTemplate('manufacturer');
      }
      ?>

im using Joomla 3.3.6 and vm 2.9.9.2


tobisagt

Hi. I dont know if this is useful for you because its in german: http://www.webnut.de/webnut-blog/geschreibsel/52-virtuemart-3-es-wird-nur-ein-hersteller-angezeigt.html
Replace the code in "default_manufacturer.php" in your template overrite with this code:

<div class="manufacturer">   
    <?
        $manufacturers_id = $this->product->virtuemart_manufacturer_id;
         
        // Zähle die Hersteller
        $numManufacturer = count($manufacturers_id);
     
        $i = 1;
         
        // Gebe die Hersteller aus
        foreach($manufacturers_id as $manufacturer_id)
        {
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('mf_name');
            $query->from($db->quoteName('#__virtuemart_manufacturers_de_de'));
            $query->where($db->quoteName('virtuemart_manufacturer_id')." = ".$manufacturer_id);
             
            $db->setQuery($query);
            $manufacturers_details = $db->loadObject();
             
            // Produktlink des Herstellers
            $link = JRoute::_('index.php?option=com_virtuemart&view=manufacturer&virtuemart_manufacturer_id=' . $manufacturer_id .'&tmpl=component', FALSE);
            $name = $manufacturers_details->mf_name;
             
            /* Avoid JavaScript on PDF Output */
            if (strtolower(vRequest::getCmd('output')) == "pdf") {
                echo JHtml::_('link', $link, $name);
            } else {
            ?>
                <a class="manuModal" rel="{handler: 'iframe', size: {x: 700, y: 550}}" href="/<?php echo $link ?>"><?php echo $name ?></a> 
             
                <?php        
                
// Füge ein Komma hinter jeden Hersteller, außer dem letzten.
                
if ($i != $numManufacturer)
                {
                    echo 
', ';
                }
            }   
            
$i++;
        }
    
?>

</div>


I hope it is useful for you.

Maybe you need to change this line to your language:
$query->from($db->quoteName('#__virtuemart_manufacturers_de_de'));

Milbo

I strongly recommened to use the vm api for stuff like that


foreach($manufacturers_id as $manufacturer_id)
        {
            $db = JFactory::getDbo();

This is evil, avoid always sql in the templates, better use the cached vm objects

$manModel = VmModel::getModel('manufacturer');
$manufacturers_details = $manModel->getManufacturer($id);

....
then you also do not have to think about the language. In your case language fallback wouldnt work.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/