PHP,
pasted
on Mar 18:
|
public function addToCartEvent($observer)
{
$request = Mage::app()->getFrontController()->getRequest();
if (!$request->getParam('in_cart') && !$request->getParam('is_checkout'))
{
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
$quote = Mage::getSingleton('checkout/cart')->getQuote();
$grandTotal = $quote->getGrandTotal();
$subTotal = $quote->getSubtotal();
$session = Mage::getSingleton('checkout/session');
$shippingTaxamount = Mage::helper('checkout')->getQuote()->getShippingAddress()->getData('tax_amount');
// get coupon discounted value
$totals = $quote->getTotals(); //Total object
if (isset($totals['discount']) && $totals['discount']->getValue())
{
$discount = Mage::helper('core')->currency($totals['discount']->getValue()); //Discount value if applied
}
else
{
$discount = '';
}
//get discount value end
$post = Mage::app()->getRequest()->getParams();
$html = '';
$productser = '';
foreach ($session->getQuote()->getAllVisibleItems() as $item)
{
$oldPrice = $item->getPrice();
if($item->getHasChildren()) {
foreach($item->getChildren() as $child) {
$returnItems[] = $child;
$item = $child;
}
}
$item->setPrice($oldPrice);
$lastProduct = 0;
$productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
if ($post['product'] == $productOptions['info_buyRequest']['product']
&& count($post['super_attribute']) == count($productOptions['info_buyRequest']['super_attribute'])) {
$r = array_diff_assoc($post['super_attribute'], $productOptions['info_buyRequest']['super_attribute']);
if (empty($r)) {
$lastProduct = 1;
}
}
// print_r($productOptions);
if ($productOptions)
{
if (isset($productOptions['options']))
{
foreach ($productOptions['options'] as $_option)
{
$productser = $_option['option_id'] . ',' . $_option['option_value'];
}
}
$superAttrString = '';
if (isset($productOptions['info_buyRequest']['super_attribute']))
{
foreach ($productOptions['info_buyRequest']['super_attribute'] as $key => $_superAttr)
{
$attr = Mage::getModel('catalog/resource_eav_attribute')->load($key);
$label = $attr->getSource()->getOptionText($_superAttr);
$superAttrString .= '<dt> ' . $attr->getAttributeCode() . ': </dt> <dd> ' . $label . ' </dd>';
}
}
if ($superAttrString):
$superAttrString . '&qty=1';
endif;
}
$productid = $item->getId();
$html .='<li id="li-' . $productid . '">';
$product_id = $item->getProduct()->getId();
$productsku = $item->getSku();
$productname = $item->getName();
$productqty = $item->getQty();
$_product = Mage::getModel('catalog/product')->load($product_id);
$url = Mage::getUrl(
'checkout/cart/deleteqty', array(
'id' => $productid,
Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core/url')->getEncodedUrl()
)
);
$totalcount = Mage::helper('checkout/cart')->getSummaryCount();
$count = $quote->getItemsCount();
$htmlItem ='<div class="item-thumbnail"> ';
// echo Mage::helper('catalog/image')->init($item->getProduct(), 'small_image');
// var_dump($item->getProductId());
$product = Mage::getModel('catalog/product')->load($item->getProductId());
$imageURL = Mage::helper('catalog/image')->init($product, 'thumbnail');
if ($item->hasProductUrl()):
$htmlItem .='<a href="' . $item->getUrl() . '" title="' . $item->getName() . '" class="product-image"><img src="' . $imageURL . '" width="115" height="115" alt="' . $this->escapeHtml($item->getName()) . '" /></a>';
else:
$htmlItem .='<span><img src="' . $imageURL . '" width="115" height="115" alt="' . $item->getName() . '" /></span>';
endif;
$htmlItem .='</div>';
$htmlItem .='<div class="mini-basket-content-wrapper">
<div class="mini-cart-name">
<a class="item-name" href="' . $item->getUrl() . '">' . $productname . '</a>
<span class="item-price"><span class="price">$' . $item->getPrice() . '</span></span>
<div class="truncated_full_value">
<dl class="item-options">
<dd class="truncated">
<div class="truncated_full_value">
<dl class="item-options">
' . $superAttrString . '
</dl>
</div>
</dd>
</dl>
</div>';
$cart_items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
foreach($cart_items as $items) {
$qtyr = $items->getQty();
$htmlItem .= ' <div class="qty-btngroup">'
. '<input type="text" class="input-text qty" maxlength="12" title="Qty" size="4" value="'.$qtyr.'" name="" readonly="readonly">'
. ' </div>';
} // THIS GOES HERE
$htmlItem .=' <div class="product-cart-sku">SKU # :<span>' . $productsku . '</span></div>
</div>
</div>
<div class="clearfix"></div>';
$htmlItem .='</li>';
$html .= $htmlItem;
if ($lastProduct) {
$xhtml = $htmlItem;
}
}
$_response = Mage::getModel('ajaxminicart/response')
->setProductName($observer->getProduct()->getName())
->setCarttotal($grandTotal)
->setCartsubtotal($subTotal)
->setCartcount($count)
->setTotalcount($totalcount)
->setDiscount($discount)
->setShippingtaxamount($shippingTaxamount)
->setCartitem($html)
->setMessage($xhtml);
//append updated blocks
$_response->addUpdatedBlocks($_response);
$_response->send();
}
if ($request->getParam('is_checkout'))
{
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
$_response = Mage::getModel('ajaxminicart/response')
->setProductName($observer->getProduct()->getName())
->setMessage(Mage::helper('checkout')->__('%s was added into cart.', $observer->getProduct()->getName()));
$_response->send();
}
}
|
Output:
|
public function addToCartEvent($observer)
{
$request = Mage::app()->getFrontController()->getRequest();
if (!$request->getParam('in_cart') && !$request->getParam('is_checkout'))
{
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
$quote = Mage::getSingleton('checkout/cart')->getQuote();
$grandTotal = $quote->getGrandTotal();
$subTotal = $quote->getSubtotal();
$session = Mage::getSingleton('checkout/session');
$shippingTaxamount = Mage::helper('checkout')->getQuote()->getShippingAddress()->getData('tax_amount');
// get coupon discounted value
$totals = $quote->getTotals(); //Total object
if (isset($totals['discount']) && $totals['discount']->getValue())
{
$discount = Mage::helper('core')->currency($totals['discount']->getValue()); //Discount value if applied
}
else
{
$discount = '';
}
//get discount value end
$post = Mage::app()->getRequest()->getParams();
$html = '';
$productser = '';
foreach ($session->getQuote()->getAllVisibleItems() as $item)
{
$oldPrice = $item->getPrice();
if($item->getHasChildren()) {
foreach($item->getChildren() as $child) {
$returnItems[] = $child;
$item = $child;
}
}
$item->setPrice($oldPrice);
$lastProduct = 0;
$productOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
if ($post['product'] == $productOptions['info_buyRequest']['product']
&& count($post['super_attribute']) == count($productOptions['info_buyRequest']['super_attribute'])) {
$r = array_diff_assoc($post['super_attribute'], $productOptions['info_buyRequest']['super_attribute']);
if (empty($r)) {
$lastProduct = 1;
}
}
// print_r($productOptions);
if ($productOptions)
{
if (isset($productOptions['options']))
{
foreach ($productOptions['options'] as $_option)
{
$productser = $_option['option_id'] . ',' . $_option['option_value'];
}
}
$superAttrString = '';
if (isset($productOptions['info_buyRequest']['super_attribute']))
{
foreach ($productOptions['info_buyRequest']['super_attribute'] as $key => $_superAttr)
{
$attr = Mage::getModel('catalog/resource_eav_attribute')->load($key);
$label = $attr->getSource()->getOptionText($_superAttr);
$superAttrString .= '<dt> ' . $attr->getAttributeCode() . ': </dt> <dd> ' . $label . ' </dd>';
}
}
if ($superAttrString):
$superAttrString . '&qty=1';
endif;
}
$productid = $item->getId();
$html .='<li id="li-' . $productid . '">';
$product_id = $item->getProduct()->getId();
$productsku = $item->getSku();
$productname = $item->getName();
$productqty = $item->getQty();
$_product = Mage::getModel('catalog/product')->load($product_id);
$url = Mage::getUrl(
'checkout/cart/deleteqty', array(
'id' => $productid,
Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => Mage::helper('core/url')->getEncodedUrl()
)
);
$totalcount = Mage::helper('checkout/cart')->getSummaryCount();
$count = $quote->getItemsCount();
$htmlItem ='<div class="item-thumbnail"> ';
// echo Mage::helper('catalog/image')->init($item->getProduct(), 'small_image');
// var_dump($item->getProductId());
$product = Mage::getModel('catalog/product')->load($item->getProductId());
$imageURL = Mage::helper('catalog/image')->init($product, 'thumbnail');
if ($item->hasProductUrl()):
$htmlItem .='<a href="' . $item->getUrl() . '" title="' . $item->getName() . '" class="product-image"><img src="' . $imageURL . '" width="115" height="115" alt="' . $this->escapeHtml($item->getName()) . '" /></a>';
else:
$htmlItem .='<span><img src="' . $imageURL . '" width="115" height="115" alt="' . $item->getName() . '" /></span>';
endif;
$htmlItem .='</div>';
$htmlItem .='<div class="mini-basket-content-wrapper">
<div class="mini-cart-name">
<a class="item-name" href="' . $item->getUrl() . '">' . $productname . '</a>
<span class="item-price"><span class="price">$' . $item->getPrice() . '</span></span>
<div class="truncated_full_value">
<dl class="item-options">
<dd class="truncated">
<div class="truncated_full_value">
<dl class="item-options">
' . $superAttrString . '
</dl>
</div>
</dd>
</dl>
</div>';
$cart_items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
foreach($cart_items as $items) {
$qtyr = $items->getQty();
$htmlItem .= ' <div class="qty-btngroup">'
. '<input type="text" class="input-text qty" maxlength="12" title="Qty" size="4" value="'.$qtyr.'" name="" readonly="readonly">'
. ' </div>';
} // THIS GOES HERE
$htmlItem .=' <div class="product-cart-sku">SKU # :<span>' . $productsku . '</span></div>
</div>
</div>
<div class="clearfix"></div>';
$htmlItem .='</li>';
$html .= $htmlItem;
if ($lastProduct) {
$xhtml = $htmlItem;
}
}
$_response = Mage::getModel('ajaxminicart/response')
->setProductName($observer->getProduct()->getName())
->setCarttotal($grandTotal)
->setCartsubtotal($subTotal)
->setCartcount($count)
->setTotalcount($totalcount)
->setDiscount($discount)
->setShippingtaxamount($shippingTaxamount)
->setCartitem($html)
->setMessage($xhtml);
//append updated blocks
$_response->addUpdatedBlocks($_response);
$_response->send();
}
if ($request->getParam('is_checkout'))
{
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
$_response = Mage::getModel('ajaxminicart/response')
->setProductName($observer->getProduct()->getName())
->setMessage(Mage::helper('checkout')->__('%s was added into cart.', $observer->getProduct()->getName()));
$_response->send();
}
}
|
|