Display Tier Price on Cart page in Magento - magento

How can I display tier price on cart page in Magento?
I understand that the method getTierPriceHtml() only works on List and Detail page, so we cannot use that on cart page.
I'm editing /template/checkout/cart/item/default.phtml

you want tier price in cart page also.I think this is useful for your functionality
you can directly use this code in checkout/cart/item/default.phtml: after the $_item = $this->getItem(); (in line 28)....
**$tierPrice = $this->getLayout()->createBlock(
'catalog/product_view',
'product.tierprices',
array(
'product_id' => $_item->getProductId()
)
);**
**$tierPrice->setTemplate('catalog/product/view/tierprices.phtml');**
**echo $tierPrice->getTierPriceHtml();**
you can create your own style template that file also you can use it in place of catalog/product/view/tierprice.phml like catalog/product/view/tierprice1.phml

Related

How to load category on catalog_category_view page based on the collection returned from ProductRepository::getList()

Is there any short customization that can be done to make catalog_category_view page load products based on some product attributes such as special_price, cost, and special_date_from without specifying any specific category Id. Reason is - I don't want people to go back and start assigning products to specific categories just to be able to load it in catalog_category_view page.
It appears catalog/category/view page is hardwired to load product based on category Id
In the block page responsible for load the products you can add an method .
In that class you inject:
use \Magento\Reports\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
On your constructor:
$this->_productsFactory = $productsFactory;
And in mehod:
$collection = $this->_productsFactory->create()->addAttributeToSelect(
'*'
)->addAttributeToFilter('product_brandname', array('neq' => ''))
->addAttributeToFilter('price', array(
array('gt' => 0.01, 'lt' => 99999999),
)
);

magento same product with many quantity different size change one time

I have a little experience in magento. All my products have custom size in option.
All products have different sizes and different prices.
Customer adds one product with quantity 5 to cart. So 5 products of this size are added to cart. When the customer adds another product with different size all products in cart change to this size.
How can i prevent this behavior?
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: Random "Featured Product"

My client needs a a small box on CMS pages and on Category landing pages that will show thumbnail/price/short description of a random item related to that category (separate from the grid view)
Any thoughts on what would be the best way to accomplish this?
Thanks,
-Sam
go to template/catalog/product/view/ and make a new phtml file random_product.phtml with the following code
<?php
$catId = $this->getCat_id();
$cat=Mage::getModel("catalog/category")->load($catId);
$prodCollection = $cat->getProductCollection();
$pids=array();
foreach($prodCollection as $product)
{
array_push($pids,$product->getId());
}
$randProductId=array_rand($pids);
echo $randProductId;
?>
now if your category id is for example 10, make a static block and paste the following code in the contents
{{block type="catalog/product" cat_id="10" template="catalog/product/view/random_product.phtml"}}
now when you will view the static block, you will see a random product id every time you refresh.
THen,you can write your own custom html in the phtml file after loading the product.
To load your product from here you can do $product = Mage::getModel('catalog/product')->load($randProductId); then call methods such as $product->getName() etc to get the details you need to output.

Magento - No price in product page

I have SCP (simple configurable product) installed and for every simple product that has no custom options, the price doesn’t show up in the product page. As soon as I add an option, the price shows up.
There is no price block or template called on the product page when no options is selected.
I saw that the extension is extending Mage_Catalog_Block_Product_Price block , but I can't find where this block should be called.
Haven't found any solution yet , so I made this jquery workaround that works
Put this at the end of template/catalog/product/view.phtml
jQuery(document).ready(function($) {
if($('.price-box').length==0){
var price = '<div class="price-box"><span class="regular-price"><span class="price">$<?php echo number_format($_product->getPrice(),2); ?></span></span></div>';
$('.product-options-bottom').before(price);
}
});
Of course, you need to have jquery.

Magento Auto Add Items Based on Quantity

I'm designing a custom product page with a button that when clicked I need to have an alert come up with a "Yes" or "No" option.
If "Yes" is selected I then need the following to happen.
Add another product into the cart based on the products quantity i.e. between 1 & 2 items add product A between 3 & 4 Items product B, between 5 & 12 product C and so on.
Any idea of the best way to accomplish this?
It has to be a alert style popup (ajax popup preferred) cannot be a checkbox on the product page.
Thanks!
So I've come across a solution to my problem... I'm using a Simple Modal (That TheBlackBenzKid hinted me to) that I'm either going to call from a custom button or with the add to cart button. This in turn will redirect to a php page that will redirect to the cart. For the php page I'll just include the code to put a item into the cart from there anyone could figure out how to customize it to there own needs.
<?php
// Include Magento application (URL to Mage.php)
require_once ( "app/Mage.php" );
umask(0);
//specified quantity my own variable I'm using for quantities
$spqty = 9;
// Initialize Magento
Mage::app("default");
// You have two options here,
// "frontend" for frontend session or "adminhtml" for admin session
Mage::getSingleton("core/session", array("name" => "frontend"));
$session = Mage::getSingleton("customer/session");
// get the current Magento cart
$cart = Mage::getSingleton('checkout/cart');
if ($spqty <= 2) {
// insert item to cart where "98" is the product ID (NOT SKU!) Where "2" is the quantity
$cart->addProduct(98, array('qty' => 2));
} elseif ($spqty >= 4 ){
// you can add multiple products at the same time by adding this line multiple times
$cart->addProduct(96, array('qty' => 3));
}
// save the cart
$cart->save();
// very straightforward, set the cart as updated
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
// redirect to index.php
header("Location: index.php/checkout/cart");
I also found some of this information from this guys blog I'll link to the article
How to add a product from an external site into Magento
I'm happy to answer any questions on this...
This is not the best answer, but code to get you started:
You could make the cart function use:
<input type="button" onClick="javascript:nValidateForm();"/>
And your form code:
<form name="m2mform" id="m2mform" method="post" onSubmit="javascript:nValidateForm();">
And then just call an external JavaScript in your page XML headers and add it to cart so that JS file will always be checked and validate the popup.

Resources