Skip to content

Instantly share code, notes, and snippets.

@AS87-code
Last active September 9, 2017 00:36
Show Gist options
  • Save AS87-code/9e01e275071d7797a842 to your computer and use it in GitHub Desktop.
Save AS87-code/9e01e275071d7797a842 to your computer and use it in GitHub Desktop.
Magento
<?php
if(!Mage::getSingleton('customer/session')->isLoggedIn()){
echo $this->__('Sign In');
}else{
echo $this->__('Hello, %s!', $this->helper('customer')->getCustomerName());
}
?>
<?php
$obj = new Mage_Catalog_Block_Navigation();
$storeCategories = $obj->getStoreCategories();
Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
foreach ($storeCategories as $_category):
?>
<li class="level0">
<a href="<?php echo $_category->getName().'.html'; ?>" class="level0"><?php echo $_category->getName(); ?></a>
<?php $categoryChildren = $_category->getChildren(); ?>
<?php if($categoryChildren->count()) : ?>
<div class="menu-block">
<div class="menu-title">
<ul class="level0">
<?php foreach($categoryChildren as $_categoryChild) : ?>
<?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId());?>
<?php $categoryGrandchildren=$_categoryChild->getChildren(); ?>
<li class="level1">
<?php echo '<a class="level0" href="' . $_categoryChildModel->getUrl() . '">' . $_categoryChild->getName() . '</a>'; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="menu-descr">
<?php
$_categoryThumbnail = Mage::getModel('catalog/category')->load($_category->getId())->getThumbnailUrl();
$media_url = Mage::getBaseUrl('media').'catalog/category/';
if ($_categoryThumbnail){}
else $_categoryThumbnail = 'default.jpg';
echo '<img src="' . $media_url . $_categoryThumbnail . '" /';
?>
</div>
</div>
<?php endif; ?>
</li>
<?php endforeach ?>
<?php
$html = '';
$staticBlock = $this->getLayout()->createBlock('cms/block')->setBlockId(16)->toHtml();
$collection = $collectionType = Mage::getModel('catalog/category')
->load(2)->getCollection()
->addAttributeToSelect('*')
->addAttributeToSort('position');
foreach ($collection as $col) {
if($col->getLevel()==2) {
$html .= '<li class="level0"><a class="level0 has-children" href="' . $col->getUrl() . '">' . $col->getName() . '</a></li>';
foreach ($collection as $col2) {
if ($col2->getLevel() == 3) {
$html .= '<div class="menu-block">';
$html .= '<div class="menu-title">';
$html .= '<ul class="level0">';
$html .= '<li class="level1"><a class="level1" href="' . $col->getUrl() . '">' . $col->getName() . '</a></li>';
$html .= '</ul>';
$html .= '</div>';
$html .= '<div class="menu-descr">' . $staticBlock . '</div>';
$html .= '</div>';
}
}
}
}
return $html;
/*****************
* MENU FOR GRID *
****************/
$html = '';
$collection1 = $collectionType = Mage::getModel('catalog/category')
->load(2)->getCollection()
->addAttributeToSelect('*')
->addAttributeToSort('position');
$html .= '<section class="isotope_grid">';
$html .= '<div class="grid_title"><span>New Products</span></div>';
$html .= '<div class="button-group filters-button-group">';
$html .= '<button class="button is-checked" data-filter="*">show all</button>';
foreach ($collection1 as $col) {
if($col->getLevel()==2) {
$html .= '<button class="button" data-filter="' . '.' . preg_replace('/&/', "", str_replace(" ", "", $col->getName())) . '">' . $col->getName() . '</button>';
}
}
$html .= '</div>';
echo $html;
/***********************
* GET IMG FOR CATEGORY *
***********************/
$_categoryThumbnail = Mage::getModel('catalog/category')->load($_category->getId())->getThumbnailUrl();
$media_url = Mage::getBaseUrl('media').'catalog/category/';
if ($_categoryThumbnail){}
else $_categoryThumbnail = 'default.jpg';
echo '<img src="' . $media_url . $_categoryThumbnail . '" />';
?>
<?php
$catid = '182';
$category = new Mage_Catalog_Model_Category();
$category->load($catid); // this is your special offers category id!
$collection = $category->getProductCollection();
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = 4;
$collection->setPage(1, $numProducts)->load();
foreach($collection as $product) :
$product = Mage::getModel('catalog/product')->load($product->getId()); /* Load Products by ID*/
echo '<br />';
echo $product->getName();
echo '<br />';
echo $product->getShortDescription();
endforeach;
?>
/*********************
* GET RATED PRODUCTS *
*********************/
$categoryId = Mage::getModel('catalog/category')->load($_categoryChild->getId());
$numDays = 30;
$productCount = 4;
$storeId = Mage::app()->getStore()->getId();
//$todayDate = Mage::getModel('core/date')->date('Y-m-d');
//$fromDate = date('Y-m-d', strtotime('now -'.$numDays.' days'));
$_bestSellersCollection = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->setStoreId($storeId)
->addAttributeToSelect('*')
->addCategoryFilter($categoryId)
//->addAttributeToFilter('created_at', array('date' => true, 'from' => $fromDate, 'to' => $todayDate))
->setOrder('ordered_qty', 'desc')
->setPageSize($productCount);
if ($_bestSellersCollection->getSize()>0) {
echo '<div class="nav_rated_product_wrap"><h2>most rated products for &laquo;' . $_categoryChild->getName() . '&raquo;</h2>';
foreach($_bestSellersCollection as $col) : $col = Mage::getModel('catalog/product')->load($col->getId());
$imageSrc = $this->helper('catalog/image')->init($col, 'small_image')->resize(150);
echo '<div class="nav_rated_product">';
echo '<a class="rated_link" href="' . $col->getProductUrl() . '"title="' . $this->stripTags($col->getName(), null, true) . '">';
echo '<img class="rated_img" src="' . $imageSrc. '" alt="' . $this->stripTags($col->getName(), null, true) . '" />';
echo '<h4>' . $col->getName(). '</h4>';
echo '</a></div';
endforeach;
echo '</div>';
}
if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div class="grid">
<?php $helper = Mage::helper('catalog/category');
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); // current date
foreach ($helper->getStoreCategories() as $_category):
$category_id = $_category->getId(); // if you know static category then enter number
$catagory_model = Mage::getModel('catalog/category')->load($category_id); // where $category_id is the id of the category
$collection = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($catagory_model)
->addAttributeToFilter('status', 1)
->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate)) // date from*
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))), 'left') // date to*
->addAttributeToSort('news_from_date', 'desc') // sort by 'desc'
->addAttributeToSelect(array('name', 'url', 'small_image')) // add product attribute to be fetched
//->getSelect()->order('rand()'); // uncomment to get products in random order
->addStoreFilter();
$numProducts = 5; // quantity of products
$collection->setPage(1, $numProducts)->load();
if (! empty($collection)) {
foreach ($collection as $product) : $product = Mage::getModel('catalog/product')->load($product->getId());
echo '<div class="element-item ' . preg_replace("/&/", "", str_replace(" ", "", $_category->getName())) . '" data-category="' . preg_replace("/&/", "", str_replace(" ", "", $_category->getName())) . '">';
echo '<a href="' . $product->getProductUrl() . '"title="' . $this->stripTags($product->getName(), null, true) . '" class="product-image">';
echo '<img src="' . $this->helper('catalog/image')->init($product, 'small_image')->resize(210) . '" alt="' . $this->stripTags($product->getName(), null, true) . '" />';
echo '</a><div class="product-info">';
echo '<h3 class="product-name"><a href="' . $product->getProductUrl() . '" title="' . $this->stripTags($product->getName(), null, true) . '">' . $this->helper('catalog/output')->productAttribute($product, $product->getName(), 'name') . '</a></h3>';
echo $this->getPriceHtml($product, true, '-widget-new-grid');
echo '</div></div>';
endforeach;
} else {
echo 'No products exists';
}
endforeach; ?>
</div>
<?php endif; ?>
// in phtml
$staticBlock = $this->getLayout()->createBlock('cms/block')->setBlockId(16)->toHtml();
// in cms
{{block type="cms/block" block_id="baner_block"}}
// in xml
<block type="cms/block" name="Имя_статичного_блока">
<action method="setBlockId"><block_id>ID_статичного_блока</block_id></action>
</block>
app > code > core > Mage > Catalog > Model > Category.php
str -> 480
/**
* Retrieve thumbnail image URL
*
* @return string
*/
public function getThumbnailUrl($fullpath = false)
{
$url = false;
if ($image = $this->getThumbnail()) {
if ($fullpath == true) {
$url = Mage::getBaseUrl('media').'catalog/category/'.$image;
} else {
$url = $image;
}
}
return $url;
}
Вызов:
$_categoryThumbnail = Mage::getModel('catalog/category')->load($_category->getId())->getThumbnailUrl();
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
chown -R user:group .
checkout/cart/minicart.phtml
<span class="count">
<?php echo Mage::helper('checkout')->formatPrice(Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal()) ?>
</span>
***
Пример, как получить общую сумму товаров в корзине (cart) CMS Magento (Мадженто).
Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal();
Пример, как получить отформатированную сумму товаров в корзине Magento, со знаком валюты.
Mage::helper('checkout')->formatPrice(Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment