How can I add "Quantity" to a VirtueMart "Browse" page? - joomla

My VirtueMart shop.browse page has the typical columns of SKU, Name, Price, and "Update" (which contains the Add to Cart button). I would like to add a Quantity column between Price and Update so that a buyer can choose a quantity prior to pressing the "Add to Cart" button.
Though I don't know HOW to do this, I think I know WHERE to do it:
/public_html/components/com_virtuemart/themes/default/templates/browse/includes/browse_listtable.tpl.php
Lines 67-72 of that file tell the program how to build the table, but what I DON'T know how to do is modify the code source to tell it to include quantity as an element for the table. Here's the code:
// Loop through each row and build the table
foreach($data as $key => $value) {
$table->addRow( $data[$key], 'class="sectiontableentry'.$i.'"', 'td', true );
$i = $i == 1 ? 2 : 1;
}
Which include file is actually being called in this foreach loop, and what code would I add to reference quantity data?

You should not modify your core code. If you just need to put quantity box inside your browse template use variable $form_addtocart
It will give you quantity box and add to cart button.
All variables for browse page and for flypage template you can find here:
http://virtuemart.net/documentation/Developer_Manual/Modifying_the_Layout.html
If this is not what you are trying to get, please be more specific, or show your web page.

Related

Magento display a 3rd price on the product page

I would like to add a third price to my products like "MSRP" on the latest version but not available on mine (Magento 1.4.1.1).
I would like to display it on the product page and it has to change according to the selected option.
So, I started by creating a new attribute called "msrp".
I managed to get it for every child product on my view.phtml file with the following code:
<?php
if($_product->isConfigurable())
{
$_associatedProducts = $_product->getTypeInstance()->getUsedProducts();
foreach($_associatedProducts as $assProducts)
{
$msrp = $assProducts->getData("msrp");
echo "MSRP: ".$msrp."<br />" ;
}
}
?>
Now the question is how to show it only one at a time and which corresponds to the selected option?
(Just like the normal price changes when we select an option.)
Maybe with a piece of javascript in this file?
/app/design/frontend/[...]/[...]/template/catalog/product/view/type/options/configurable.phtml
Thanks for your help !

Magento Bundle Product - Multiple Options with Same products. How to stop Magento from hiding the repetitive products?

I am trying to setup a bundle product within Magento. This product should allow the customer to select 4 free products to include with the bundle. These products can be all different or 4 of the same product.
For example
Free Product 1
Free Product 2
Free Product 3
A customer could select four of Free Product 1, or one of Free Product 1 & 2, with two of Free Product 3.
I am using 4 drop-down input types which each have all three Free products as options. So a customer can choose any of the three products for each Free Gift line item.
Magento is only displaying one of the drop-down select lists, I believe due to the fact that each drop-down contains the same product list.
Where would I need to look to stop Magento from checking if the product options are already listed in a previous selection?
Unless you're doing this programmatically (that is writing the code), there's no way to do this.
When Magento adds a product, it first looks into the quote / shopping cart to see if one already exists. If one does, it pulls that one and adds to the quantity. There is no way to turn this off.
Programmatically, you very manually add an item to a shopping cart. This is how...
$cart = Mage::getSingleton("checkout/cart");
foreach ($products_to_add as $product_id => $custom_options) {
$product = Mage::getModel("catalog/product")->load($product_id);
$options = new Varien_Object(array("options" => $custom_options,
"qty" => 1));
// some products may result in multiple products getting added to cart
// I beleive this pulls them all and sets the custom options accordingly
$add_all = $product->getTypeInstance(true)
->prepareForCartAdvanced($options, $product, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL);
foreach ($add_all as $add_me) {
$item = Mage::getModel('sales/quote_item');
$item->setStoreId(Mage::app()->getStore()->getId());
$item->setOptions($add_me->getCustomOptions())
->setProduct($add_me);
$item->setQty(1);
$cart->getQuote()->addItem($item);
}
}
// when done adding all the items, finally call save on the cart
$cart->save();

