public function indexAction()
 {
     $uploaded_file = $_FILES['customer-image'];
     if ($uploaded_file['error'] != UPLOAD_ERR_OK) {
         echo 'Error';
         return;
     }
     $media_config = Mage::getModel('catalog/product_media_config');
     $extension = substr($uploaded_file['name'], strrpos($uploaded_file['name'], '.'));
     $file_name = zetaprints_generate_guid() . strtolower($extension);
     $zp_dir = (string) Mage::getConfig()->getNode('default/zetaprints/webtoprint/uploading/dir');
     $file_path = $media_config->getTmpMediaPath("{$zp_dir}/{$file_name}");
     $result = move_uploaded_file($uploaded_file['tmp_name'], $file_path);
     if (!$result) {
         echo 'Error';
         return;
     }
     $helper = Mage::helper('webtoprint');
     $user_credentials = $helper->get_zetaprints_credentials();
     //FIXME fast n dirty image upload fix
     $img_url = $media_config->getTmpMediaUrl("{$zp_dir}/{$file_name}");
     if (substr($img_url, 0, 1) == '/') {
         $img_url = 'http://' . $_SERVER['SERVER_NAME'] . $img_url;
     } else {
         //ZetaPrints doesn't accept URLs with HTTPS scheme
         $img_url = str_replace('https://', 'http://', $img_url);
     }
     $params = array('ID' => $user_credentials['id'], 'Hash' => zetaprints_generate_user_password_hash($user_credentials['password']), 'URL' => $img_url);
     $url = Mage::getStoreConfig('webtoprint/settings/url');
     $key = Mage::getStoreConfig('webtoprint/settings/key');
     $image = zetaprints_download_customer_image($url, $key, $params);
     unlink($file_path);
     if (is_array($image) && count($image) == 1) {
         $image = $image[0];
     } else {
         echo 'Error';
         return;
     }
     $result = array('guid' => $image['guid']);
     if ($image['mime'] === 'image/jpeg' || $image['mime'] === 'image/jpg') {
         $result['thumbnail'] = $helper->get_photo_thumbnail_url($image['thumbnail'], 0, 100);
     } else {
         $result['thumbnail'] = $helper->get_photo_thumbnail_url($image['thumbnail']);
     }
     echo json_encode($result);
 }
Example #2
0
 public function completeZetaPrintsOrder($id)
 {
     $url = Mage::getStoreConfig('webtoprint/settings/url');
     $key = Mage::getStoreConfig('webtoprint/settings/key');
     //New GUID for completed order
     $newId = zetaprints_generate_guid();
     $details = zetaprints_complete_order($url, $key, $id, $newId);
     if (!$details) {
         //_zetaprints_debug('Order wasn\'t completed '
         //                  . "(old ID: {$id}, new ID: {$newId})");
         //Check if saved order exists on ZetaPrints...
         if (zetaprints_get_order_details($url, $key, $id)) {
             //_zetaprints_debug('Order with old ID exists '
             //                  . "(old ID: {$id}, new ID: {$newId})");
             //... then try again to complete the order
             $details = zetaprints_complete_order($url, $key, $id, $newId);
             //If it fails...
             if (!$details) {
                 //_zetaprints_debug('Order wasn\'t completed second time '
                 //                  . "(old ID: {$id}, new ID: {$newId})");
                 $message = $this->__('Use the link to ZP order to troubleshoot.');
                 //... then return error.
                 return array('error' => true, 'message' => $message);
             }
         } else {
             if (!($details = zetaprints_get_order_details($url, $key, $newId))) {
                 //_zetaprints_debug('Orders with old and new ID don\'t exist '
                 //                  . "(old ID: {$id}, new ID: {$newId})");
                 $message = $this->__('Failed order. Contact admin@zetaprints.com ASAP to resolve.');
                 //... then return error.
                 return array('error' => true, 'message' => $message);
             }
         }
     }
     $data = array('error' => false, 'files' => array());
     $types = array('pdf', 'gif', 'png', 'jpeg', 'cdr');
     foreach ($types as $type) {
         if (strlen($details[$type])) {
             $data['files'][$type] = $url . '/' . $details[$type];
         }
     }
     $data['id'] = $details['guid'];
     return $data;
 }
 public function map()
 {
     //Always print debug information. Issue #80
     $this->debug = true;
     $this->warning('Product type: ' . $this->getAction()->getParam('product-type', 'simple'));
     if (!($assignToWebsites = $this->_getWebsitesForAssign())) {
         return;
     }
     //Get all web-to-print templates
     $templates = Mage::getModel('webtoprint/template')->getCollection()->load();
     //Get all products
     $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('webtoprint_template')->load();
     //If there're products then...
     if ($has_products = (bool) count($products)) {
         //... create array to store used web-to-print template GUIDs
         $used_templates = array();
         //For every product...
         foreach ($products as $product) {
             //... remember its ID
             $used_templates[$product->getId()] = null;
             //And if it has web-to-print attribute set then...
             if ($product->hasWebtoprintTemplate() && $product->getWebtoprintTemplate()) {
                 //... also remember the value of the attribute
                 $used_templates[$product->getWebtoprintTemplate()] = null;
             }
         }
     }
     unset($products);
     // Get ID of source product if present and try to load source product
     $sourceId = $this->getAction()->getParam('source-product-id');
     $sourceProduct = null;
     if ($sourceId) {
         $sourceProduct = Mage::getModel('catalog/product')->load($sourceId);
         if ($sourceProduct->getId()) {
             $this->warning('Base product: ' . $sourceProduct->getName());
             $sourceProduct->getCategoryIds();
             $sourceProduct->setId(null);
             $sourceData = $sourceProduct->getData();
             $sourceData['stock_item'] = null;
             $sourceData['url_key'] = null;
         } else {
             $sourceProduct = null;
         }
     }
     $url = Mage::getStoreConfig('webtoprint/settings/url');
     $key = Mage::getStoreConfig('webtoprint/settings/key');
     $_catalogues = zetaprints_get_list_of_catalogs($url, $key);
     $cataloguesMapping = array();
     foreach ($_catalogues as $_catalogue) {
         $cataloguesMapping[$_catalogue['guid']] = $_catalogue['title'];
     }
     $_catalogues = array();
     $categoryMappingStore = $this->getAction()->getParam('category-mapping-store');
     $categoryMappingStore = Mage::app()->getStore($categoryMappingStore);
     $assignToParents = (bool) $this->getAction()->getParam('assign-to-parents');
     if (!$categoryMappingStore->getId()) {
         $categoryMappingStore = null;
     }
     $useProductPopulateDefaults = Mage::getStoreConfig('webtoprint/settings/products-populate-defaults');
     $_defaultCategory = array();
     $helper = Mage::helper('webtoprint/category');
     $line = 0;
     $number_of_templates = count($templates);
     $number_of_created_products = 0;
     foreach ($templates as $template) {
         $line++;
         if ($has_products) {
             if (array_key_exists($template->getGuid(), $used_templates)) {
                 $this->debug("{$line}. Product {$template->getGuid()} already exists");
                 continue;
             }
         }
         if (!$sourceProduct) {
             $product_model = Mage::getModel('catalog/product');
             $product_model->setWebsiteIds($assignToWebsites)->setAttributeSetId($product_model->getDefaultAttributeSetId())->setTypeId($this->getAction()->getParam('product-type', 'simple'))->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED)->setVisibility(0);
             if ($useProductPopulateDefaults) {
                 $product_model->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)->setWeight(0)->setPrice(0)->setTaxClassId(0);
             }
             $templateDetails = zetaprints_parse_template_details(new SimpleXMLElement($template->getXml()));
             $templateDetails['catalogue'] = $cataloguesMapping[$template->getCatalogGuid()];
             $categoryIds = $helper->getCategoriesIds($templateDetails, $assignToParents, $categoryMappingStore);
             if (!$categoryIds && $useProductPopulateDefaults) {
                 $categoryIds = $this->_getDefaultCategoryId();
             }
             $product_model->setCategoryIds($categoryIds);
         } else {
             $product_model = $sourceProduct;
             $product_model->setOrigData()->setData($sourceData);
         }
         $product_model->setSku(zetaprints_generate_guid() . '-rename-me')->setName($template->getTitle())->setDescription($template->getDescription())->setShortDescription($template->getDescription())->setRequiredOptions(true)->setWebtoprintTemplate($template->getGuid());
         Mage::dispatchEvent('webtoprint_product_create', array('product' => $product_model, 'template' => $templateDetails, 'params' => array('process-quantities' => $this->_isProcessQuantities())));
         try {
             $product_model->save();
         } catch (Exception $e) {
             $this->error("{$line}. Error creating product from template: {$template->getGuid()}");
             $this->error($e->getMessage());
             continue;
         }
         $stock_item = Mage::getModel('cataloginventory/stock_item');
         $stock_item->setStockId(1)->setUseConfigManageStock(0)->setProduct($product_model)->save();
         $this->debug("{$line}. Product for template {$template->getGuid()} was created.");
         $number_of_created_products++;
         unset($product_model);
         unset($stock_item);
     }
     $this->notice("Number of templates: {$number_of_templates}");
     $this->notice("Number of created products: {$number_of_created_products}");
     $this->warning('Warning: products were created with general set of properties. Update other product properties using bulk edit to make them operational.');
 }
<?php

require_once Mage::getBaseDir() . '/lib/ZetaPrints/zetaprints-api.php';
$dir_name = zetaprints_generate_guid();
Mage::getConfig()->saveConfig('zetaprints/webtoprint/uploading/dir', $dir_name);
mkdir(Mage::getModel('catalog/product_media_config')->getTmpMediaPath($dir_name), 0777, true);