working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,040 snippets matching: magento

    public by shebin512 modified Nov 18, 2015  935889  1  6  0

    Product Listing in Magento using SKUs

    Code to fetch Products in collection and useing SKU's and display the products
    <html>
      <body>
    <?php
    /**
    * Code to fetch Products in collection and useing SKU's and  display the products
    *
    */
    $pCollection = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToFilter(
            'sku',
            array('in' => array(
    			    18811601,51361203,51360601,18811602,51361201,83545603,18811603// Test Sku's
            	//18807601,18807603,10264601,18792202,  83527701, 56821204// sku dev setup
    			  )
    		  )
        )	
        ->addAttributeToSelect('price')
        ->addAttributeToSelect('name')
        ->addAttributeToSelect('image')
    	  ->addAttributeToSelect('special_price');
    	  
    	  //Media model to fetch Image URL
    	  $productMediaConfig = Mage::getModel('catalog/product_media_config');
    	  ?>
    	  <div class="product-list owlCarousel">
    		<?php
    				if (count($pCollectionBolt)>0){
    					foreach ( $pCollectionBolt as $_product) {
                //Mage::Helper('training')->getProductDetails($_product); You can use helper to display the product details as you Wish
                //I'm adding code here itself
                $_pSku = $_product->getSku();
                $_pName = $_product->getName();
                $_pUrl = $_product->getProductUrl();
                $_pImageUrl = Mage::helper('catalog/image')->init($_product, 'image');
                //$_pPrice = $_product->getPrice();
                $_pPrice = $_product->getFinalPrice();
                echo "<div><a href='".$_pUrl."'><img src='".$_pImageUrl."' alt='".$_pName."' /></a>
                    <div class='productname-price'><a href='".$_pUrl."' style='min-height:0px;'>".$_pName."</a><span>&#8377;".$_pPrice."</span></div>
                  </div>";
    					}
    				}else{
    					echo "<span style='text-align:center'>No products in the List</span>";
    				}
    			?>
    		</div>
    	</body>
    </html>            

    public by fadzly modified Feb 11, 2015  444479  67  5  0

    Magento - custom table join product eav table in a grid

    protected function _prepareCollection()
        {
    		//to join normal attributes; but not sku, type_id and others (see catalog_product_entity database table)
    		$productAttributesArray = array('product_name' => 'name', 'product_seller' => 'seller', 'product_supplier' => 'supplier');
    		$poTempModel = Mage::getModel('mymodule/modelone')->load($this->getRequest()->getParam('id'),'actual_id');
    		$collection = Mage::getModel('mymodule/modeltwo')->getCollection()->addFieldToFilter('parent_id',$poTempModel->getId());
    		foreach ($productAttributesArray as $alias => $attributeCode)
    		{
        		$tableAlias = $attributeCode . '_table';
        		$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
    			//Add eav attribute value
        		$collection->getSelect()
    							->joinLeft(
    								array($tableAlias => $attribute->getBackendTable()),
    								"main_table.product_id = $tableAlias.entity_id AND $tableAlias.attribute_id={$attribute->getId()}",
    								array($alias => 'value')
    							);
        	}
    		//to join entity attributes such sku, type_id
    		$collection->join(
                'catalog/product',
                'product_id = `catalog/product`.entity_id',//note the ` . DO NOT USE '
                array('sku' => 'sku')
            );
    		$this->setCollection($collection);
    		return parent::_prepareCollection();
        }
    	
    	protected function _prepareColumns()
    	{
    		$this->addColumn('position', array(
    			'header'=> 'Position',
    			'width' => '50px',
    			'type'  => 'number',
    			'index'=>'position',
    			'sortable' => false
    		));
    		$this->addColumn('product_name', array(
    			'header'=> 'Name',
    			'type'  => 'text',
    			'index'=>'product_name',
    			'sortable' => false
    		));
    		$this->addColumn('sku', array(
    			'header'=> 'SKU',
    			'type'  => 'text',
    			'index'=>'sku',
    			'sortable' => false
    		));
    		$this->addColumn('poitemtemp_id', array(
    			'header'=> 'Action',
    			'align'	=> 'center',
    			'type'  => 'number',
    			'index'=>'poitemtemp_id',
    			'renderer' 	=> 'mymodule/adminhtml_editpo_elements_edit_gridscontainer_currentitemsrender',
    			'sortable' => false
    		));
    		return parent::_prepareColumns();
    	}            

    public by fadzly modified Aug 13, 2014  208405  0  7  0

    Add product attribute to setup

    $catalog = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('catalog_setup');
    
    $catalog->addAttribute('catalog_product','pickuprate', array(
    		'type' => 'int',
    		'input'=> 'select',
    		'label' => 'Pick Up Rate',
    		'user_defined' => 1,
    		'required' => 0,
    		'group'=> 'Prices',
    		'source' => 'Marketplace_Mod_Model_Pickuprategrp'
    	));

    public by bobby modified Jan 10, 2017  156950  2  4  0

    Returns Descriptions for all active Magento products

    Returns Descriptions for all active Magento products: Magento-active-product-descriptions.sql
    SELECT 
        e.entity_id,
        e.sku,
        eav.value AS 'description',
        IF(at_status.value_id > 0,
            at_status.value,
            at_status_default.value) AS `status`
    FROM
        catalog_product_entity e
            JOIN
        catalog_product_entity_text eav ON e.entity_id = eav.entity_id
            JOIN
        eav_attribute ea ON eav.attribute_id = ea.attribute_id
            INNER JOIN
        `catalog_product_entity_int` AS `at_status_default` ON (`at_status_default`.`entity_id` = `e`.`entity_id`)
            AND (`at_status_default`.`attribute_id` = '89')
            AND `at_status_default`.`store_id` = 0
            LEFT JOIN
        `catalog_product_entity_int` AS `at_status` ON (`at_status`.`entity_id` = `e`.`entity_id`)
            AND (`at_status`.`attribute_id` = '89')
            AND (`at_status`.`store_id` = 1)
    WHERE
        ea.attribute_code = 'description'
            AND IF(at_status.value_id > 0,
            at_status.value,
            at_status_default.value) = 1
    LIMIT 9999
    
                

    public by shebin512 modified Oct 4, 2016  1499  1  5  0

    Bash Script to clean magento 1.x Cache

    Magento 1.x cache clean Bash script. 1. Save the code in "/path/of/the/file/.sh" 2. Give executable permission for the file "chmod a+x /path/of/the/file/.sh" 3. Run the script from your magento document root like $ /path/of/the/file/.sh
    #!/bin/bash 
    # author Shebin Sheikh
    
    # function to remove the magento cache.
    function mageCacheClear {
    
    	local current_dir=$(pwd);
    	#echo $current_dir
    	#exit
    
    	if [[ -f "$current_dir/app/Mage.php" ]]; then
    		#echo "Inside Mage Doc root"
    		rm -vrf var/{cache,full_page_cache}/ media/{js,css}/
    	else
    		echo -e "Not inside A magento 1.X's document root!"
    		exit $?
    	fi
    
    }
    
    mageCacheClear # call the function

    public by shebin512 modified Oct 4, 2016  3759  1  7  1

    Magento get current controller ,current module , current action and route name

    Magento get current controller ,current module , current action and route name
    <?php
    
    /*
     *Magento get current controller ,current module , current action and route name
     */
    
    //1 . controller name
    Mage::app()->getRequest()->getControllerName();// will return controller name
    
    //2. action name
    Mage::app()->getRequest()->getActionName();//will return action name
    
    //3. module name
    Mage::app()->getRequest()->getModuleName();// will return module name
    
    //4. routes name
    Mage::app()->getRequest()->getRouteName();//will return routes name            

    public by fadzly modified Jan 19, 2017  11585  0  4  0

    Saving date in Magento

    Saving date in Magento
    Mage::getModel('plansetter/dailyscheduledraft')
                                        ->setId()
                                        ->setScheduleDate(Mage::getModel('core/date')->gmtDate(null, date("d-m-Y")))

    public by fadzly modified Nov 1, 2016  4033  0  5  0

    Get magento locale date/time from GMT timestamp / current time

    Get magento locale date/time from GMT timestamp / current time
    date("d-m-Y H:i:s", Mage::getModel('core/date')->timestamp(time()))

    public by fadzly modified Apr 22, 2015  2735  1  5  -1

    Custom Magento system.xml (Sytem->Configuration) model

    <field>
    	<label></label>
    	<button_label>New Button</button_label>
    	<frontend_model>mymodule/adminhtml_config_buttons_custombutton</frontend_model>
    	<sort_order>3</sort_order>
    	<show_in_default>1</show_in_default>
    	<show_in_website>1</show_in_website>
    	<show_in_store>1</show_in_store>
    </field>

    public by shebin512 modified Jan 6, 2017  1846  2  5  0

    Magento 1.x Update single Quote Item

    Update a single quote Item in magento 1.x
    <?php
    // Update single quote Item/s qty/data.
    
    // Step 1 : Load the quote object. This can be done in variety of ways depending on the location and usage.
    $quoteId=1;
    $itemId = 1234;// Items Id
    $quote = Mage::getModel('sales/quote')->setStore($store)->load($quoteId);
    
    // Step 2 : set the quote object qty manually
    
    // prepare data.
      $params = array();
      $params['qty'] = 5;// similarly you can set any item attribute.
      $request = new Varien_Object($params);
      
    // set Data.
      $quote->updateItem($itemId,$request);
                                        
    • Public Snippets
    • Channels Snippets