magento

warning: Creating default object from empty value in /data/web/1/000/027/003/273448/htdocs/panticz.de/modules/taxonomy/taxonomy.pages.inc on line 33.

Magento: Newsletter subscriber import script

add subscriber

<?php
require_once("./app/Mage.php");
Mage::app();

$subscribers = array('email1@server1.com', 'email2@server2.com');

foreach ($subscribers as $email) {
    # create new subscriber without send an confirmation email
    Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);
    
    # get just generated subscriber
    $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);

    # change status to "subscribed" and save
    $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
    $subscriber->save();
}
?>
1

list all subscribers

<?php
require_once("./app/Mage.php");
Mage::app();

$collection = Mage::getResourceModel('newsletter/subscriber_collection')->load();

foreach($collection->getItems() as $subscriber) {
    echo $subscriber->getSubscriberEmail();
}
?>
1

files
./app/code/core/Mage/Adminhtml/Block/Newsletter/Subscriber/Grid.php
./app/design/frontend/base/default/template/newsletter/subscribe.phtml

Links
http://docs.magentocommerce.com/Mage_Newsletter/Mage_Newsletter_Model_Subscriber.html#setStatus
http://blogs.ifuelinteractive.com/2011/01/04/programmatically-subscribing-a-customer-to-the-newsletter-list/
http://www.magentocommerce.com/boards/viewthread/7626/
http://magento-wordpress.blogspot.de/2012/08/how-to-send-newsletter-manually.html

Magento: Category list

./app/design/frontend/default/default/template/catalog/navigation/category_list.phtml

<?php $catId = $this->getCatId(); ?>
<?php $collection = Mage::getModel('catalog/category')->getCategories($catId); ?>
1

