Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB,array('_secure'=>Mage::app()->getStore()->isCurrentlySecure()));
if (Mage::app()->getStore()->isFrontUrlSecure()) {
echo 'Secure URL is enabled in Frontend';
} else {
echo 'Secure URL is disabled in Frontend';
}
if (Mage::app()->getStore()->isAdminUrlSecure()) {
echo 'Secure URL is enabled in Admin';
} else {
echo 'Secure URL is disabled in Admin';
}
if (Mage::app()->getStore()->isCurrentlySecure()) {
echo 'Current URL is Secure';
} else {
echo 'Current URL is NOT Secure';
}
if (Mage::app()->getStore()->isAdmin()) {
echo 'You are in Admin page';
} else {
echo 'You are in Frontend page';
}
Mage::getSingleton('core/session', array('name' => 'frontend'));
$_quote = Mage::getSingleton('checkout/session')->getQuote();
$cart = Mage::helper('checkout/cart')->getCart()->getQuote()->getAllItems();
// /* cart item loop */
foreach($cart as $item) {
/* This will get custom option value of cart item */
$_customOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
/* Each custom option loop */
foreach($_customOptions['options'] as $_option){
echo $_option['label'] .'=>'. $_option['value']."<br/>";
// Do your further logic here
}
}
$indexingProcesses = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($indexingProcesses as $process) {
try {
$startTime = microtime(true);
$process->reindexEverything();
$resultTime = microtime(true) - $startTime;
Mage::dispatchEvent($process->getIndexerCode() . '_shell_reindex_after');
echo $process->getIndexer()->getName()
. " index was rebuilt successfully in " . gmdate('H:i:s', $resultTime) . "\n";
} catch (Mage_Core_Exception $e) {
echo $e->getMessage() . "\n";
} catch (Exception $e) {
echo $process->getIndexer()->getName() . " index process unknown error:\n";
echo $e . "\n";
}
}
$tableName = Mage::getSingleton('core/resource')->getTableName('catalog_product_option');
if (Mage::app()->getLocale()->isStoreDateInInterval($store, $specialPriceFrom, $specialPriceTo)) {
}
- Get Base Url :
Mage::getBaseUrl();
- Get Skin Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
(a) Unsecure Skin Url :
$this->getSkinUrl('images/imagename.jpg');
(b) Secure Skin Url :
$this->getSkinUrl('images/imagename.gif', array('_secure'=>true));
- Get Media Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
- Get Js Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
- Get Store Url :
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
- Get Current Url
Mage::helper('core/url')->getCurrentUrl();
- Get Base Url :
{{store url=""}}
- Get Skin Url :
{{skin url='images/imagename.jpg'}}
- Get Media Url :
{{media url='/imagename.jpg'}}
- Get Store Url :
{{store url='mypage.html'}}
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
// Run you code here
?>
<?php
// get all parameters
$allParams = Mage::app()->getRequest()->getParams();
// $_GET
$productId = Mage::app()->getRequest()->getParam('product_id');
// The second parameter to getParam allows you to set a default value which is returned if the GET value isn't set
$productId = Mage::app()->getRequest()->getParam('product_id', 44);
$postData = Mage::app()->getRequest()->getPost();
// You can access individual variables like...
$productId = $postData['product_id']);
?>
<?php
### Notice ###
Mage::getSingleton('core/session')->addNotice('Notice message');
### Success ###
Mage::getSingleton('core/session')->addSuccess('Success message');
### Error ###
Mage::getSingleton('core/session')->addError('Error message');
### Warning (admin only) ###
Mage::getSingleton('adminhtml/session')->addWarning('Warning message');
?>
<?php
Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
?>
<?php
$_price = '15.806666666667';
$formattedPrice = Mage::helper('core')->currency($_price, true, true); // <span class="price">€15.81</span>
$formattedPrice = Mage::helper('core')->currency($_price, true, false); // €15.81
$formattedPrice = Mage::helper('core')->currency($_price, false, false); // 15.806666666667
$formattedPrice = Mage::getModel('directory/currency')->format($_price,array('display'=>Zend_Currency::NO_SYMBOL), false); // 15.81
?>
<?php
Mage::app()->getStore()->getCurrentCurrencyCode();
?>
<?php
$from = 'USD';
$to = 'NPR';
$price = 10;
$newPrice = Mage::helper('directory')->currencyConvert($price, $from, $to);
?>
<?php
$visitorData = Mage::getSingleton('core/session')->getVisitorData();
print_r($visitorData);
?>
<?php
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$price = 100;
// convert price from current currency to base currency
$priceOne = Mage::helper('directory')->currencyConvert($price, $currentCurrencyCode, $baseCurrencyCode);
// convert price from base currency to current currency
$priceTwo = Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $currentCurrencyCode);
?>
set custom session in frontend
// To Set the Session
Mage::getSingleton('core/session')->setMySessionVariable('MyValue');
// To Get the Session
$myValue = Mage::getSingleton('core/session')->getMySessionVariable();
echo $myValue;
// To Unset the session
Mage::getSingleton('core/session')->unsMySessionVariable();
How to Use customer or core session in frontend. Use adminhtml session in the backend.
Core Session :- Mage::getSingleton('core/session');
Customer Session :- Mage::getSingleton('customer/session');
Admin Session :- Mage::getSingleton('adminhtml/session');
Shopping Cart Session :-Mage::getSingleton('checkout/session')->getQuote();
$_products = Mage::getModel('catalog/product')->getCollection();
For EAV Tables
## Equals: eq ##
$_products->addAttributeToFilter('status', array('eq' => 1));
## Not Equals - neq ##
$_products->addAttributeToFilter('sku', array('neq' => 'test-product'));
## Like - like ##
$_products->addAttributeToFilter('sku', array('like' => 'UX%'));
One thing to note about like is that you can include SQL wildcard characters such as the percent sign.
## Not Like - nlike ##
$_products->addAttributeToFilter('sku', array('nlike' => 'err-prod%'));
## In - in ##
$_products->addAttributeToFilter('id', array('in' => array(1,4,98)));
When using in, the value parameter accepts an array of values.
## Not In - nin ##
$_products->addAttributeToFilter('id', array('nin' => array(1,4,98)));
## NULL - null ##
$_products->addAttributeToFilter('description', 'null');
## Not NULL - notnull ##
$_products->addAttributeToFilter('description', 'notnull');
## Greater Than - gt ##
$_products->addAttributeToFilter('id', array('gt' => 5));
## Less Than - lt ##
$_products->addAttributeToFilter('id', array('lt' => 5));
## Greater Than or Equals To- gteq ##
$_products->addAttributeToFilter('id', array('gteq' => 5));
## Less Than or Equals To - lteq ##
$_products->addAttributeToFilter('id', array('lteq' => 5));
For Single Tables
//for AND
$collection = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('my_field1', 'my_value1')
->addFieldToFilter('my_field2', 'my_value2');
echo $collection->getSelect()->__toString();
//for OR - please note 'attribute' is the key name and must remain the same, only replace //the value (my_field1, my_field2) with your attribute name
$collection = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter(
array(
array('attribute'=>'my_field1','eq'=>'my_value1'),
array('attribute'=>'my_field2', 'eq'=>'my_value2')
)
);
$website_id = Mage::app()->getWebsite()->getId();
$website_name = Mage::app()->getWebsite()->getName();
$store_id = Mage::app()->getStore()->getId();
$store_name = Mage::app()->getStore()->getName();
$store_code = Mage::app()->getStore()->getCode()";
Mage::getStoreConfig('myappgeneral/current_time/second', $store_id)
<?php
// clear cache
Mage::app()->removeCache('catalog_rules_dirty');
// reindex prices
Mage::getModel('index/process')->load(2)->reindexEverything();
/*
1 = Product Attributes
2 = Product Attributes
3 = Catalog URL Rewrites
4 = Product Flat Data
5 = Category Flat Data
6 = Category Products
7 = Catalog Search Index
8 = Tag Aggregation Data
9 = Stock Status
*/
?>
if($this->getIsHomePage())
{
// Home page
}
if (Mage::registry('current_category'))
{
// category page
}
if (Mage::registry('current_category'))
{
// Category Name
echo Mage::registry('current_category')->getName();
// Category ID
echo Mage::registry('current_category')->getId();
}
if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
{
// CMS page
}
if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')
{
echo Mage::getSingleton('cms/page')->getIdentifier();
}
if(Mage::app()->getFrontController()->getRequest()->getRequestedActionName() == 'configure')
{
// Product Configuration page
}
$request = $this->getRequest();
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if($module == 'checkout' && $controller == 'cart' && $action == 'index')
{
//Cart Page
}
{{ block type="core/template" name="mycstompage" template="SkyMagento/mycustompage.phtml" }}
{{block type="cms/block" block_id="your_block_id"}}
<?php echo $this->getLayout()
->createBlock('cms/block')
->setBlockId('your_block_id')->toHtml(); ?>
<default>
<cms_page> <!-- need to be redefined for your needs -->
<reference name="content">
<block type="cms/block" name="cms_newest_product" as="cms_newest_product">
<action method="setBlockId"><block_id>newest_product</block_id></action>
</block>
</reference>
</cms_page>
</default>
In your phtml template call file as mention:
echo $this->getChildHtml('newest_product');
<?php
echo $this->getLayout()->createBlock('core/template')->setTemplate('goodtest/test.phtml')->toHtml();
?>
go to design and change the layout what you want
to add left column in cms page just add belw code in layout
<reference name="left">
<block type="cms/block" name="sample_block" before="-">
<action method="setBlockId"><block_id>sample_block</block_id></action>
</block>
</reference>
to add right column in cms page just add belw code in layout
<reference name="right">
<block type="cms/block" name="sample_block" before="-">
<action method="setBlockId"><block_id>sample_block</block_id></action>
</block>
</reference>
{{block type="catalog/product_list" name="product_list" category_id="3" column_count="6" count="6"
limit="4" mode="grid" template="catalog/product/list.phtml"}}
First, use get_class to get the name of an object's class.
<?php $class_name = get_class($object); ?>
Then, pass that get_class_methods to get a list of all the callable methods on an object
<?php
$class_name = get_class($object);
$methods = get_class_methods($class_name);
foreach($methods as $method)
{
var_dump($method);
}
?>
Mage::log('Your Log Message', Zend_Log::INFO, 'your_log_file.log');
<?php
$collection = Mage::getModel('modulename/modelname')->getCollection();
echo $collection->printLogQuery(true);
echo $collection->getSelect();
?>
<?php Zend_Debug::dump($thing_to_debug, 'debug'); ?>
try {
// code to run
} catch (Exception $e) {
var_dump($e->getMessage());
}
$_customer = Mage::getSingleton('customer/session')->isLoggedIn();
if ($_customer) {}
<?php
$customerAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping();
if ($customerAddressId){
$address = Mage::getModel('customer/address')->load($customerAddressId);
}
?>
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->getPrefix();
$customer->getName(); // Full Name
$customer->getFirstname(); // First Name
$customer->getMiddlename(); // Middle Name
$customer->getLastname(); // Last Name
$customer->getSuffix();
// All other customer data
$customer->getWebsiteId(); // ID
$customer->getEntityId(); // ID
$customer->getEntityTypeId(); // ID
$customer->getAttributeSetId(); // ID
$customer->getEmail();
$customer->getGroupId(); // ID
$customer->getStoreId(); // ID
$customer->getCreatedAt(); // yyyy-mm-ddThh:mm:ss+01:00
$customer->getUpdatedAt(); // yyyy-mm-dd hh:mm:ss
$customer->getIsActive(); // 1
$customer->getDisableAutoGroupChange();
$customer->getTaxvat();
$customer->getPasswordHash();
$customer->getCreatedIn(); // Admin
$customer->getGender(); // ID
$customer->getDefaultBilling(); // ID
$customer->getDefaultShipping(); // ID
$customer->getDob(); // yyyy-mm-dd hh:mm:ss
$customer->getTaxClassId(); // ID
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer_id = $customer->getId();
$customer_email = $customer->getEmail();
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer ->setWebsiteId($websiteId)
->setStore($store)
->setFirstname('John')
->setLastname('Doe')
->setEmail('[email protected]')
->setPassword('somepassword');
try{
$customer->save();
}
catch (Exception $e) {
Zend_Debug::dump($e->getMessage());
}
<?php
$_product_1 = Mage::getModel('catalog/product')->load(12);
$_product_2 = Mage::getModel('catalog/product')->loadByAttribute('sku','cordoba-classic-6-String-guitar');
?>
<?php
$currentCategory = Mage::registry('current_category');
$currentProduct = Mage::registry('current_product');
$currentCmsPage = Mage::registry('cms_page');
?>
<?php if($_product->isSaleable()) { // do stuff } ?>
<?php
$_product = Mage::getModel('catalog/product')->load(4);
echo $_product->getProductUrl();
?>
<?php
$_product = Mage::getModel('catalog/product')->load(4);
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
echo $stock->getQty();
echo $stock->getMinQty();
echo $stock->getMinSaleQty();
?>
<?php
/**
* Load Product you want to get Super attributes of
*/
$product=Mage::getModel("catalog/product")->load(52520);
/**
* Get Configurable Type Product Instace and get Configurable attributes collection
*/
$configurableAttributeCollection=$product->getTypeInstance()->getConfigurableAttributes();
/**
* Use the collection to get the desired values of attribute
*/
foreach($configurableAttributeCollection as $attribute){
echo "Attr-Code:".$attribute->getProductAttribute()->getAttributeCode()."<br/>";
echo "Attr-Label:".$attribute->getProductAttribute()->getFrontend()->getLabel()."<br/>";
echo "Attr-Id:".$attribute->getProductAttribute()->getId()."<br/>";
var_dump($_attribute->debug()); // returns the set of values you can use the get magic method on
}
?>
<?php
$_category = Mage::getModel('catalog/category')->load(47);
$_productCollection = $_category->getProductCollection();
if($_productCollection->count()) {
foreach( $_productCollection as $_product ):
echo $_product->getProductUrl();
echo $this->getPriceHtml($_product, true);
echo $this->htmlEscape($_product->getName());
endforeach;
}
?>
<?php
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country">
<option value="">-- Please Select --</option>
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>">
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>
<?php
$_product = Mage::getModel('catalog/product')->load(4);
// input is $_product and result is iterating child products
$this->helper('catalog/image')->init($_product, 'image');
?>
<?php
$_productId = 52;
$_product = Mage::getModel('catalog/product')->load($_productId);
// without currency sign
$_actualPrice = number_format($_product->getPrice(), 2);
// with currency sign
$_formattedActualPrice = Mage::helper('core')->currency(number_format($_product->getPrice(), 2),true,false);
// without currency sign
$_specialPrice = $_product->getFinalPrice();
// with currency sign
$_formattedSpecialPrice = Mage::helper('core')->currency(number_format($_product->getFinalPrice(), 2),true,false);
?>
<?php
$this->helper('catalog/image')
->init($_product, 'image')
->keepFrame(false) // avoids getting the small image in original size on a solid background color presented (can be handy not to break some layouts)
->constrainOnly(true) // avoids getting small images bigger
->resize(650); // sets the desired width and the height accordingly (proportional by default)
?>
<catalog_product_view>
<reference name="product.info.container1" after="-">
<action method="setTemplate">
<template>pincode/index.phtml</template>
</action>
<block type="catalog/product_view" name="original_addtocart"
as="original_addtocart" template="pincode/index.phtml"/>
</reference>
</catalog_product_view>
<?php
// input is $_product and result is iterating child products
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product);
?>
<?php
$_product->getThisattribute();
$_product->getAttributeText('thisattribute');
$_product->getResource()->getAttribute('thisattribute')->getFrontend()->getValue($_product);
$_product->getData('thisattribute');
// The following returns the option IDs for an attribute that is a multiple-select field:
$_product->getData('color'); // i.e. 456,499
// The following returns the attribute object, and instance of Mage_Catalog_Model_Resource_Eav_Attribute:
$_product->getResource()->getAttribute('color'); // instance of Mage_Catalog_Model_Resource_Eav_Attribute
// The following returns an array of the text values for the attribute:
$_product->getAttributeText('color') // Array([0]=>'red', [1]=>'green')
// The following returns the text for the attribute
if ($attr = $_product->getResource()->getAttribute('color')):
echo $attr->getFrontend()->getValue($_product); // will display: red, green
endif;
?>
<?php
// pass the sku of the child product
public function getParentproduct(int $sku){
$product = Mage::getModel('catalog/product');
$productobject = $product->load($product->getIdBySku($sku));
$ProductId = $product->getIdBySku($sku);
$helperdata = Mage::helper("modulename/data");
if($productobject->getTypeId() == 'simple'){
//product_type_grouped
$parentIds = Mage::getModel('catalog/product_type_grouped')
->getParentIdsByChild($productobject->getId());
//product_type_configurable
if(!$parentIds){
$parentIds = Mage::getModel('catalog/product_type_configurable')
->getParentIdsByChild($productobject->getId());
}
//product_type_bundle
if(!$parentIds){
$parentIds = Mage::getModel('bundle/product_type')
->getParentIdsByChild($productobject->getId());
}
}
return $parentIds;
}
?>
<?php
$_category = Mage::getModel('catalog/category')->load(89);
$_category_url = $_category->getUrl();
?>
<?php
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$_category = Mage::getModel('catalog/category')->load($rootCategoryId);
// You can then get all of the top level categories using:
$_subcategories = $_category->getChildrenCategories();
?>
<?php
$category = Mage::getModel('catalog/category')->load(4);
echo $category->getUrl();
?>
Make sure the block that you’re working is of the type catalog/navigation. If you’re editing catalog/navigation/left.phtml then you should be okay.
<div id="leftnav">
<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<?php if (count($categories) > 0): ?>
<ul id="leftnav-tree" class="level0">
<?php foreach($categories as $category): ?>
<li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>">
<a href="<?php echo $helper->getCategoryUrl($category) ?>"><span><?php echo $this->escapeHtml($category->getName()) ?></span></a>
<?php if ($this->isCategoryActive($category)): ?>
<?php $subcategories = $category->getChildren() ?>
<?php if (count($subcategories) > 0): ?>
<ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1">
<?php foreach($subcategories as $subcategory): ?>
<li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>">
<a href="<?php echo $helper->getCategoryUrl($subcategory) ?>"><?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?></a>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script>
<?php endif; ?>
</div>
## Get Sales Quote in Frontend ##
Mage::getSingleton('checkout/session')->getQuote();
## Get Sales Quote in Admin ##
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
## Get Latest Order in Frontend ##
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
## Get Latest Order in Admin ##
$order = Mage::getModel('sales/order')->getCollection()
->setOrder('created_at','DESC')
->setPageSize(1)
->setCurPage(1)
->getFirstItem();
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllItems();
foreach($items as $item) {
echo 'ID: '.$item->getProductId().'<br />';
echo 'Name: '.$item->getName().'<br />';
echo 'Sku: '.$item->getSku().'<br />';
echo 'Quantity: '.$item->getQty().'<br />';
echo 'Price: '.$item->getPrice().'<br />';
echo "<br />";
}
$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount();
$firstItem = $collection->getFirstItem(); Mage::log($firstItem->getData());
$lastItem = $collection->getLastItem(); Mage::log($lastItem->getData());
<?php
Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
Mage::getSingleton('checkout/session')->getQuote()->getItemsCount();
?>
<?php
Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
Mage::getSingleton('checkout/session')->getQuote()->getItemsQty();
?>
<?php
Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
?>
<?php
Mage::helper('checkout')->formatPrice(Mage::getModel('checkout/cart')->getQuote()->getGrandTotal());
Mage::helper('checkout')->formatPrice(Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal());
?>
<?php
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllItems();
foreach ($items as $item) {
$priceInclVat += $item->getRowTotalInclTax();
}
Mage::helper('checkout')->formatPrice($priceInclVat);
?>
<?php
$totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();
?>
To load by Order id you would just call load:
$order = Mage::getModel('sales/order')->load(24999); //use an entity id here
To load an order by increment id one would do:
$order = Mage::getModel('sales/order')->loadByIncrementId('10000001'); //use a real increment order
To load by Order id you would just call load:
echo '<pre>';
$order = Mage::getModel('sales/order')->load(24999); //use an entity id here
$orderData = $order->getData();
print_r($orderData);
<?php
$order_id = 2314; //use your own order id
$order = Mage::getModel("sales/order")->load($order_id); //load order by order id
$ordered_items = $order->getAllItems();
foreach($ordered_items as $item){ //item detail
echo $item->getItemId(); //product id
echo $item->getSku();
echo $item->getQtyOrdered(); //ordered qty of item
echo $item->getName(); // etc.
}
?>
<?php
$incrementId = '100057506'; //replace this with the increment id of your actual order
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING);
$order->setStatus('processing');
$order->setBaseDiscountCanceled(0);
$order->setBaseShippingCanceled(0);
$order->setBaseSubtotalCanceled(0);
$order->setBaseTaxCanceled(0);
$order->setBaseTotalCanceled(0);
$order->setDiscountCanceled(0);
$order->setShippingCanceled(0);
$order->setSubtotalCanceled(0);
$order->setTaxCanceled(0);
$order->setTotalCanceled(0);
foreach($order->getAllItems() as $item){
$item->setQtyCanceled(0);
$item->setTaxCanceled(0);
$item->setHiddenTaxCanceled(0);
$item->save();
}
$order->save();
?>
$activePayMethods = Mage::getModel('payment/config')->getActiveMethods();
$activeCarriers = Mage::getSingleton('shipping/config')->getActiveCarriers();
<?php
$_customerId = Mage::getSingleton('customer/session')->getCustomerId();
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$_totalData =$order->getData();
$_grand = $_totalData['grand_total'];
?>
By default, Magento will check the 'Exclude' box for you on all imported images, making them not show up as a thumbnail under the main product image on the product view.
# Mass Unexclude
UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '0' WHERE `disabled` = '1';
# Mass Exclude
UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '1' WHERE `disabled` = '0';
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_order_status_history`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;
TRUNCATE `sales_invoiced_aggregated`;
TRUNCATE `sales_invoiced_aggregated_order`;
TRUNCATE `sales_order_aggregated_created`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_aggregated_created` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;
SET FOREIGN_KEY_CHECKS=0;
-- reset customers
TRUNCATE customer_address_entity;
TRUNCATE customer_address_entity_datetime;
TRUNCATE customer_address_entity_decimal;
TRUNCATE customer_address_entity_int;
TRUNCATE customer_address_entity_text;
TRUNCATE customer_address_entity_varchar;
TRUNCATE customer_entity;
TRUNCATE customer_entity_datetime;
TRUNCATE customer_entity_decimal;
TRUNCATE customer_entity_int;
TRUNCATE customer_entity_text;
TRUNCATE customer_entity_varchar;
TRUNCATE log_customer;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
ALTER TABLE customer_address_entity AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_datetime AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_decimal AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_int AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_text AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_varchar AUTO_INCREMENT=1;
ALTER TABLE customer_entity AUTO_INCREMENT=1;
ALTER TABLE customer_entity_datetime AUTO_INCREMENT=1;
ALTER TABLE customer_entity_decimal AUTO_INCREMENT=1;
ALTER TABLE customer_entity_int AUTO_INCREMENT=1;
ALTER TABLE customer_entity_text AUTO_INCREMENT=1;
ALTER TABLE customer_entity_varchar AUTO_INCREMENT=1;
ALTER TABLE log_customer AUTO_INCREMENT=1;
ALTER TABLE log_visitor AUTO_INCREMENT=1;
ALTER TABLE log_visitor_info AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
TRUNCATE `log_visitor_online`;
TRUNCATE `log_quote`;
TRUNCATE `log_summary`;
TRUNCATE `log_summary_type`;
TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `sendfriend_log`;
TRUNCATE `report_event`;
TRUNCATE `dataflow_batch_import`;
TRUNCATE `dataflow_batch_export`;
TRUNCATE `index_process_event`;
TRUNCATE `index_event`;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_online` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `log_summary` AUTO_INCREMENT=1;
ALTER TABLE `log_url_info` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
ALTER TABLE `dataflow_batch_import` AUTO_INCREMENT=1;
ALTER TABLE `dataflow_batch_export` AUTO_INCREMENT=1;
ALTER TABLE `index_event` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
function getCategoriesTreeView() {
// Get category collection
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('name')
->addAttributeToSort('path', 'asc')
->addFieldToFilter('is_active', array('eq'=>'1'))
->load()
->toArray();
// Arrange categories in required array
$categoryList = array();
foreach ($categories as $catId => $category) {
if (isset($category['name'])) {
$categoryList[] = array(
'label' => $category['name'],
'level' =>$category['level'],
'value' => $catId
);
}
}
return $categoryList;
}
// Return options to system config
function toOptionArray()
{
$options = array();
// $options[] = array(
// 'label' => Mage::helper('overrides')->__('-- None --'),
// 'value' => ''
// );
$categoriesTreeView = getCategoriesTreeView();
foreach($categoriesTreeView as $value)
{
$catName = $value['label'];
$catId = $value['value'];
$catLevel = $value['level'];
$hyphen = '';
for($i=1; $i<$catLevel; $i++){
$hyphen = $hyphen ." -> ";
}
$catName = $hyphen .$catName.' ('.$catId.')';
$options[] = array(
'label' => $catName,
'value' => $catId
);
}
return $options;
}
$categoryList = toOptionArray();
foreach ($categoryList as $catvalue) {
echo "Category Id: ".$catvalue['value'];
echo "<br/>";
$category = Mage::getModel('catalog/category')->load($catvalue['value']);
$category->setPageLayout(''); // empty, one_column, two_columns_left, two_columns_right, three_columns
$category->save();
}
$customer = Mage::getModel('customer/customer');
if ($customerId) {
$customer->load($customerId);
}
public function exportOrders($orders)
{
$fileName = 'order_export_'.date("Ymd_His").'.csv';
$fp = fopen(Mage::getBaseDir('export').'/'.$fileName, 'w');
$this->writeHeadRow($fp);
foreach ($orders as $order) {
$this->writeOrder($order, $fp);
}
fclose($fp);
return $fileName;
}
protected function writeHeadRow($fp)
{
fputcsv($fp, $this->getHeadRowValues(), self::DELIMITER, self::ENCLOSURE);
}
protected function writeOrder($order, $fp)
{
fputcsv($fp, $record, self::DELIMITER, self::ENCLOSURE);
}
protected function getHeadRowValues()
{
return array(
'Order Number',
'Order Date',
'Order Status',
'Order Purchased From',
'Order Payment Method',
'Order Shipping Method',
'Order Subtotal',
'Order Tax',
'Order Shipping'
);
}
There is a more proper way to do this to avoid SQL Injections.
$resource = Mage::getSingleton('core/resource');
$write = $resource->getConnection('core_write');
$table = $resource->getTableName('your/model');
You can Create:
$write->insert(
$table,
['column_1' => 1, 'column_2' => 2]
);
Read:
$select = $write->select()
->from(['tbl' => $table], ['entity_id', 'company'])
->join(['tbl2' => $table2], 'tbl.entity_id = tbl2.product_id', ['stuff'])
->where('name LIKE ?', "%{$name}%")
->group('company');
$results = $write->fetchAll($select);
Update:
$write->update(
$table,
['column_1' => 3, 'column_2' => 4],
['entity_id = ?' => 123]
);
Delete:
$write->delete(
$table,
['entity_id IN (?)' => [123, 456]]
);
Insert Multiple:
$rows = [
['col_1'=>'value1', 'col_2'=>'value2', 'col_3'=>'value3'],
['col_1'=>'value3', 'col_2'=>'value4', 'col_3'=>'value5'],
];
$write->insertMultiple($table, $rows);
Insert Update On Duplicate:
$data = [];
$data[] = [
'sku' => $sku,
'name' => $name
];
$write->insertOnDuplicate(
$table,
$data, // Could also be an array of rows like insertMultiple
['name'] // this is the fields that will be updated in case of duplication
);
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection');
$type = Mage::getModel('eav/entity_type')->loadByCode(Mage_Catalog_Model_Product::ENTITY);
$attributeSetCollection->setEntityTypeFilter($type->getEntityTypeId()); // 4 is Catalog Product Entity Type ID
foreach ($attributeSetCollection as $id=>$attributeSet) {
$attributeSetName = $attributeSet->getAttributeSetName();
$attributeSetId = $attributeSet->getId();
$type = Mage::getModel('eav/entity_type')->loadByCode(Mage_Catalog_Model_Product::ENTITY);
$defaultAttributes = Mage::getModel('catalog/product_attribute_api')->items($attributeSetId);
$defaultAttributeCodes = array();
foreach ($defaultAttributes as $attributes) {
$defaultAttributeCodes[] = $attributes['code'];
}
echo "Attribute Set Name: <b>".$attributeSetName."</b>";
echo "<br/>";
echo "-- Atribute List----";
echo "<br/>";
foreach($defaultAttributeCodes as $child){
echo "---> ".$child;
echo "<br/>";
}
echo "<br/>";
}
$attrib_data = array(); $allAttributeCodes = array();
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')->getItems();
foreach ($attributes as $attribute){
$attrib_data[$attribute->getAttributeCode()] = $attribute->getData();
$allAttributeCodes[] = $attribute->getAttributeCode();
}
print_r($allAttributeCodes);