Magento set "Show All" products by specific category (or in .phtml) rather than globally

I'm aware of the setting in the admin panel for the default number of products to show on the category list pages. This appears to be a global setting for the whole store. I'm looking for a way to set this on a per category basis (e.g. have most categories default to 25 products per page, but one specific category default to showing all products on the first page). Ideally this would be done in admin or in a .phtml file if possible. How can I set the default products per page for a specific category?
Take a look in
design/package/theme/catalog/product/list/toolbar.phtml
The items per page select drop down is generated by a for loop around:
$this->getAvailableLimit()
The block for the toolbar has the following method on it:
public function getLimitUrl($limit)
{
return $this->getPagerUrl(array(
$this->getLimitVarName() => $limit,
$this->getPageVarName() => null
));
}
The trick is to do one of the two following:
1) leverage magento to build the proper url when it is injected in any link directing to the category you want to be in view all mode.
2) on the /catalog/product/list/toolbar.phtml block check the current category, if the current category is the desired category execute the following code:
if( strtoupper($this->getLimitVarName()) != "ALL" )
{
$viewAllUrl = $this->getLimitUrl('All');
$this->_redirectUrl( $viewAllUrl );
}
At Admin Panel
Go to -> CMS -> Pages -> Home Page
Click on "Content" tab on LEFT
Click on "Show/Hide Editor" Button at RIGHT
Copy - Paste This Code there :
{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}
Give Category ID of your desired Category
To check Category_id of any category Go to : Catalog Menu -> Manage Catagories
Click on category, at right side's TITLE somewhat like will be displayed :
"CATEGORY_NAME ( ID : 5 )"
Regards.

Add additional product price with mangento base product price

I want to add additional price with product(simple) price, I am trying to do this with the help of custom attributes. I add a custom attribute "Margin Price" and I want to add up this custom attribute value (margin price) with the base price of the product in the template file.
I am updating all product price after each 5 minutes by cron job, thats why I think I have to do add margin price with base product price by this way.
I added it successfully in product list page and in product view page, but have problem with how to add this margin price with base price in the cart and onepage checkout?
Here is the code on the product list page and same for the product detail page which works fine for me in magento 1.6.x.
$regularPrice = number_format($_product->getFinalPrice(), 2);
//echo $regularPrice = $this->getPriceHtml($_product, true
$priceWithoutComma = str_replace(",", "",$regularPrice);
settype($priceWithoutComma, "float");
$marPrice = $_product->getMarginPrice();
settype($marPrice, "integer");
$finalPrice = $priceWithoutComma + $marPrice;
echo $finalPrice.Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol();
I am doing this right way or I have to changes the whole process?
Looks like you might need to consider a different approach. The reason being that echoing the price from a template file does not modify the price of the item in any way. It simply outputs a calculation.
You'll need to learn a bit about event listeners for this one to work.
Here's a blog post of mine on how to do this.

restricting items in cart and calculating

I'm currently trying to create a 'Sample' functionality on my Magento site.
The samples are free but when there more than 5 in the cart, then the total needs to be $10.
I can add the 'sample' products to the cart programatically that's no problem.
My main problem is:
Checking how many Sample products are in the cart (all have a value of $0)
If there are 5 or more, then the total needs to be $10+tax (or add this to the current total)
There cannot be more than 10 samples in the cart at one time(so no more than 10 $0 products)
Many thanks
To loop through the items in your cart you can loop through
foreach (Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems() as $item) {
if ($item->getPrice() == 0) {
//this item is a sample
}
}
To prevent things from adding to the cart you can overwrite the addProduct method in app/code/core/Mage/Checkout/Model/Cart.php to add your own custom logic to prevent products from being added to the cart when you don't want them. To make sure you are overriding correctly, you can learn more at http://alanstorm.com/magento_upgrade_rewrite_override

Resources