Skip to content

Instantly share code, notes, and snippets.

@mokanfar
Last active November 27, 2018 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokanfar/3140a6218920f64d69ee6ed69ae75a01 to your computer and use it in GitHub Desktop.
Save mokanfar/3140a6218920f64d69ee6ed69ae75a01 to your computer and use it in GitHub Desktop.
Magento Snippets #2
magento product phtml data sku attribute get data
<?php echo $_product->getProductUrl() ?>
<?php echo $_product->getId() ?>
<?php echo $_product->getSku() ?>
###Customer ID Final Price Customer Group
<?php
require_once 'app/Mage.php';
Mage::app();
//to overwrite limit but you need first to increase your memory limit
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') // select all attributes
->setPageSize(5000) // limit number of results returned
->setCurPage(1); // set the offset (useful for pagination)
// we iterate through the list of products to get attribute values
foreach ($collection as $product) {
$product->setCustomerGroupId(1);
echo $product->getSku();
echo '&#9;';
echo (float) $product->getFinalPrice(); //get price as cast to float
echo '<br />';
}
?>
<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(220); ?>
<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
<?php echo $_product->getData('child_skus'); ?>
<?php if($product->getAttributeText('product_category_type') == 'Dining Chair'): ?>
<?php product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku); ?>
<?php product = Mage::getModel('catalog/product')->load($entity_id); ?>
<?php if():?>
<?php else: ?>
<?php endif;?>
magento child block phtml
<?php $this->getChild('stock_info')->setData("product", $_product); ?>
<?php echo $this->getChildHtml('stock_info', false) ?>
<?php echo $this->getChildHtml('child_view') ?>
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSort('model', 'ASC')
->addAttributeToSelect('*')
->addAttributeToFilter('product_category_type', array('nin' => array(92,19,81,14)))
->joinField('is_in_stock',
'cataloginventory/stock_item',
'is_in_stock',
'product_id=entity_id',
'is_in_stock=0',
'{{table}}.stock_id=1',
'left')
->load();
magento cms url skin base media
{{skin url='images/sampleimage.jpg'}}
{{media url='/sampleimage.jpg'}}
{{store url='mypage.html'}}
magento phtml skin url base url current url
<?php $current_url = Mage::helper('core/url')->getCurrentUrl();?>
<?php echo $this->getSkinUrl('images/sampleimage.jpg') ?>
<?php echo $this->getSkinUrl('images/ sampleimage.gif',array('_secure'=>true)) ?>
magento customer logged in get customer id
<?php $loggedIn = $this->helper("customer")->isLoggedIn();?>
<?php
$customer = Mage::getSingleton('customer/session');
$customerData = Mage::getSingleton('customer/session')->getCustomer()->getGroupId();
?>
<?php if(!$customer->isLoggedIn()): ?>
<?php if ($customerData == '6'): ?>
magento stock info qty get is in stock
<?php $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product); echo 'Qty: ' . round($stock->getQty()); ?>
<?php if($_product->isSaleable()): ?>
magento translate echo
<?php echo $this->__('Quick Overview') ?>
magento load product by sku entity id phtml
<?php product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku); ?>
<?php product = Mage::getModel('catalog/product')->load($entity_id); ?>
change sku
<?php
//no headers in csv file
//old sku c1 new sku c2
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 'Off');
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
set_time_limit(0);
ini_set('memory_limit','1024M');
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$updates_file="./sku2sku.csv";
$sku_entry=array();
$updates_handle=fopen($updates_file, 'r');
if($updates_handle) {
while($sku_entry=fgetcsv($updates_handle, 1000, ",")) {
$old_sku=$sku_entry[0];
$new_sku=$sku_entry[1];
echo "<br>Updating ".$old_sku." to ".$new_sku." - ";
try {
$get_item = Mage::getModel('catalog/product')->loadByAttribute('sku', $old_sku);
if ($get_item) {
$product_id = $get_item->getId();
$writeConnection->update(
"catalog_product_entity",
array("sku" => $new_sku),
"entity_id=$product_id"
);
echo "successful";
} else {
echo "item not found";
}
} catch (Exception $e) {
echo "Cannot retrieve products from Magento: ".$e->getMessage()."<br>";
return;
}
}
}
fclose($updates_handle);
?>
<!-- magento xml snippet -->
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<action method="addItem"><type>js_css</type><stylesheet>fontawesome/css/font-awesome.min.css</stylesheet><params>media="all"</params></action>
<action method="addItem"><type>skin_js</type><name>js/jquery.easytabs.min.js</name></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addCss"><stylesheet>css/styles.css</stylesheet></action>
<action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action>
</reference>
</default>
<!-- magento xml view.phtml modify -->
<catalog_product_view translate="label">
<reference name="head">
<action method="addItem"><type>skin_js</type><name>js/jquery.easytabs.min.js</name></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
<reference name="product.info">
<block type="catalog/product_view" name="child_view" template="catalog/product/child_view.phtml"/>
</reference>
<reference name="product.info.additional">
<remove name="product_tag_list"/>
<remove name="product_tag_list"/>
</reference>
</catalog_product_view>
<!-- Magento xml category layered list.phtml modify-->
<catalog_category_layered>
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
<reference name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list" name="stock_info" template="catalog/product/stock_view.phtml"/>
</reference>
</catalog_category_layered>
<!-- magento xml head css js add -->
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<action method="addItem"><type>js_css</type><stylesheet>fontawesome/css/font-awesome.min.css</stylesheet><params>media="all"</params></action>
<action method="addItem"><type>skin_js</type><name>js/jquery.easytabs.min.js</name></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addCss"><stylesheet>css/styles.css</stylesheet></action>
<action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action>
</reference>
</default>
</layout>
<!-- magento xml special block inside product list.phtml -->
<catalog_category_default>
<reference name="product_list">
<block type="catalog/product_list" name="stock_info" template="catalog/product/stock_view.phtml"/>
</reference>
</catalog_category_default>
<checkout_onepage_index translate="label">
<reference name="content">
<block type="core/text" name="checkout.initiated" before="-">
<action method="setText">
<text><![CDATA[
<script>
fbq('track', 'InitiateCheckout');
</script>
]]></text>
</action>
</block>
</reference>
</checkout_onepage_index>
<checkout_onepage_success>
<reference name="before_body_end">
<block name="order_tracking" template="checkout/tracking.phtml" type="core/template" />
</reference>
</checkout_onepage_success>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment