Product.php 4.7 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_Product extends Mage_Core_Helper_Abstract {
    private $attributsets = array() ;
    /**
     * gibt den attributset name zurück
     * 
     * @param int $param_id - attribute_set_id
     * @return string
     */
    public function getAttributeSetName($param_id) {
            if(!array_key_exists($param_id, $this->attributsets)) {
                    $attribute_set_name = Mage::helper('anc_lib/sql')->selectFetchOne(
                                    'attribute_set_name', 
                                    'eav_attribute_set', 
                                    array('attribute_set_id' => $param_id)
                    );
                    $this->attributsets[$param_id] = $attribute_set_name;
            }		
            return $this->attributsets[$param_id];
    }    

    /**
     * gibt product model zurück und speichert es intern im CACHE
     * 
     * @param int $param_id
     * @return Mage_Catalog_Model_Product
     */
    public function getProduct($param_id) {
	if(!array_key_exists($param_id, $this->CACHE_products)) {
	    $this->CACHE_products[$param_id] = Mage::getModel("catalog/product");
	    $this->CACHE_products[$param_id]->load($param_id);	    
	}
	return $this->CACHE_products[$param_id];
    }
    
    private $CACHE_products = array();
    
    /**
     * gibt Product sku zurück
     * 
     * @param int $param_id
     * @return string
     */
    public function getProductSku($param_id) {
	$product = $this->getProduct($param_id);
	return $product->getData('sku');
    }
    
	/**
	 * fnc setzt parameter für eine vorhandene individuelle option
	 *	sie muss mit der sku eindeutig sein, und darf nur einmal in kombination $param_product_id, $param_option_sku vorkommen
	 *	ansonsten gibts nen fehler!!!!!
	 * 
	 * 
	 * @param int $param_product_id
	 * @param string $param_option_sku
	 * @param string $param_max_characters=null - wenn null Wert wird nicht gesetzt
	 * @param string $param_file_extension=null - wenn null Wert wird nicht gesetzt
	 * @param int $param_image_size_x=null - wenn null Wert wird nicht gesetzt
	 * @param int $param_image_size_y=null - wenn null Wert wird nicht gesetzt
	 */
	public function setIndividuelOptionWithoutOptionID($param_product_id, $param_option_sku, $param_max_characters=NULL, $param_file_extension=NULL, $param_image_size_x=NULL, $param_image_size_y=NULL) {
		if($param_product_id && $param_option_sku) {
			$option_id = Mage::helper('anc_lib/sql')->selectFetchCol(
				'option_id', 
				'catalog_product_option', 
				array(
					'product_id' => $param_product_id,
					'sku' => $param_option_sku
				)
			);			
			
			if(is_array($option_id) && count($option_id) && $option_id[0]) {
				$where = array( 'option_id' => $option_id[0]);
				if(!is_null($param_max_characters)) {
					Mage::helper('anc_lib/sql')->updateOneCell('catalog_product_option', 'max_characters', $param_max_characters, $where);
				}
				if(!is_null($param_file_extension)) {
					Mage::helper('anc_lib/sql')->updateOneCell('catalog_product_option', 'file_extension', $param_file_extension, $where);
				}				
				if(!is_null($param_image_size_x)) {
					Mage::helper('anc_lib/sql')->updateOneCell('catalog_product_option', 'image_size_x', $param_image_size_x, $where);
				}
				if(!is_null($param_image_size_y)) {
					Mage::helper('anc_lib/sql')->updateOneCell('catalog_product_option', 'image_size_y', $param_image_size_y, $where);
				}				
					
			} else {
				if(is_array($option_id) && empty($option_id)) {
					D::li('FEHLER: keine option_id gefunden $param_product_id('.$param_product_id.'), $param_option_sku('.$param_option_sku.')');
				} else {
					D::fe($option_id, 'FEHLER: ermittelte option_id ist nicht eindeutig $param_product_id('.$param_product_id.'), $param_option_sku('.$param_option_sku.')');
				}
					
				return false;				
			}
		} else {
			D::li('FEHLER: es müssen $param_product_id und $param_option_sku übergeben werden ');
			return false;
		}

	}
}