function writeProduct($product) { // print_r($product); // return; /* print '"'; print $product[0]["sku"]; print '"'; print ","; $res = ""; $res = str_replace('"', "", $product[0]["name"]); $res = str_replace(",", " ", $res); $res = str_replace('"', '', $res); print '"'; print $res; print '"'; $res = ""; foreach($product as $fields){ if(isset($fields["merkmal_122"])){ $res = $fields["merkmal_122"]; } } // print $product[10]["merkmal_122"]; print ","; print '"'; print $res; print '"'; print ","; print '"'; $res = 0; $res = $product[0]["price"]; // $res = Mage::helper('core')->currency($res, true, false); // $res = str_replace(",", ".", $res); // $res = str_replace(".", ",", $res); print $res; print '"'; $res = str_replace(".", ",", $res); print ","; print '"'; print $res; print '"'; print "\n"; return; */ global $settings; global $magicImportIDs; global $productContainer; logger("writeProduct()"); // returns with the "old" export format if (3 == count($product)) { logger("Deprecated product import format; returning"); return; } // ** selects largest product id $sql = "select max(entity_id) from catalog_product_entity"; $res = Mage::getSingleton('core/resource')->getConnection("core_read")->fetchAll($sql); $pid = (int) $res[0]["max(entity_id)"]; $pid += 1; logger("pid:" . $pid); $sku = $product[0]["sku"]; logger("sku:" . $sku); // returns without the sku if (null === $sku) { logger("No sku found; returning"); return; } // loads product by sku $coll = Mage::getModel("catalog/product")->getCollection(); $coll->addFieldToFilter("sku", $sku); $prod = null; foreach ($coll as $prod) { $prod = $prod->load($prod->getId()); $pid = $prod->getId(); logger("Product found:" . $prod->getSku()); } // reads a product from store if (null === $prod) { logger("New product"); $coll = Mage::getModel("catalog/product")->getCollection(); foreach ($coll as $p) { // selects a product $prod = $p->load($p->getId()); logger("Reading first prod from collection"); break; } } // reads product from persisted product instance if (null === $prod) { logger("Using serialized prod"); // selects serialized product global $pmod; $prod = $pmod; } // sets attribute id $prod->setAttributeID(Mage::getModel("eav/entity_attribute_set")->getCollection()->setEntityTypeFilter(Mage::getModel("eav/entity")->setType("catalog_product")->getTypeId())->addFieldToFilter("attribute_set_name", "Default")->getFirstItem()->getAttributeSetId()); // extracts linked categories $lc = array(); for ($i = 0; $i < count($product); $i++) { $cat = $product[$i]["_category"]; if (null === $cat) { continue; } $temp = explode(".", $cat); $cat = $temp[1]; if ("" !== $cat) { $lc[] = $cat; } } $cats = implode(",", $lc); logger("Cats: " . $cats); $prod->setCategoryIds($cats); if ($settings["attrdownload"]) { $productAttributes = fetchProductAttributes($sku); } $additional = array(); foreach ($productAttributes->attributes as $key => $value) { switch ($key) { case "318": foreach ($value as $kkey => $vvalue) { $loc = "en"; if ("1" === $kkey) { $loc = "de"; } foreach ($vvalue as $kkkey => $vvvalue) { if ("value" === $kkkey) { $additional[$loc][0] = $vvvalue; } } } break; case "319": foreach ($value as $kkey => $vvalue) { $loc = "en"; if ("1" === $kkey) { $loc = "de"; } foreach ($vvalue as $kkkey => $vvvalue) { if ("value" === $kkkey) { $additional[$loc][1] = $vvvalue; } } } break; case "320": foreach ($value as $kkey => $vvalue) { $loc = "en"; if ("1" === $kkey) { $loc = "de"; } foreach ($vvalue as $kkkey => $vvvalue) { if ("value" === $kkkey) { $additional[$loc][2] = $vvvalue; } } } break; } } // extracts product image | codex !! $productImagePath = null; foreach ($product as $p) { if (isset($p["merkmal_473"])) { $productImagePath = $p["merkmal_473"]; } } // assume there is no "merkmal_473" switch ($productImagePath) { case null: case "": $productImagePath = $product[0]["image"]; } // print ">>" . $productImagePath . "\n"; // extracts category image | codex $categoryImagePath = null; foreach ($product as $p) { if (isset($p["merkmal_280"])) { $categoryImagePath = $p["merkmal_280"]; } } /* $cid = $lc[0]; if(null !== ($cat = Mage::getModel("catalog/category")->setStoreId("default")->load($cid))){ $cat->setStoreId(getStoreId("default")); $cat->setData("add_desc_1", $additional["de"][0]); $cat->setData("add_desc_2", $additional["de"][1]); $cat->setData("add_desc_3", $additional["de"][2]); print "" . $cat->getId() . ":" . $cat->getName() . "\n"; $cat->save(); } */ /* if(null !== ($cat = Mage::getModel("catalog/category")->setStoreId(getStoreId("en"))->load($cid))){ $cat->setStoreId(getStoreId("default")); $cat->setData("add_desc_1", $additional["en"][0]); $cat->setData("add_desc_2", $additional["en"][1]); $cat->setData("add_desc_3", $additional["en"][2]); $cat->save(); } */ // adds a product image /* fetchImage($categoryImagePath); $target = Mage::getBaseDir("media") . DS . "import" . DS . $categoryImagePath; $data['display_mode'] = 'PRODUCTS_AND_PAGE'; $data['page_layout'] = 'one_column'; $data['thumbnail'] = $target; $cat->addData($data); $cat->save(); */ // print "sku: " . $sku . "\n"; // exit(1); // $cat->addImageToMediaGallery($target, array("thumbnail"), true, false); // $cat->setDisplayMode("PRODUCTS_AND_PAGE"); // $cat->setPageLayout("one_column"); // $cat->saveThumbnail($target); // $cat->save(); // this might fail with two ore more parent categories // sets website ids $prod->setWebsiteIds(array(1)); // deletes values $prod->setMetaTitle(""); $prod->setMetaDescription(""); $prod->setMetaKeyword(""); $prod->setUrlKey(""); $prod->setManufacturer(""); // gets the index of global values in an ever changing import array for ($i = 0; $i < count($product); $i++) { if (isset($product[$i]["_product_websites"])) { if ("base" === $product[$i]["_product_websites"]) { $index = $i; $magicImportIDs["global"] = $index; break; } } } // sets global store values $prod->setId($pid); $prod->setSku($sku); $prod->setName(UTF8($product[$index]["name"])); $prod->setGlobalName(UTF8($product[$index]["global_name"])); $prod->setTypeId($product[$index]["_type"]); $prod->setStatus(1); $prod->setDescription(UTF8($product[$index]["description"])); $prod->setShortDescription(UTF8($product[$index]["short_description"])); $prod->setPrice($product[$index]["price"]); $prod->setTaxClassId($product[$index]["tax_class_id"]); $prod->setIsInStock($product[$index]["is_in_stock"]); $prod->setUseConfigManageStock($product[$index]["use_config_manage_stock"]); $prod->setVisibility($product[$index]["visibility"]); $prod->setQty($product[$index]["qty"]); $prod->setBasisartikelnr($product[$index]["basisartikelnr"]); /* $prod->setImage($product[$index]["image"]); $prod->setThumbnail($product[$index]["thumbnail"]); $prod->setSmallImage($product[$index]["small_image"]); $prod->setMediaImage($product[$index]["_media_image"]); $prod->setMediaPosition($product[$index]["_media_position"]); if($settings["fetch"]){ fetchImage($product[$index]["image"]); } */ $prod->setSmallImage($productImagePath); $prod->setThumbnail($productImagePath); $prod->setImage($productImagePath); $prod->setMediaImage($productImagePath); if ($settings["fetch"]) { fetchImage($productImagePath); } // additional fields // get stored in the categores.... // $prod->setArtikelbezeichnung1($additional["de"][0]); $prod->setArtikelbezeichnung2($additional["de"][1]); $prod->setArtikelbezeichnung3($additional["de"][2]); // karlie related product attributes // karlie related product attributes /* $prod->setBasisArtikelNr($product[$index]["basisartikelnr"]); $prod->setPackagingUnit($product[$index]["packaging_unit"]); $prod->setLength($product[$index]["length"]); $prod->setWidth($product[$index]["width"]); $prod->setHeight($product[$index]["height"]); $prod->setDiameter($product[$index]["diameter"]); $prod->setVolume($product[$index]["volume"]); $prod->setSize($product[$index]["size"]); $prod->setBargain($product[$index]["bargain"]); $prod->setNew($product[$index]["new"]); $prod->setWeight($product[$index]["weight"]); $prod->setTierart($product[$index]["tierart"]); $prod->setColor($product[$index]["color"]); */ // $prod->save(); // saves default view // sets magic index of the magic import interface // de is "one" (i guess) $index = 1; $magicImportIDs["de"] = $index; // sets "de" (default) store values $prod->setStoreId(getStoreId("default")); $prod->setName(UTF8($product[$index]["name"])); $prod->setDescription(UTF8($product[$index]["description"])); $prod->setShortDescription(UTF8($product[$index]["short_description"])); /* $prod->setMediaImage($product[$index]["_media_image"]); $prod->setThumbnail($product[$index]["thumbnail"]); $prod->setSmallImage($product[$index]["small_image"]); $prod->setImage($product[$index]["image"]); $prod->setMediaPosition($product[$index]["_media_position"]); if($settings["fetch"]){ fetchImage($product[$index]["image"]); } */ // saves "de" store view $prod->save(); // gets the index of "en" store values in an ever changing import array for ($i = 0; $i < count($product); $i++) { if (isset($product[$i]["_store"])) { if ("en" === $product[$i]["_store"]) { $index = $i; $magicImportIDs["en"] = $index; break; } } } // sets "en" store values $prod->setStoreId(getStoreId("en")); $prod->setName(UTF8($product[$index]["name"])); $prod->setDescription(UTF8($product[$index]["description"])); $prod->setShortDescription(UTF8($product[$index]["short_description"])); /* $prod->setArtikelbezeichnung1($additional["en"][0]); $prod->setArtikelbezeichnung2($additional["en"][1]); $prod->setArtikelbezeichnung3($additional["en"][2]); */ /* $prod->setMediaImage($product[$index]["_media_image"]); $prod->setThumbnail($product[$index]["thumbnail"]); $prod->setSmallImage($product[$index]["small_image"]); $prod->setImage($product[$index]["image"]); $prod->setMediaPosition($product[$index]["_media_position"]); if($settings["fetch"]){ fetchImage($product[$index]["image"]); } */ // saves "en" store view $prod->save(); // finds and fetches images whithin the magic arry /* $characteristica = array( "_media_image", "thumbnail", "small_image", "image", "_media_attribute_id", "_media_is_disabled", "_media_position" ); for($i = 0; $i < count($product); $i++){ $probablyAnImageAsset = 0; for($ii = 0; $ii < count($characteristica); $ii++){ if(isset($product[$i][$characteristica[$ii]])){ $probablyAnImageAsset += 1; } } if(7 == $probablyAnImageAsset){ $magicImportIDs["images"][$sku][] = $i; logger("Magic image found at " . $i . " : " . $product[$i]["image"]); if($settings["fetch"]){ fetchImage($product[$i]["image"]); } } } */ $productContainer[] = $product; logger("Written:" . $prod->getSku()); return true; }
function goType($type, $id, $size = 64, $imghost = "") { if ($size != 32 && $size != 64 && $size != 24 && $size != 48 && !($type == "ship" && ($size == 256 || ($size = 512)))) { show404(); } if ($id == 0) { if ($size == 32 || $size == 64 || $size == 128 || $size == 256) { header("Location: {$imghost}img/portrait_0_{$size}.jpg"); } else { header("Location: {$imghost}img/portrait_0_64.jpg"); } die; } define('KB_CACHEDIR', 'cache'); require_once "common/includes/class.cachehandler.php"; // If it's in the cache then read it from there. if (CacheHandler::exists("{$id}_{$size}.png", "img")) { expiryHeaders("png", CacheHandler::getInternal("{$id}_{$size}.png", "img")); readfile(CacheHandler::getInternal("{$id}_{$size}.png", "img")); die; } //TODO: add an optional memcache backed by the filecache //Ships are available at 256 and 512 if ($type == 'ship' && $size > 64) { $img = fetchImage($id, "Render", $size, "png"); } else { if ($size > 32) { if (CacheHandler::exists("{$id}_64.png", "img")) { $img = imagecreatefrompng(CacheHandler::getInternal("{$id}_64.png", "img")); } else { $img = fetchImage($id, "InventoryType", 64, "png"); } if ($img && $size != 64) { resize($size, 64, $img, CacheHandler::getInternal("{$id}_{$size}.png", "img")); } } else { if (CacheHandler::exists("{$id}_32.png", "img")) { $img = imagecreatefrompng(CacheHandler::getInternal("{$id}_32.png", "img")); } else { $img = fetchImage($id, "InventoryType", 32, "png"); } if ($img && $size != 32) { resize($size, 32, $img, CacheHandler::getInternal("{$id}_{$size}.png", "img")); } } } if (!$img) { show404(); } expiryHeaders("png", CacheHandler::getInternal("{$id}_{$size}.png", "img")); readfile(CacheHandler::getInternal("{$id}_{$size}.png", "img")); die; }