Data.php 10.4 KB
<?php
/**
 * @package  anc_lib 
 * @category magento
 * @mailto	code [at] netz.coop
 * @author	netz.coop eG* 
 * @copyright (c) 2014, netz.coop eG
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */ 

class Anc_Lib_Helper_Data extends Mage_Core_Helper_Abstract {

    public function cleanCache(){
         $cache = Mage::getSingleton('core/cache');
        $cache->flush();
    }
	private $ElementIndexForId_index = 0;
	
	public function getElementIndexForId() {
		return $this->ElementIndexForId_index++;
	}
	
	public function getAncsvgpageName($param_product_id, $param_page_id) {
		return 'ancsvgpage'.$param_product_id.'p'.$param_page_id;
	}	
	
	public function getAncsvgpageFunctionName($param_product_id, $param_page_id) {
		return 'get'.ucfirst($this->getAncsvgpageName($param_product_id, $param_page_id));
	}
    
    public function runPageTree($param_ProductId, $param_callback_obj, $param_callback_fnc) {
        $return = array();


        if (!$param_ProductId) {
            return false;
        }

        $current_product = Mage::registry('current_product');

        // Anzahl des Atributes "printpages"
        $var_num_ancprintpages = $current_product->getAncprintpages();
        $varpagename = "ancsvgpage" . $current_product->getId() . 'p';
        $varpagelabel = "SVG Seite ";

        /**
         *  Create Page Attributes for ancprintpages:
         */
        for ($i = 0; $i < $var_num_ancprintpages; $i++) {
            $j = $i + 1;
            // fnc name um den Inhalt des Attributes (svg Dateipfad) aus dem produkt zu holen
            $fncpagename = 'get' . ucfirst($varpagename) . $i;
            $varattributexists = $current_product->$fncpagename();

            $param_array = array(
                'productId' => $param_ProductId,
                'pageName' => $varpagename . $i,
                'pageLabel' => $varpagelabel,
                'pageLabelNumber' => $j,
                'attributeValue' => $varattributexists,
            );
            $return[] = $param_callback_obj->$param_callback_fnc($param_array);
        }

        return $return;
    }
     
     
     public function uniqueId(){
//         $test = Mage::getModel('sales/order');
//         D::show($test,'test',1,1);
//         $id= Mage::getModel('eav/entity_type')->loadByCode('cart_tracker')->fetchNewIncrementId(1); 
////        (int) Mage::getModel('eav/entity_type')->loadByCode('cart_tracker')->fetchNewIncrementId();
//         echo '<br><h1>id:'.$id.'</h1>';
         $id=  uniqid();
         return $id;
    }

	private $Currentcheckoutcartinfos = false;
	
