News:

Looking for documentation? Take a look on our wiki

Main Menu

Tutorial: How to add "make offer" and "auction bid" functions

Started by guybr, June 12, 2015, 13:21:46 PM

Previous topic - Next topic

guybr

I don't know if I'm publishing this in the right place but here goes:

I'm using VM 2.6.6 but I think this recipe will work on other versions.

I needed a way to be able to do 2 things: enable visitors to make an offer on specially designated items, and in a similar way to receive bids from visitors on certain items.

Regarding the bid function specifically, in my business (antiques/collectibles), auctions often run over a published period of time, like a month, and bids are received in writing - something called "mail auctions" or "mailbids". Mailbids can be 'silent' whereby the present bid level is not published (and participants contact the auctioneer to check), or they can be visible. Visibility here will require development, and the basis for it may work with this idea: http://arwan.lecture.ub.ac.id/files/2012/02/Pert-6-PHP-Manipulating-Database-using-PHP.pptx, and I'll look into it.

But for now, for my needs I just a targeted way of enabling users to submit a bid in writing. (I don't have a problem purchasing auction software but here my problem is two-fold: I need that it be integrated with VM2, and the price of most programs is exorbitant - a few thousand $.)

For both my needs the solution was to replicate the "ask a question" email function (which is directly associated with the item in question), alter the text and button, and conditionally display it on the category, VM store homepage and product details page.

Here's the recipe:

1. Create a custom field for each:
-> boolean field type
-> show title (for admin)
-> publish
-> "no" cart attribute
-> layout position (the critical 'flag' for identifying the field) - "bid" or "offer"
-> "yes" admin only
-> "no" is a list
-> "yes" hidden


2. copy the "askquestion" view folder and paste it twice: give each copy a name (eg. "makeoffer", "submitbid")


3. go though all the files of each folder and adapt the coding to suit "makeoffer" and "submitbid"
-> create new text string labels (see below)
----> the overrides don't really save: need to "save & close" after each one!!
-> upload to the views/ directory


4. must replicate and adapt segments pertaining to "ask question" in these files:
-> vmsite-ltr.css
-> controllers/productdetails.php
-> views/productdetails/tmpl/default.php
-> views/productdetails/view.html.php
-> com_virtuemart/router.php
-> category/tmpl/default.php
-> category/tmpl/default_products.php


SOME NOTES:
1. in views/productdetails/view.html.php I duplicated the $askquestion_url JROUTE pattern and adapted it even though in the end I don't seem to have been able to rely on $makeoffer_url (in productdetails/tmpl/default.php) - nevertheless, did it.


2. in productdetails/tmpl/default.php, after much QA, this coding worked for me:

a)
// Make an Offer contact us option:
if (!empty($this->product->customfieldsSorted['offer'])) {
    ?>
          <div class="make-an-offer">
            <a class="make-an-offer" href="<?php echo $this->makeoffer_url ?>" rel="nofollow" ><?php echo JText::_('COM_VIRTUEMART_PRODUCT_MAKE_OFFER_LBL') ?></a>
          </div>
      <?php }
      ?>

b) further up, in the jquery section:
i. comment out the "ask_question" condition as I don't want to be tied to it
ii. DO USE the JRoute URL instead of the askquestion styled href: '" . $this->makeoffer_url . "', - because this never worked!

   /*if(VmConfig::get('ask_question', 0)){*/
      $boxOffer = "jQuery.fancybox({
            href: '" . JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=makeoffer&virtuemart_product_id=' . $this->product->virtuemart_product_id . '&virtuemart_category_id=' . $this->product->virtuemart_category_id . '&tmpl=component') . "',
            type: 'iframe',
            height: '550'
         });";
   /*}*/


3. in controllers/productdetails.php
a) in the section called * View email layout on browser, make sure to replicate the askquestion (and not recommended) coding because of a slight difference in their coding!

b) should this file cause a white screen (with an error when using debug) the problem is because of excess line spacings: obtain a copy from the original VM installation package (which doesn't have all those line spacings) and work on that copy.

c) I tried adding the auto-subscribe (into acymailing patch) as per https://forum.virtuemart.net/index.php?topic=129993.0
but so far I don't see that my test mails were auto-subscribed...


4. in category/tmpl/default.php and category/tmpl/default_products.php I used the following to conditionally display the contact links, and placed them just below the 'product details' button:

                  <?php
                  // Display Make an Offer option, if item has been set with this customfield. Source: http://forum.virtuemart.net/index.php?topic=103145.msg342591#msg360038 and http://forum.virtuemart.net/index.php?topic=118770.0
                  foreach ($product->customfields as $field){
                  if( $field->layout_pos=='offer'){?>
                     <span class="make-an-offer">
                     <a class="make-an-offer modal" rel="{handler: 'iframe', size: {x: 700, y: 550}}" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=makeoffer&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id . '&tmpl=component'); ?>"><?php echo JText::_('COM_VIRTUEMART_PRODUCT_MAKE_OFFER_BTN') ?></a>
                     </span><?php
                  //if (!empty($product->customfieldsSorted['offer'])) {
                  //echo JHTML::link ($product->makeoffer_url, JText::_ ('COM_VIRTUEMART_PRODUCT_MAKE_OFFER_BTN'), array('title' => $product->product_names, 'class' => 'product-details'));
                     }
                  elseif( $field->layout_pos=='bid'){?>
                     <span class="submit-a-bid">
                     <a class="submit-a-bid modal" rel="{handler: 'iframe', size: {x: 700, y: 550}}" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&task=submitbid&virtuemart_product_id=' . $product->virtuemart_product_id . '&virtuemart_category_id=' . $product->virtuemart_category_id . '&tmpl=component'); ?>"><?php echo JText::_('COM_VIRTUEMART_PRODUCT_SUBMIT_BID_BTN') ?></a>
                     </span><?php   
                  }
                  }
                  ?>