cms include php template
{{block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/category_list.phtml" cat_id=2227}}

CSS
.category_list ul {
height: 120px;
margin-bottom: 15px;
}

.category_list li {
float: left;
width: 250px;
}

Magento: CMS extension

./app/design/frontend/default/default/template/ebook/view.php

<?php
$filter = $this->getFilter();

$collection = Mage::getModel("cms/page")
    ->getCollection()
    ->addFieldToFilter("identifier", array("like"=>"%$filter%"))
    ->addFieldToFilter("is_active", 1)
    ->addOrder("title", "asc");
?>



<?php echo 'Count: ' . $collection->count(); ?>
1

./app/add.php

<?php
require_once './app/Mage.php';
Mage::app(0);

if($_POST["pass"] != "YOUR_PASS") {
    exit;
}

$newBlock = Mage::getModel('cms/page')
    ->setTitle(urldecode($_POST["t"]))
    ->setContent(urldecode($_POST["c"]))
    ->setIdentifier(urldecode($_POST["i"]))
    ->setContentHeading(urldecode($_POST["st"]))
    ->setMetaKeywords(urldecode($_POST["mk"]))
    ->setMetaDescription(urldecode($_POST["md"]))
    ->setCustomLayoutUpdateXml(urldecode($_POST["clux"]))
    ->setIsActive(true)
    ->setStores(0)
    ->setRootTemplate('two_columns_left')
    ->save();
?>
1

./app/del.php

<?php
require_once './app/Mage.php';
Mage::app(0);

if($_POST["pass"] != "YOUR_PASS") {
    exit;
}

$collection = Mage::getModel('cms/page')
    ->getCollection()
    ->addFieldToFilter('identifier', array('like'=>'%ebooks%'));

foreach ($collection as $page) {
    $page->delete();
}

echo "deleted: " . $collection->count();
?>
1

cms include php template
{{block type='core/template' template='ebook/view.php' filter='ebooks'}}

cms search
./app/design/frontend/default/default/template/cmssearch/result.phtml

Magento: Vertical Category Navigation (RicoNeitzel_VertNav)

Fix VertNav Category selection

diff -Naur /root/magento/app/code/community/RicoNeitzel/VertNav/Block/Navigation.php /var/www/app/code/community/RicoNeitzel/VertNav/Block/Navigation.php
--- /root/magento/app/code/community/RicoNeitzel/VertNav/Block/Navigation.php	2012-08-24 17:44:08.000000000 +0200
+++ /var/www/app/code/community/RicoNeitzel/VertNav/Block/Navigation.php	2012-08-24 17:50:06.000000000 +0200
@@ -30,6 +30,7 @@
 class RicoNeitzel_VertNav_Block_Navigation extends Mage_Catalog_Block_Navigation
 {
 	protected $_storeCategories;
+	protected $_currentCategory;
 
 	/**
 	 * Add the customer group to the cache key so this module is compatible with more extensions.
@@ -105,6 +106,48 @@
     }
 
     /**
+     * Get current category from layer or selected product 
+     *
+     * @return Mage_Catalog_Model_Category
+     */
+    public function getCurrentCategory()
+    {
+        if (isset($this->_currentCategory))
+        {
+            return $this->_currentCategory;
+        }
+
+        $id = $this->getRequest()->getParam('id');
+
+        // default
+        if (Mage::getSingleton('catalog/layer'))
+        {
+            $category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
+            $storeCategoriesParentId = $this->getStoreCategories()->getFirstItem()->getParentId();
+
+            if($category->getId() != $storeCategoriesParentId || $id == $storeCategoriesParentId)
+            {
+                $this->_currentCategory = $category;
+                return $category;
+            }
+        }
+
+        // get category from product
+        $product = Mage::getModel('catalog/product')->load($id);
+        $categoryIds = $product->getCategoryIds();
+
+        if(count($categoryIds) > 0)
+        {
+            $categoryId = reset($categoryIds);
+
+            $this->_currentCategory = Mage::getModel('catalog/category')->load($categoryId);
+            return Mage::getModel('catalog/category')->load($categoryId);
+        }
+
+        return false;
+    }
+
+    /**
      * Add project specific formatting
      *
      * @param Mage_Model_Catalog_Category $category
1

remove duplicate base files
rm -r /var/www/app/design/frontend/base/default/template/vertnav/

Links
http://www.magentocommerce.com/magento-connect/vertical-navigation-with-css-classes.html - Download on Magento Connect
http://www.magentocommerce.com/boards/viewthread/244440/#t359105 - Bug report "Blocks HTML output cache error"

Magento: featured items

./app/design/frontend/default/default/template/catalog/product/featured.phtml

<?php
$categoryId = 2228;

$catagory_model = Mage::getModel('catalog/category')->load($categoryId);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryFilter($catagory_model);
$collection->addAttributeToFilter('status', 1);
// $collection->addAttributeToSelect(array('name','url','small_image')); //add product attribute to be fetched
$collection->getSelect()->order('rand()');   
$collection->addStoreFilter();
$collection->setPageSize(1);
$collection->setCurPage(1);

if(!empty($collection)) {
    foreach ($collection as $_product) {
    $_product = Mage::getModel('catalog/product')->setStoreId($this->store_id)->load($_product->getId());   
?>
    
<?php
    }
}
1

Create cms page
Admin > CMS > Pages > Add new page
Page Title: featured
URL Key: featured
Content: {{block type="featured/featured" name="product_featured" as="product_featured" template="catalog/product/featured.phtml"}}

view on other page

<?php
    $html = file_get_contents("http://www.YOUR_SERVER.com/featured");
    $offerSku1 = preg_replace("/.*]*>|<\/sku>.*/si", "", $html);
    echo preg_replace("/.*]*>|<\/body>.*/si", "", $html);
?>


<?php
    // exclude same sku
    do {
        $html = file_get_contents("http://www.YOUR_SERVER.com/featured");
        $offerSku2 = preg_replace("/.*]*>|<\/sku>.*/si", "", $html);
    } while ($offerSku1 == $offerSku2);
    echo preg_replace("/.*]*>|<\/body>.*/si", "", $html);
?>
1

Links
http://inchoo.net/ecommerce/magento/featured-products-on-magento-frontpage/

Magento Cron

cat < /etc/cron.d/magento_cron
MAILTO=YOUR@EMAIL.COM

*/5 * * * * root /var/www/cron.sh
EOF

chmod u+x /var/www/cron.sh

Links
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job

Magento: Delete unused product images

#!/bin/bash

LOG=/var/log/magento/del_unused_img.log

. /etc/magento/magento.conf

function search_db() {
    COUNT=$(mysql -u ${DB_USER} -p${DB_PASS} ${DB_NAME} --execute="SELECT count(*) FROM catalog_product_entity_media_gallery WHERE value = \"$1\"")

    echo $(echo ${COUNT} | cut -d" " -f2)
}

echo $(date) | tee -a ${LOG}

for IMG in $(find /var/www/media/catalog/product/ -name '*.jpg' ! -path '*cache*' ! -name 'google*'); do
    # search in db
    if [ $(search_db ${IMG/'/var/www/media/catalog/product'/}) != 1 ]; then
        IMG=${IMG##*/}
        for CACHE_IMG in $(find /var/www/media/catalog/product/ -name "${IMG}"); do
            echo "${CACHE_IMG}" | tee -a ${LOG}
            
            rm "${CACHE_IMG}"
        done

        echo "" | tee -a ${LOG}
    fi
done

Links
http://www.magentocommerce.com/magento-connect/defcon2/extension/1147/image-clean/reviews#review_6087
http://stackoverflow.com/questions/4339699/delete-unused-product-images-in-magento

Magento Shadowbox (Rewrite EasyLightBox to Shadowbox)

# install easy light box
http://www.magentocommerce.com/magento-connect/TemplatesMaster/extension/1487/magento-easy-lightbox

# xml
edit
./app/design/frontend/default/default/layout/easylightbox.xml
replace
easylightbox
to
shadowbox

# phtml
copy
./app/design/frontend/default/default/template/easylightbox/media.phtml
to
./app/design/frontend/default/default/template/shadowbox/media.phtml
edit or download
http://www.panticz.de/sites/default/files/magento/shadowbox/media.phtml

# js
copy
./custom/shadowbox/shadowbox.js
to

Fix Magento order tax view

mkdir -p ./app/design/frontend/default/default/template/tax/order
cp ./app/design/frontend/base/default/template/tax/order/tax.phtml ./app/design/frontend/default/default/template/tax/order

--- ./app/design/frontend/base/default/template/tax/order/tax.phtml	2011-06-22 16:08:45.000000000 +0200
+++ ./app/design/frontend/default/default/template/tax/order/tax.phtml	2011-06-22 16:07:28.000000000 +0200
@@ -46,9 +46,9 @@
          tax-details<?php if ($isTop): echo ' tax-details-first'; endif; ?>"<?php if (!$this->getIsPlaneMode()):?> style="display:none;"<?php endif;?>>
             getLabelProperties()?>>
                 <?php echo $rate['title']; ?>
-                <?php if ($rate['percent']): ?>
+                
                     (<?php echo $rate['percent']; ?>%)
-                <?php endif; ?>
+                <?php endif; ?>-->
                 
             
             <?php if ($isFirst): ?>
@@ -63,7 +63,7 @@
     <?php endforeach; ?>
 <?php endif;?>
 
-<?php if ($this->displayFullSummary() && $_fullInfo && !$this->getIsPlaneMode()): ?>
+displayFullSummary() && $_fullInfo && !$this->getIsPlaneMode()): ?>
 ')">
 <?php elseif ($this->displayFullSummary() && $_fullInfo && $this->getIsPlaneMode()): ?>
 
@@ -78,4 +78,4 @@
         <?php endif;?>
     
     getValueProperties()?>><?php echo $_order->formatPrice($_source->getTaxAmount()) ?>
-
+ -->
1

mkdir -p ./app/design/frontend/default/default/template/sales/order/
cp ./app/design/frontend/base/default/template/sales/order/totals.phtml ./app/design/frontend/default/default/template/sales/order

--- ./app/design/frontend/base/default/template/sales/order/totals.phtml	2011-06-22 16:05:58.000000000 +0200
+++ ./app/design/frontend/default/default/template/sales/order/totals.phtml	2011-06-22 16:05:47.000000000 +0200
@@ -29,9 +29,7 @@
  */
 ?>
 <?php foreach ($this->getTotals() as $_code => $_total): ?>
-    <?php if ($_total->getBlockName()): ?>
-        <?php echo $this->getChildHtml($_total->getBlockName(), false); ?>
-    <?php else:?>
+    <?php if (!$_total->getBlockName()): ?>
     ">
         getLabelProperties()?>>
             <?php if ($_total->getStrong()):?>
@@ -50,3 +48,11 @@
     
     <?php endif?>
 <?php endforeach?>
+
+<?php foreach ($this->getTotals() as $_code => $_total): ?>
+    <?php if ($_total->getBlockName()): ?>
+    ">
+        <?php  echo $this->getChildHtml($_total->getBlockName(), false); ?>
+    
+    <?php endif?>
+<?php endforeach?>
1

Fix Magento 1.4.0.1 PayPal shipping costs bug

wget http://www.boostingecommerce.com/files/Magento_1_4_0_1_PayPal_fix.zip -O /tmp/Magento_1_4_0_1_PayPal_fix.zip
unzip /tmp/Magento_1_4_0_1_PayPal_fix.zip -d /tmp/
cp -a /tmp/Magento_1_4_0_1_PayPal_fix/app/code/local/Mage/Paypal /var/www/app/code/local/Mage/

Links
http://www.magentocommerce.com/bug-tracking/issue?issue=8467
http://www.boostingecommerce.com/fix-for-magento-1-4-0-1-paypal-and-shipping-costs

Syndicate content