	/**
	 * generiert info array zum checkout/cart/ aufruf
	 * * derzeit unterstützt es die Actions configure, subconfigure
	 * 
	 * array(
	 *		item_id => int
	 *		item => sales/quote_item
	 *		item_link => string
	 *		item_product => catalog/product
	 * 
	 *		breadcrumbs => array
	 * 
	 *		// optional
	 *			parent_item_id => int
	 *			parent_item => sales/quote_item 
	 *			parent_item_link => string
	 *			parent_item_product => catalog/product
	 * 
	 * )
	 */
//	public function getCurrentcheckoutcartinfos() {
	private function generateCurrentcheckoutcartinfos() {
		
		if($this->Currentcheckoutcartinfos === false) {
			$return = array();
			$productelement_special = $productelement = array();
			if(Mage::app()->getRequest()->getModuleName() === 'checkout' && Mage::app()->getRequest()->getControllerName() === 'cart') {
				if(Mage::app()->getRequest()->getActionName() === 'subconfigure') {
					$return['parent_item_id'] = Mage::app()->getRequest()->getParam('parent_item_id');
					$return['parent_item'] = Mage::getModel('sales/quote_item')->load($return['parent_item_id']);
					$return['parent_item_link'] = Mage::getUrl('checkout/cart/configure/', array('id' => $return['parent_item_id']));
					$return['parent_item_product'] = Mage::getModel('catalog/product')->load($return['parent_item']->getProductId());

					$productelement['label'] = $return['parent_item_product']->getName();
					$productelement['title'] = $return['parent_item_product']->getDescription();
					$productelement['link'] = $return['parent_item_link'];										

					$return['item_id'] = Mage::app()->getRequest()->getParam('id');
					$return['item'] = Mage::getModel('sales/quote_item')->load($return['item_id']);
					$return['item_product'] = Mage::getModel('catalog/product')->load($return['item']->getProductId());
					$return['item_link'] = Mage::getUrl('checkout/cart/subconfigure/', array('id' => $return['item_id'], 'parent_item_id' => $return['parent_item_id']));

					$productelement_special['label'] = $return['item_product']->getName();
					$productelement_special['title'] = $return['item_product']->getDescription();
					$productelement_special['link'] = $return['item_link'];							
					$productelement_special['last'] = true;
					$productelement_special['readonly'] = true;
					$productelement_special['special'] = 'ajax link!!!!';


					$_product = $return['parent_item_product'];

				} else if(Mage::app()->getRequest()->getActionName() === 'configure') {
					$return['item_id'] = Mage::app()->getRequest()->getParam('id');
					$return['item'] = Mage::getModel('sales/quote_item')->load($return['item_id']);
					$return['item_product'] = Mage::getModel('catalog/product')->load($return['item']->getProductId());
					$return['item_link'] = Mage::getUrl('checkout/cart/configure/', array('id' => $return['item_id']));

					$productelement['label'] = $return['item_product']->getName();
					$productelement['title'] = $return['item_product']->getDescription();
					$productelement['link'] = $return['item_link'];							
					$productelement['last'] = true;				
					$productelement['readonly'] = true;

					$_product = $return['item_product'];

				} else {
					D::li('Fall nicht abgedeckt ... ?',1,1);
				}


				$parent_category  = $_product->getCategory();
				if(!$parent_category) {
					$CategoryIds = $_product->getCategoryIds();
					$_category = Mage::getModel("catalog/category");
					$parent_category = $_category->load($CategoryIds[0]);
				}
				$parant_categorys = array();
				$parent_category = $parent_category;		
				do {
					if(is_object($parent_category)) {
						if(empty($parant_categorys)) {
							$first = true;
						} else {
							$first = false;
						}
						$parant_categorys[$parent_category->getUrlKey()] = array();
						if($parent_category->getName() ==='ncalbumjokercategory') {
							$SelectedCategoryNcAlbumModel = Mage::helper('anc_album/nccategory')->getSelectedCategoryNcAlbumModel(); 
							if(is_object($SelectedCategoryNcAlbumModel) && $SelectedCategoryNcAlbumModel->getId()) {
								$parant_categorys[$parent_category->getUrlKey()]['label'] = $SelectedCategoryNcAlbumModel->getName();
								$parant_categorys[$parent_category->getUrlKey()]['title'] = $SelectedCategoryNcAlbumModel->getComment();
								$parant_categorys[$parent_category->getUrlKey()]['link'] = "/".Mage::helper('anc_album/nccategory')->getCategoryUrl($parent_category, $SelectedCategoryNcAlbumModel->getData()).'';								
							} else {
								unset($parant_categorys[$parent_category->getUrlKey()]);
							}
						} else {
							$parant_categorys[$parent_category->getUrlKey()]['label'] = $parent_category->getName();
							$parant_categorys[$parent_category->getUrlKey()]['title'] = $parent_category->getDescription();
							$parant_categorys[$parent_category->getUrlKey()]['link'] = '/'.$parent_category->getUrlPath();
						}
						$parent_category = $parent_category->getParentCategory();
					}
				} while (is_object($parent_category) && $parent_category->getEntityId() && $parent_category->getName() != 'Produkt');
				 $parant_categorys = array_reverse($parant_categorys);				

				 $parant_categorys[] = $productelement;

				 if(!empty($productelement_special)) {
					 $parant_categorys[] = $productelement_special;
				 }

				 $return['breadcrumbs'] = $parant_categorys;
				 $this->Currentcheckoutcartinfos =  $return;
			} else {
				$this->Currentcheckoutcartinfos = array ('error' => 'error');
				
			}			
			
		}
//		return $this->Currentcheckoutcartinfos;
	}
	public function getCheckoutCartItemInfos() {
		$this->generateCurrentcheckoutcartinfos();
		$return = array();
		$return['item_id']		= $this->Currentcheckoutcartinfos['item_id'];
		$return['item']			= $this->Currentcheckoutcartinfos['item'];
		$return['item_product'] = $this->Currentcheckoutcartinfos['item_product'];
		$return['item_link']	= $this->Currentcheckoutcartinfos['item_link'];
		return $return;		
	}
	public function getCheckoutCartParentItemInfos() {
		$this->generateCurrentcheckoutcartinfos();
		$return = array();
	
		if(array_key_exists('parent_item_id', $this->Currentcheckoutcartinfos)) {
			$return['parent_item_id']		= $this->Currentcheckoutcartinfos['parent_item_id'];
			$return['parent_item']			= $this->Currentcheckoutcartinfos['parent_item'];
			$return['parent_item_link']		= $this->Currentcheckoutcartinfos['parent_item_link'];
			$return['parent_item_product']	= $this->Currentcheckoutcartinfos['parent_item_product'];			
		}
		return $return;		
	}	
	/**
	 * gibt den Breadcrumbs Pfad zurück
	 * 
	 * @return array
	 */
	public function getBreadcrumbs() {
		$this->generateCurrentcheckoutcartinfos();
		return $this->Currentcheckoutcartinfos['breadcrumbs'];
	}
	
	public function realPathToWebPath($param_realPath, $param_withStartSlash=false) {
		$return = false;
		if(strpos($param_realPath, Mage::helper('anc_lib/ncfilepath')->getThisMagentoInstallationPath()) !== false) {
			$return = str_replace(Mage::helper('anc_lib/ncfilepath')->getThisMagentoInstallationPath(), '', $param_realPath);
		} else if(strpos($param_realPath, Mage::getBaseDir('base')) !== false) {
			$return = str_replace(Mage::getBaseDir('base'), '', $param_realPath);
		}
		if(strpos($return, '/') === 0) {
			if(!$param_withStartSlash) {
				$return = substr($return, 1);
			}
		} else {
			if($param_withStartSlash) { 
				$return = '/'.$return;
			}
		}
		return $return;
	}
}