Gateway3D_PersonaliseIt - Version 1.6.0.0

Version Notes

1. package release

Download this release

Release Info

Developer James Ball
Extension Gateway3D_PersonaliseIt
Version 1.6.0.0
Comparing to
See all releases


Version 1.6.0.0

Files changed (56) hide show
  1. app/code/local/Gateway3D/PersonaliseIt/Block/Adminhtml/Catalog/Product/Edit/Tab/Options.php +31 -0
  2. app/code/local/Gateway3D/PersonaliseIt/Block/Adminhtml/Catalog/Product/Edit/Tab/Options/Option.php +28 -0
  3. app/code/local/Gateway3D/PersonaliseIt/Block/Product/View/Options.php +19 -0
  4. app/code/local/Gateway3D/PersonaliseIt/Helper/Data.php +17 -0
  5. app/code/local/Gateway3D/PersonaliseIt/Helper/MessageEvent.php +42 -0
  6. app/code/local/Gateway3D/PersonaliseIt/Helper/ProductCustomOptions.php +98 -0
  7. app/code/local/Gateway3D/PersonaliseIt/Model/Catalog/Product/Option.php +43 -0
  8. app/code/local/Gateway3D/PersonaliseIt/Model/Catalog/Product/Option/Type/Hidden.php +12 -0
  9. app/code/local/Gateway3D/PersonaliseIt/Model/Cron/Abstract.php +89 -0
  10. app/code/local/Gateway3D/PersonaliseIt/Model/Cron/DelayedPrintJob.php +144 -0
  11. app/code/local/Gateway3D/PersonaliseIt/Model/Cron/Sl.php +623 -0
  12. app/code/local/Gateway3D/PersonaliseIt/Model/ImportOptions.php +193 -0
  13. app/code/local/Gateway3D/PersonaliseIt/Model/Product/Abstract.php +64 -0
  14. app/code/local/Gateway3D/PersonaliseIt/Model/Product/Callback.php +389 -0
  15. app/code/local/Gateway3D/PersonaliseIt/Model/Product/Epa.php +260 -0
  16. app/code/local/Gateway3D/PersonaliseIt/Model/Product/Rating.php +70 -0
  17. app/code/local/Gateway3D/PersonaliseIt/Model/Resource/Eav/Mysql4/Setup.php +279 -0
  18. app/code/local/Gateway3D/PersonaliseIt/Model/Source/Orderstatus.php +19 -0
  19. app/code/local/Gateway3D/PersonaliseIt/Model/Status/Callback.php +91 -0
  20. app/code/local/Gateway3D/PersonaliseIt/controllers/CppController.php +23 -0
  21. app/code/local/Gateway3D/PersonaliseIt/controllers/ProductController.php +157 -0
  22. app/code/local/Gateway3D/PersonaliseIt/controllers/ProductsController.php +21 -0
  23. app/code/local/Gateway3D/PersonaliseIt/controllers/StatusController.php +52 -0
  24. app/code/local/Gateway3D/PersonaliseIt/etc/config.xml +165 -0
  25. app/code/local/Gateway3D/PersonaliseIt/etc/system.xml +130 -0
  26. app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-install-1.0.0.php +5 -0
  27. app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.0.0-1.1.0.php +122 -0
  28. app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.1.1-1.1.2.php +20 -0
  29. app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.1.7.1-1.2.0.0.php +5 -0
  30. app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.2.0.3-1.3.0.0.php +26 -0
  31. app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.3.5.4-1.3.6.0.php +26 -0
  32. app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.3.6.0-1.4.0.0.php +49 -0
  33. app/design/adminhtml/default/default/template/personaliseit/catalog/product/edit/options.phtml +60 -0
  34. app/design/adminhtml/default/default/template/personaliseit/item_column_renderer_name.phtml +30 -0
  35. app/design/adminhtml/default/default/template/personaliseit/option.phtml +370 -0
  36. app/design/frontend/base/default/layout/personaliseit.xml +71 -0
  37. app/design/frontend/base/default/template/personaliseit/cart/item/default.phtml +299 -0
  38. app/design/frontend/base/default/template/personaliseit/product/callback.phtml +15 -0
  39. app/design/frontend/base/default/template/personaliseit/product/view/addtocart.phtml +42 -0
  40. app/design/frontend/base/default/template/personaliseit/product/view/media.phtml +218 -0
  41. app/design/frontend/base/default/template/personaliseit/products/index.phtml +48 -0
  42. app/etc/modules/Gateway3D_PersonaliseIt.xml +19 -0
  43. js/personalise-it/delayed-preview.js +87 -0
  44. lib/Gateway3D/PersonaliseIt/Service/Api/Abstract.php +179 -0
  45. lib/Gateway3D/PersonaliseIt/Service/Api/P1/Product.php +38 -0
  46. lib/Gateway3D/PersonaliseIt/Service/Api/P1/Sample.php +38 -0
  47. lib/Gateway3D/PersonaliseIt/Service/Api/P2/PrintJob.php +51 -0
  48. lib/Gateway3D/PersonaliseIt/Service/Api/Sl/Order.php +42 -0
  49. lib/Gateway3D/PersonaliseIt/Service/Dto/Abstract.php +17 -0
  50. lib/Gateway3D/PersonaliseIt/Service/Dto/Interface.php +15 -0
  51. lib/Gateway3D/PersonaliseIt/Service/Dto/P1/Product.php +26 -0
  52. lib/Gateway3D/PersonaliseIt/Service/Dto/P1/Sample.php +25 -0
  53. lib/Gateway3D/PersonaliseIt/Service/Dto/P2/PrintJob.php +27 -0
  54. lib/Gateway3D/PersonaliseIt/Service/Dto/Sl/Order.php +79 -0
  55. lib/Gateway3D/PersonaliseIt/Service/Dto/Sl/Order/Item.php +45 -0
  56. package.xml +26 -0
app/code/local/Gateway3D/PersonaliseIt/Block/Adminhtml/Catalog/Product/Edit/Tab/Options.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Gateway3D_PersonaliseIt_Block_Adminhtml_Catalog_Product_Edit_Tab_Options
4
+ extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options
5
+ {
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+
10
+ $this->setTemplate('personaliseit/catalog/product/edit/options.phtml');
11
+ }
12
+
13
+ protected function _prepareLayout()
14
+ {
15
+ $this->setChild('import_from_cpp_button',
16
+ $this->getLayout()->createBlock('adminhtml/widget_button')
17
+ ->setData(array(
18
+ 'label' => Mage::helper('catalog')->__('Import From Gateway CPP'),
19
+ 'class' => 'add',
20
+ 'id' => 'import_from_cpp_button'
21
+ ))
22
+ );
23
+
24
+ return parent::_prepareLayout();
25
+ }
26
+
27
+ public function getImportFromCppButtonHtml()
28
+ {
29
+ return $this->getChildHtml('import_from_cpp_button');
30
+ }
31
+ }
app/code/local/Gateway3D/PersonaliseIt/Block/Adminhtml/Catalog/Product/Edit/Tab/Options/Option.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option
11
+ extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option
12
+ {
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+ $this->setTemplate('personaliseit/option.phtml');
17
+ }
18
+
19
+ public function getImportFromCppButtonId()
20
+ {
21
+ $buttonId = $this
22
+ ->getLayout()
23
+ ->getBlock('admin.product.options')
24
+ ->getChild('import_from_cpp_button')->getId();
25
+
26
+ return $buttonId;
27
+ }
28
+ }
app/code/local/Gateway3D/PersonaliseIt/Block/Product/View/Options.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Block_Product_View_Options
11
+ extends Mage_Catalog_Block_Product_View_Options
12
+ {
13
+ public function getOptionHtml(Mage_Catalog_Model_Product_Option $option)
14
+ {
15
+ return $option->getType() == Gateway3D_PersonaliseIt_Model_Catalog_Product_Option::OPTION_TYPE_HIDDEN
16
+ ? ""
17
+ : parent::getOptionHtml($option);
18
+ }
19
+ }
app/code/local/Gateway3D/PersonaliseIt/Helper/Data.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2013 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Helper_Data
11
+ extends Mage_Core_Helper_Data
12
+ {
13
+ public function reduceUrlSlashes($url)
14
+ {
15
+ return preg_replace('/(?<!:)\/\//', '/', $url);
16
+ }
17
+ }
app/code/local/Gateway3D/PersonaliseIt/Helper/MessageEvent.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Helper_MessageEvent
11
+ {
12
+ private $_id;
13
+
14
+ public function getId()
15
+ {
16
+ if(!$this->_id)
17
+ {
18
+ $this->_id = md5(uniqid());
19
+ }
20
+
21
+ return $this->_id;
22
+ }
23
+
24
+ public function getOrigin($uri)
25
+ {
26
+ $parsed = parse_url($uri);
27
+
28
+ if(!isset($parsed['host']))
29
+ {
30
+ return "";
31
+ }
32
+
33
+ if(!isset($parsed['scheme']))
34
+ {
35
+ $parsed['scheme'] = Mage::app()->getStore()->isCurrentlySecure()
36
+ ? 'https'
37
+ : 'http';
38
+ }
39
+
40
+ return "{$parsed['scheme']}://{$parsed['host']}";
41
+ }
42
+ }
app/code/local/Gateway3D/PersonaliseIt/Helper/ProductCustomOptions.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Helper_ProductCustomOptions
11
+ {
12
+ public static function ensureProductHasCustomOptions(Mage_Catalog_Model_Product $product, $required = array())
13
+ {
14
+ // Compatability hack for older Magentos
15
+ if(!class_exists('Mage_Catalog_Model_Product_Option_Api'))
16
+ {
17
+ return;
18
+ }
19
+
20
+ // determine if the product has the required custom options
21
+ $options = $product->getOptions();
22
+ $coSkus = array_map(function($o) { return $o->getSku(); }, $options);
23
+ $coTitles = array_map(function($o) { return $o->getTitle(); }, $options);
24
+ $coSkusAndTitles = $coSkus + $coTitles;
25
+
26
+ $missing = array_unique(array_diff($required, $coSkusAndTitles));
27
+
28
+ // create missing options
29
+ foreach($missing as $sku)
30
+ {
31
+ $optionData = array(
32
+ 'title' => $sku,
33
+ 'type' => Gateway3D_PersonaliseIt_Model_Catalog_Product_Option::OPTION_TYPE_HIDDEN,
34
+ 'is_require' => false,
35
+ 'sort_order' => 1,
36
+ 'additional_fields' => array(array(
37
+ 'price' => 0,
38
+ 'price_type' => 'fixed',
39
+ 'sku' => $sku
40
+ ))
41
+ );
42
+
43
+ self::addOption($product, $optionData);
44
+ }
45
+
46
+ // reload
47
+ $product->load($product->getId());
48
+
49
+ return array_values(array_filter($product->getOptions(), function($o) use ($required)
50
+ {
51
+ return in_array($o->getSku(), $required);
52
+ }));
53
+ }
54
+
55
+ static function addOption(Mage_Catalog_Model_Product $product, array $optionData)
56
+ {
57
+ // HACK:
58
+ //
59
+ // Magento seems to only let you change product custom options
60
+ // if it thinks that we are in the backend.
61
+ //
62
+ // See Mage_Catalog_Model_Product::getOrigData
63
+
64
+ $id = Mage::app()->getStore()->getId();
65
+ Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
66
+
67
+ $m = new Mage_Catalog_Model_Product_Option_Api;
68
+ $m->add($product->getId(), $optionData);
69
+
70
+ Mage::app()->getStore()->setId($id);
71
+
72
+ // HACK:
73
+ //
74
+ // Magento versions older than 1.8 seem to require us to
75
+ // explictly reset the product options array otherwise
76
+ // options will be added multiple times the next time we
77
+ // try to add one.
78
+ //
79
+ // Presumably 1.8 and above call this line somewhere down
80
+ // in the call chain of Mage_Catalog_Model_Product_Option_Api.
81
+
82
+ $product->getOptionInstance()
83
+ ->setProduct($product)
84
+ ->setOptions(array());
85
+
86
+ }
87
+
88
+ static function update(Mage_Catalog_Model_Product_Option $option, array $data)
89
+ {
90
+ $id = Mage::app()->getStore()->getId();
91
+ Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
92
+
93
+ $m = new Mage_Catalog_Model_Product_Option_Api;
94
+ $m->update($option->getId(), $data);
95
+
96
+ Mage::app()->getStore()->setId($id);
97
+ }
98
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Catalog/Product/Option.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Model_Catalog_Product_Option
11
+ extends Mage_Catalog_Model_Product_Option
12
+ {
13
+ const OPTION_GROUP_HIDDEN = 'hidden';
14
+ const OPTION_TYPE_HIDDEN = 'hidden';
15
+
16
+ public function getGroupByType($type = null)
17
+ {
18
+ if (is_null($type)) {
19
+ $type = $this->getType();
20
+ }
21
+
22
+ if($type === self::OPTION_TYPE_HIDDEN)
23
+ {
24
+ return self::OPTION_GROUP_HIDDEN;
25
+ }
26
+ else
27
+ {
28
+ return parent::getGroupByType($type);
29
+ }
30
+ }
31
+
32
+ public function groupFactory($type)
33
+ {
34
+ if($type === self::OPTION_TYPE_HIDDEN)
35
+ {
36
+ return Mage::getModel('personaliseit/catalog_product_option_type_hidden');
37
+ }
38
+ else
39
+ {
40
+ return parent::groupFactory($type);
41
+ }
42
+ }
43
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Catalog/Product/Option/Type/Hidden.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Model_Catalog_Product_Option_Type_Hidden
11
+ extends Mage_Catalog_Model_Product_Option_Type_Text
12
+ { }
app/code/local/Gateway3D/PersonaliseIt/Model/Cron/Abstract.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Gateway3D_PersonaliseIt_Model_Cron_Abstract
4
+ {
5
+ const PRINT_JOB_ID_CUSTOM_OPTION_SKU = "printJobId";
6
+ const EXTERNAL_URL_CUSTOM_OPTION_SKU = "external_url";
7
+
8
+ protected static function _getOrderCollection()
9
+ {
10
+ return Mage::getResourceModel('sales/order_collection')
11
+ ->addAttributeToSelect('*')
12
+
13
+ // Include orders that have been completed because
14
+ // orders with 100% discount codes go straight to
15
+ // complete and bypass processing.
16
+ ->addFieldToFilter('status', array(
17
+ array('eq' => Mage_Sales_Model_Order::STATE_PROCESSING),
18
+ array('eq' => Mage_Sales_Model_Order::STATE_COMPLETE))
19
+ )
20
+
21
+ ->addFieldToFilter('sent', 0)
22
+ ->addOrder('created_at', 'desc');
23
+ }
24
+
25
+ protected static function _getItemPrintJobId($storeId, Mage_Sales_Model_Order_Item $item)
26
+ {
27
+ return (int)self::_getItemCustomOption($storeId, $item, self::PRINT_JOB_ID_CUSTOM_OPTION_SKU);
28
+ }
29
+
30
+ protected static function _getItemExternalUrl($storeId, Mage_Sales_Model_Order_Item $item)
31
+ {
32
+ return self::_getItemCustomOption($storeId, $item, self::EXTERNAL_URL_CUSTOM_OPTION_SKU);
33
+ }
34
+
35
+ protected static function _getItemCustomOption($storeId, Mage_Sales_Model_Order_Item $item, $sku)
36
+ {
37
+ $options = self::_getItemProduct($storeId, $item)->getOptions();
38
+
39
+ foreach($options as $option)
40
+ {
41
+ if($option->getSku() == $sku)
42
+ {
43
+ $id = $option->getId();
44
+ }
45
+ }
46
+
47
+ if(isset($id) && $id)
48
+ {
49
+ $options = $item->getProductOptions();
50
+ $options = $options['options'];
51
+
52
+ foreach($options as $option)
53
+ {
54
+ if($option['option_id'] == $id)
55
+ {
56
+ return $option['value'];
57
+ }
58
+ }
59
+ }
60
+
61
+ return null;
62
+ }
63
+
64
+ protected static function _log($message)
65
+ {
66
+ $message = "SL :: {$message}";
67
+
68
+ if(getenv('LOG_TO_STDOUT'))
69
+ {
70
+ echo "{$message}\n";
71
+ }
72
+
73
+ Mage::log($message);
74
+ }
75
+
76
+ /**
77
+ * Load a product.
78
+ *
79
+ * @param int $storeId
80
+ * @param Mage_Sales_Model_Order_Item $item
81
+ * @return Mage_Catalog_Model_Product
82
+ */
83
+ protected static function _getItemProduct($storeId, Mage_Sales_Model_Order_Item $item)
84
+ {
85
+ return Mage::getModel('catalog/product')
86
+ ->setStoreId($storeId)
87
+ ->load($item->getProductId());
88
+ }
89
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Cron/DelayedPrintJob.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ /**
11
+ * Cron class that is responsible for creating print jobs for any delayed preview
12
+ * products that have been purchased but don't yet have a print job ID.
13
+ */
14
+ class Gateway3D_PersonaliseIt_Model_Cron_DelayedPrintJob
15
+ extends Gateway3D_PersonaliseIt_Model_Cron_Abstract
16
+ {
17
+ const PRINT_JOB_ID_CUSTOM_OPTION_SKU = "printJobId";
18
+
19
+ /**
20
+ * @var Gateway3D_PersonaliseIt_Service_Api2_PrintJob
21
+ */
22
+ private $_api;
23
+
24
+ public function start()
25
+ {
26
+ self::_log("Personalise-iT Delayed Print Job Cron Started");
27
+
28
+ $this->_initApi();
29
+ $this->_push();
30
+
31
+ self::_log("Finished");
32
+ }
33
+
34
+ private function _initApi()
35
+ {
36
+ $path = Mage::getStoreConfig("general/personaliseit-delayed-preview/api_path");
37
+
38
+ if($path)
39
+ {
40
+ $this->_api = new Gateway3D_PersonaliseIt_Service_Api_P2_PrintJob($path);
41
+ }
42
+ else
43
+ {
44
+ Mage::throwException('No delayed preview API path set');
45
+ }
46
+ }
47
+
48
+ private function _push()
49
+ {
50
+ $collection = self::_getOrderCollection();
51
+
52
+ foreach($collection as $order)
53
+ {
54
+ $this->_pushOrder($order);
55
+ }
56
+
57
+ if(!count($collection))
58
+ {
59
+ self::_log("Nothing to do");
60
+ }
61
+ }
62
+
63
+ private function _pushOrder(Mage_Sales_Model_Order $order)
64
+ {
65
+ $items = $order->getAllVisibleItems();
66
+
67
+ foreach($items as $item)
68
+ {
69
+ $storeId = $order->getStoreId();
70
+ $product = self::_getItemProduct($storeId, $item);
71
+
72
+ if($product->personaliseit_dp_enabled && !self::_getItemPrintJobId($storeId, $item))
73
+ {
74
+ self::_log("Attemping to create print job for {$order->getIncrementId()}/{$item->getId()}");
75
+
76
+ $printJobId = $this->_pushPrintJob($item, $product);
77
+
78
+ $required = array(self::PRINT_JOB_ID_CUSTOM_OPTION_SKU);
79
+
80
+ $requiredOptions = Gateway3D_PersonaliseIt_Helper_ProductCustomOptions::ensureProductHasCustomOptions($product, $required);
81
+ $printJobOption = $requiredOptions[0];
82
+
83
+ $itemOptions = $item->getProductOptions();
84
+ $itemOptions['options'][] = array(
85
+ 'label' => $printJobOption->getTitle(),
86
+ 'value' => $printJobId,
87
+ 'option_id' => $printJobOption->getId(),
88
+ );
89
+
90
+ $item->setProductOptions($itemOptions);
91
+ $item->save();
92
+
93
+ self::_log("PJ: {$printJobId}");
94
+ }
95
+ }
96
+ }
97
+
98
+ private function _pushPrintJob(Mage_Sales_Model_Order_Item $item, Mage_Catalog_Model_Product $product)
99
+ {
100
+ $printJob = $this->_createPrintJob($item, $product);
101
+
102
+ $this->_api->create($printJob, $options = array(
103
+ Gateway3D_PersonaliseIt_Service_Api_P2_PrintJob::OPTION_IMPLICIT => true
104
+ ));
105
+
106
+ return $printJob->print_job_id;
107
+ }
108
+
109
+ private function _createPrintJob(Mage_Sales_Model_Order_Item $item, Mage_Catalog_Model_Product $product)
110
+ {
111
+ $printJob = new Gateway3D_PersonaliseIt_Service_Dto_P2_PrintJob;
112
+
113
+ $printJob->product_id = $product->personaliseit_dp_pid;
114
+ $printJob->print_job_company_id = $product->personaliseit_company_ref_id;
115
+ $printJob->items = array();
116
+
117
+ // Create text items
118
+ $options = $product->getOptions();
119
+ $itemOptions = $item->getProductOptionByCode('options');
120
+
121
+ foreach($options as $option)
122
+ {
123
+ $matches = array();
124
+
125
+ if(preg_match('/^userText([0-9]*)$/', $option->getSku(), $matches) && count($matches) == 2)
126
+ {
127
+ foreach($itemOptions as $itemOption)
128
+ {
129
+ if($itemOption['option_id'] == $option->getId())
130
+ {
131
+ $printJob->items[] = array(
132
+ 'area_id' => $matches[1],
133
+
134
+ 'item_type' => 'TEXT_AREA',
135
+ 'resources' => $itemOption['value']
136
+ );
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ return $printJob;
143
+ }
144
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Cron/Sl.php ADDED
@@ -0,0 +1,623 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ /**
11
+ * Cron class that is responsible for inserting orders into the Gateway3D
12
+ * Order-iT system using the Supplier Link API.
13
+ */
14
+ class Gateway3D_PersonaliseIt_Model_Cron_Sl
15
+ extends Gateway3D_PersonaliseIt_Model_Cron_Abstract
16
+ {
17
+ /**
18
+ * @var Gateway3D_PersonaliseIt_Service_Api_Sl_Order
19
+ */
20
+ private $_api;
21
+
22
+ public function start()
23
+ {
24
+ self::_log("Personalise-iT SL Cron Started");
25
+
26
+ $this->_checkOtherSupplierLinks();
27
+ $this->_initApi();
28
+
29
+ $this->_push();
30
+
31
+ if(Mage::getStoreConfig("general/personaliseit-sl/enable_order_status_polling"))
32
+ {
33
+ $this->_pull();
34
+ }
35
+
36
+ self::_log("Finished");
37
+ }
38
+
39
+ /**
40
+ * Pushes all possible Magento orders via the Supplier Link API.
41
+ */
42
+ private function _push()
43
+ {
44
+ $collection = self::_getOrderCollection();
45
+
46
+ foreach($collection as $order)
47
+ {
48
+ $this->_pushMageOrder($order);
49
+ }
50
+
51
+ if(!count($collection))
52
+ {
53
+ self::_log("Nothing to push");
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Pulls statuses from the Supplier Link API for all possible Magento orders.
59
+ */
60
+ private function _pull()
61
+ {
62
+ $collection = Mage::getResourceModel('sales/order_collection')
63
+ ->addAttributeToSelect('*')
64
+ ->addFieldToFilter('shipped', 0)
65
+ ->addFieldToFilter('sent', 1)
66
+ ->addOrder('created_at', 'desc');
67
+
68
+ foreach($collection as $order)
69
+ {
70
+ $this->_pullMageOrder($order);
71
+ }
72
+
73
+ if(!count($collection))
74
+ {
75
+ self::_log("Nothing to pull");
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Push a single Magento order through the Supplier Link API.
81
+ *
82
+ * @param Mage_Sales_Model_Order $order
83
+ */
84
+ private function _pushMageOrder(Mage_Sales_Model_Order $order)
85
+ {
86
+ self::_log("Pushing {$order->getIncrementId()}");
87
+
88
+ $items = $order->getAllVisibleItems();
89
+
90
+ // Check that any delayed preview items have had a print job generated
91
+ if(!$this->_doAllDelayedPreviewItemsHavePrintJobIds($order, $items))
92
+ {
93
+ $message = "Order has a delayed preview item that does not yet have a print job ID";
94
+
95
+ self::_log($message);
96
+ $order->addStatusHistoryComment("Personalise-iT: {$message}");
97
+ $order->save();
98
+
99
+ return;
100
+ }
101
+
102
+ //
103
+ $groupedItems = $this->_createSlOrderItems($order->getStoreId(), $items);
104
+
105
+ if(!count($groupedItems))
106
+ {
107
+ self::_log("All items have already been sent");
108
+ }
109
+
110
+ $slIds = array();
111
+
112
+ // Now we create an order for each company ref ID grouping.
113
+ foreach($groupedItems as $guid => $itemPairs)
114
+ {
115
+ // Extract all SL order items from the item pairs.
116
+ $_items = array();
117
+
118
+ foreach($itemPairs as $itemPair)
119
+ {
120
+ $_items[] = $itemPair[1];
121
+ }
122
+
123
+ // Create an SL order
124
+ $_order = $this->_createSlOrder($order, $guid, $_items);
125
+
126
+ try
127
+ {
128
+ $this->_api->create($_order);
129
+
130
+ // Update Magento order items
131
+ foreach($itemPairs as $itemPair)
132
+ {
133
+ $itemPair[0]->sl_order_id = $_order->id;
134
+ $itemPair[0]->save();
135
+ }
136
+
137
+ $order->addStatusHistoryComment("Personalise-iT Order Ref: {$_order->ref} ({$guid})");
138
+ $order->save();
139
+
140
+ self::_log("Pushed {$order->getIncrementId()} -> {$guid}, id:{$_order->id}, ref:{$_order->ref}");
141
+ }
142
+ catch(Exception $e)
143
+ {
144
+ $message = "Personalise-iT Error: {$e->getMessage()} ({$guid})";
145
+
146
+ $order->addStatusHistoryComment($message);
147
+
148
+ // don't retry the order later
149
+ $order->sent = 1;
150
+
151
+ $order->save();
152
+
153
+ self::_log($message);
154
+
155
+ // bail out
156
+ return;
157
+
158
+ }
159
+ }
160
+
161
+ // Update the magento order
162
+ $order->sent = 1;
163
+ $order->save();
164
+ }
165
+
166
+ /**
167
+ * Determines whether an order's delayed preview items ALL have print job IDs.
168
+ *
169
+ * @param Mage_Sales_Model_Order $order
170
+ * @param array $items
171
+ * @return boolean True if all delayed preview items have print job IDs.
172
+ */
173
+ private function _doAllDelayedPreviewItemsHavePrintJobIds(Mage_Sales_Model_Order $order, array $items)
174
+ {
175
+ foreach($items as $item)
176
+ {
177
+ $storeId = $order->getStoreId();
178
+ $product = self::_getItemProduct($storeId, $item);
179
+
180
+ if($product->personaliseit_dp_enabled && !self::_getItemPrintJobId($storeId, $item))
181
+ {
182
+ return false;
183
+ }
184
+ }
185
+
186
+ return true;
187
+ }
188
+
189
+
190
+ /**
191
+ * Creates a collection of SL order items from their Magento order item
192
+ * counterparts, grouped by company.
193
+ *
194
+ * @param Mage_Sales_Model_Order_Item[] $items
195
+ * @return Gateway3D_PersonaliseIt_Model_Sl_Data_Order_Item[]
196
+ */
197
+ private function _createSlOrderItems($storeId, array $items)
198
+ {
199
+ $groupedItems = array();
200
+
201
+ foreach($items as $item)
202
+ {
203
+ $product = self::_getItemProduct($storeId, $item);
204
+
205
+ // We only send the item if:
206
+ //
207
+ // 1) The item has a print job ID custom option, or,
208
+ // 2) The item's product has a POD sample ref set.
209
+ // 3) The item is has plain stock set to 'Yes'
210
+ //
211
+ // AND
212
+ //
213
+ // 4) The item has not already been sent
214
+
215
+ $printJobId = self::_getItemPrintJobId($storeId, $item);
216
+ $externalUrl = self::_getItemExternalUrl($storeId, $item);
217
+
218
+ $sampleRef = $product->personaliseit_pod_ref;
219
+ $isPlain = $product->personaliseit_is_plain;
220
+
221
+ if(($printJobId || $externalUrl || $sampleRef || $isPlain) && !$item->sl_order_id)
222
+ {
223
+ // We also need to group the item by the product's company ref ID.
224
+ $guid = $product->personaliseit_company_ref_id;
225
+
226
+ if(!isset($groupedItems[$guid]))
227
+ {
228
+ $groupedItems[$guid] = array();
229
+ }
230
+
231
+ $groupedItems[$guid][] = array($item, $this->_createSlItem($storeId, $item, $printJobId, $externalUrl, $sampleRef));
232
+ }
233
+ }
234
+
235
+ return $groupedItems;
236
+ }
237
+
238
+ /**
239
+ * Creates a single SL order item from a Magento order item.
240
+ *
241
+ * @param Mage_Sales_Model_Order_Item $item
242
+ * @param string $printJobId
243
+ * @param string $externalUrl
244
+ * @param string $sampleRef
245
+ * @return \Gateway3D_PersonaliseIt_Model_Sl_Data_Order_Item
246
+ */
247
+ private function _createSlItem($storeId, Mage_Sales_Model_Order_Item $item, $printJobId, $externalUrl, $sampleRef)
248
+ {
249
+ $product = self::_getItemProduct($storeId, $item);
250
+
251
+ $_item = new Gateway3D_PersonaliseIt_Service_Dto_Sl_Order_Item;
252
+
253
+ if($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
254
+ {
255
+ $_item->description = $item->getName();
256
+ $_item->sku = $item->getSku();
257
+ }
258
+ else
259
+ {
260
+ $_item->description = $product->getName();
261
+ $_item->sku = $product->getSku();
262
+ }
263
+
264
+ $_item->quantity = $item->getQtyOrdered();
265
+ $_item->print_job_id = $printJobId;
266
+ $_item->print_on_demand_ref = $sampleRef;
267
+ $_item->external_ref = "{$item->getOrder()->getIncrementId()}-{$item->getId()}";
268
+ $_item->unit_sale_price = $item->getOriginalPrice();
269
+
270
+ //
271
+ $options = array_merge(
272
+ $item->getProductOptionByCode('attributes_info') ?: array(),
273
+ $item->getProductOptionByCode('options'));
274
+
275
+ if($options)
276
+ {
277
+ foreach($options as $option)
278
+ {
279
+ $name = strtolower($option['label']);
280
+
281
+ if($name == 'color' || $name == 'colour' || $name == 'size')
282
+ {
283
+ $name = $name == 'color' ? 'colour' : $name;
284
+
285
+ $_item->{$name} = $option['value'];
286
+ }
287
+ }
288
+ }
289
+
290
+ //
291
+ $attributes = $this->_getInterestingItemAttributes($storeId, $item, $product);
292
+
293
+ foreach($attributes as $name => $value)
294
+ {
295
+ $_item->{$name} = $value;
296
+ }
297
+
298
+ //
299
+ if($printJobId)
300
+ {
301
+ $_item->type = Gateway3D_PersonaliseIt_Service_Dto_Sl_Order_Item::TYPE_PRINT_JOB;
302
+ }
303
+ else if($externalUrl)
304
+ {
305
+ $_item->type = Gateway3D_PersonaliseIt_Service_Dto_Sl_Order_Item::TYPE_EXTERNAL_URL;
306
+ $_item->external_url = $externalUrl;
307
+ $_item->external_thumbnail_url = $externalUrl;
308
+ }
309
+ else if($sampleRef)
310
+ {
311
+ $_item->type = Gateway3D_PersonaliseIt_Service_Dto_Sl_Order_Item::TYPE_PRINT_ON_DEMAND;
312
+ }
313
+ else
314
+ {
315
+ $_item->type = Gateway3D_PersonaliseIt_Service_Dto_Sl_Order_Item::TYPE_PLAIN;
316
+
317
+ list($_item->external_url, $_item->external_thumbnail_url) = $this->_resolveItemImages($item, $product);
318
+ }
319
+
320
+ return $_item;
321
+ }
322
+
323
+ /**
324
+ * Gets any attributes from the item that we're interested in (i.e. colour and size).
325
+ *
326
+ * @param int $storeId
327
+ * @param Mage_Sales_Model_Order_Item $item
328
+ * @param Mage_Catalog_Model_Product $product
329
+ * @return array
330
+ */
331
+ private function _getInterestingItemAttributes($storeId, Mage_Sales_Model_Order_Item $item, Mage_Catalog_Model_Product $product)
332
+ {
333
+ // For configurable products, we need to get the attributes from the
334
+ // relavent simple.
335
+ if($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
336
+ {
337
+ $children = $item->getChildrenItems();
338
+
339
+ if(count($children))
340
+ {
341
+ $product = self::_getItemProduct($storeId, $children[0]);
342
+ }
343
+ }
344
+
345
+ $attributes = $product->getAttributes();
346
+ $flatAttributes = array();
347
+
348
+ foreach($attributes as $attribute)
349
+ {
350
+ $name = $attribute->getName();
351
+
352
+ if($name == 'color' || $name == 'colour' || $name == 'size')
353
+ {
354
+ // Force UK spellings
355
+ $name = $name == 'color' ? 'colour' : $name;
356
+
357
+ $flatAttributes[$name] = $attribute->getFrontend()->getValue($product);
358
+
359
+ // Magento will return "No" if an attribute exists on a product but is not
360
+ // set. Therefore lets try and filter them out
361
+ if($flatAttributes[$name] == Mage::helper('personaliseit')->__('No'))
362
+ {
363
+ unset($flatAttributes[$name]);
364
+ }
365
+ }
366
+ }
367
+
368
+ return $flatAttributes;
369
+ }
370
+
371
+ /**
372
+ * Resolves the images to use for a plain stock item.
373
+ *
374
+ * @param Mage_Sales_Model_Order_Item $item
375
+ * @param Mage_Catalog_Model_Product $product
376
+ * @return array($imageUrl, $thumbnailUrl)
377
+ */
378
+ private function _resolveItemImages(Mage_Sales_Model_Order_Item $item, Mage_Catalog_Model_Product $product)
379
+ {
380
+ $isConfigurable = $product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
381
+
382
+ $configKey = Mage_Checkout_Block_Cart_Item_Renderer_Configurable::CONFIGURABLE_PRODUCT_IMAGE;
383
+ $useParentImage = Mage::getStoreConfig($configKey) == Mage_Checkout_Block_Cart_Item_Renderer_Configurable::USE_PARENT_IMAGE;
384
+
385
+ $children = $item->getChildrenItems();
386
+
387
+ if($isConfigurable && !$useParentImage && count($children))
388
+ {
389
+ $child = $children[0]->getProduct();
390
+ $thumbnail = $child->getData('thumbnail');
391
+
392
+ if($thumbnail && $thumbnail != 'no_selection')
393
+ {
394
+ $product = $child;
395
+ }
396
+ }
397
+
398
+ return array(
399
+ $product->getImageUrl(),
400
+ $product->getThumbnailUrl(100, 100)
401
+ );
402
+ }
403
+
404
+ /**
405
+ * Creates a single SL order from a Magento order.
406
+ *
407
+ * @param Mage_Sales_Model_Order $order
408
+ * @param string $companyRefId
409
+ * @param Gateway3D_PersonaliseIt_Model_Sl_Data_Order_Item[] $items
410
+ * @return \Gateway3D_PersonaliseIt_Model_Sl_Data_Order
411
+ */
412
+ private function _createSlOrder(Mage_Sales_Model_Order $order, $companyRefId, array $items)
413
+ {
414
+ $shippingAddress = $order->getShippingAddress();
415
+ $billingAddress = $order->getBillingAddress();
416
+
417
+ $store = Mage::app()->getStore($order->getStoreId())->getWebsite()->getName();
418
+
419
+ //
420
+ $_order = new Gateway3D_PersonaliseIt_Service_Dto_Sl_Order;
421
+
422
+ $_order->additional_info = php_uname('n') . " :: " . $store;
423
+
424
+ $this->_setAddressFields($_order, $billingAddress, "billing_address");
425
+
426
+ $_order->billing_country = trim($billingAddress->getCountry());
427
+ $_order->billing_postcode = trim($billingAddress->getPostcode());
428
+
429
+ $this->_setAddressFields($_order, $shippingAddress, "shipping_address");
430
+
431
+ $_order->shipping_country = trim($shippingAddress->getCountry());
432
+ $_order->shipping_country_code = $shippingAddress->getCountryModel()->getIso2Code();
433
+ $_order->shipping_postcode = trim($shippingAddress->getPostcode());
434
+
435
+ list($carrier, $method) = explode(' - ', $order->getShippingDescription());
436
+
437
+ $_order->shipping_carrier = $carrier;
438
+ $_order->shipping_method = $method;
439
+
440
+ $_order->customer_email = $order->getCustomerEmail();
441
+ $_order->customer_name = $shippingAddress->getName();
442
+
443
+ $_order->external_ref = $order->getIncrementId();
444
+
445
+ $order->getCreatedAtDate()->setOptions(array('format_type' => 'php'));
446
+ $_order->sale_datetime = $order->getCreatedAtDate()->toString("Y-m-d H:i:s");
447
+
448
+ $_order->purchase_complete = 1;
449
+ $_order->payment_type = $order->getPayment()->getMethodInstance()->getTitle();
450
+
451
+ $_order->company_ref_id = $companyRefId;
452
+
453
+ $_order->status = Mage::getStoreConfig("general/personaliseit-sl/default_order_status");
454
+
455
+ if(!Mage::getStoreConfig("general/personaliseit-sl/enable_order_status_polling"))
456
+ {
457
+ $_order->status_callback_url = $this->_createSlOrderStatusCallbackUrl($order);
458
+ }
459
+
460
+ $_order->items = $items;
461
+
462
+ return $_order;
463
+ }
464
+
465
+ private function _setAddressFields(
466
+ Gateway3D_PersonaliseIt_Service_Dto_Sl_Order $order,
467
+ Mage_Customer_Model_Address_Abstract $address,
468
+ $fieldPrefix)
469
+ {
470
+ $lines = $address->getStreet();
471
+ array_unshift($lines, $address->getCompany());
472
+ array_push($lines, $address->getCity());
473
+ array_push($lines, $address->getRegion());
474
+
475
+ for($i = 0; $i < count($lines) && $i < 5; $i++)
476
+ {
477
+ if($lines[$i])
478
+ {
479
+ $_i = $i + 1;
480
+ $key = "{$fieldPrefix}_{$_i}";
481
+
482
+ $order->{$key} = trim($lines[$i]);
483
+ }
484
+ }
485
+ }
486
+
487
+ private function _createSlOrderStatusCallbackUrl(Mage_Sales_Model_Order $order)
488
+ {
489
+ $ref = sha1(uniqid(time(), true));
490
+
491
+ $order->status_callback_ref = $ref;
492
+
493
+ $url = Mage::getUrl('personaliseit/status/callback/', array(
494
+ '_store' => $order->getStoreId(),
495
+ 'ref' => $ref
496
+ ));
497
+
498
+ return $url;
499
+ }
500
+
501
+ /**
502
+ *
503
+ *
504
+ * @param Mage_Sales_Model_Order $order
505
+ */
506
+ private function _pullMageOrder(Mage_Sales_Model_Order $order)
507
+ {
508
+ self::_log("Pulling {$order->getIncrementId()}");
509
+
510
+ // First we need to get all of the SL order ids that might have been
511
+ // associated with this Magento order.
512
+ $items = $order->getAllVisibleItems();
513
+
514
+ $slOrderIds = array();
515
+
516
+ foreach($items as $item)
517
+ {
518
+ if($item->sl_order_id)
519
+ {
520
+ $slOrderIds[] = (int)$item->sl_order_id;
521
+ }
522
+ else
523
+ {
524
+ // Bail out early because the order has items that have not been
525
+ // sent via the SL API thus we can't accurately say whether the
526
+ // order should be shipped.
527
+
528
+ return;
529
+ }
530
+ }
531
+
532
+ $slOrderIds = array_unique($slOrderIds);
533
+
534
+ //
535
+ $dispatched = 0;
536
+ $dispatchedStatuses = array(
537
+ Gateway3D_PersonaliseIt_Service_Dto_Sl_Order::STATUS_DISPATCHED,
538
+ Gateway3D_PersonaliseIt_Service_Dto_Sl_Order::STATUS_SUPPLIER_DISPATCHED_NOTIFIED
539
+ );
540
+
541
+ // We nw retrieve the status of each SL order. If they have all been
542
+ // dispatched then we can ship the Mage order.
543
+ foreach($slOrderIds as $id)
544
+ {
545
+ $_order = new Gateway3D_PersonaliseIt_Service_Dto_Sl_Order;
546
+ $_order->id = $id;
547
+
548
+ $this->_api->retrieve($_order);
549
+
550
+ if(in_array($_order->status, $dispatchedStatuses))
551
+ {
552
+ $dispatched++;
553
+ }
554
+ }
555
+
556
+ //
557
+ if($dispatched == count($items))
558
+ {
559
+ $this->_ship($order);
560
+ }
561
+ }
562
+
563
+ private function _ship(Mage_Sales_Model_Order $order)
564
+ {
565
+ if(!$order->canShip())
566
+ {
567
+ self::_log("Order {$order->getIncrementId()} cannot be shipped");
568
+ }
569
+ else
570
+ {
571
+ $qtys = array();
572
+
573
+ foreach($order->getAllItems() as $item)
574
+ {
575
+ $qtys[$item->getId()] = $item->getQtyToShip();
576
+ }
577
+
578
+ $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($qtys);
579
+
580
+ $shipment->register();
581
+
582
+ $shipment->setEmailSent(true);
583
+
584
+ $shipment->getOrder()->setCustomerNoteNotify(true);
585
+
586
+ $shipment->getOrder()->setIsInProcess(true);
587
+
588
+ $transactionSave = Mage::getModel('core/resource_transaction')
589
+ ->addObject($shipment)
590
+ ->addObject($shipment->getOrder())
591
+ ->save();
592
+
593
+ $shipment->sendEmail(true, '');
594
+
595
+ $order->shipped = true;
596
+ $order->save();
597
+ }
598
+ }
599
+
600
+ /**/
601
+ private function _checkOtherSupplierLinks()
602
+ {
603
+ if(@class_exists('Gateway3D_SupplierLink_Model_Observer') || @class_exists('BNetCentric_SupplierLink_Model_Observer'))
604
+ {
605
+ throw new Exception('Please disable and remove older versions of Supplier Link');
606
+ }
607
+ }
608
+
609
+ private function _initApi()
610
+ {
611
+ $path = Mage::getStoreConfig("general/personaliseit-sl/api_path");
612
+ $key = Mage::getStoreConfig("general/personaliseit-sl/api_key");
613
+
614
+ if($path && $key)
615
+ {
616
+ $this->_api = new Gateway3D_PersonaliseIt_Service_Api_Sl_Order($path, $key);
617
+ }
618
+ else
619
+ {
620
+ throw new Exception('No SL API key / path set');
621
+ }
622
+ }
623
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/ImportOptions.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Gateway3D_PersonaliseIt_Model_ImportOptions
4
+ extends Mage_Core_Helper_Abstract
5
+ {
6
+ const TYPE_SAMPLE = "su";
7
+ const TYPE_PRODUCT = "p";
8
+
9
+ private $_product = null;
10
+
11
+ private $_existingProductOptionSkus = array();
12
+ private $_existingProductOptionTitles = array();
13
+
14
+ private $_cppProduct = null;
15
+
16
+ private $_type = "";
17
+ private $_id = 0;
18
+
19
+ private $_optionData = array();
20
+
21
+ public function __construct(Mage_Catalog_Model_Product $product)
22
+ {
23
+ $this->_product = $product;
24
+
25
+ foreach($product->getOptions() as $option)
26
+ {
27
+ if($option->getSku())
28
+ {
29
+ $this->_existingProductOptionSkus[] = $option->getSku();
30
+ }
31
+ else
32
+ {
33
+ $values = $option->getValues();
34
+
35
+ foreach($option->getValues() as $value)
36
+ {
37
+ $this->_existingProductOptionSkus[] = $value->getSku();
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ public function import()
44
+ {
45
+ $this->_parseIframeUrls();
46
+
47
+ if($this->_type == self::TYPE_SAMPLE)
48
+ {
49
+ $this->_loadSample();
50
+ }
51
+
52
+ $this->_loadProduct();
53
+ $this->_determineOptions();
54
+
55
+ $m = new Mage_Catalog_Model_Product_Option_Api;
56
+
57
+ foreach($this->_optionData as $optionData)
58
+ {
59
+ $skuExists = false;
60
+
61
+ foreach($optionData['additional_fields'] as $value)
62
+ {
63
+ $skuExists |= in_array($value['sku'], $this->_existingProductOptionSkus);
64
+ }
65
+
66
+ if(!$skuExists)
67
+ {
68
+ $m->add($this->_product->getId(), $optionData);
69
+ }
70
+ }
71
+ }
72
+
73
+ private function _determineOptions()
74
+ {
75
+ $this->_determineOptionsFromCppTextAreas();
76
+ $this->_determineOptionsFromCppAttributes();
77
+ }
78
+
79
+ private function _determineOptionsFromCppTextAreas()
80
+ {
81
+ foreach($this->_cppProduct->text_areas as $area)
82
+ {
83
+ $this->_optionData[] = array(
84
+ 'title' => @$area['name'] ?: '',
85
+ 'type' => Gateway3D_PersonaliseIt_Model_Catalog_Product_Option::OPTION_TYPE_FIELD,
86
+ 'is_require' => false,
87
+ 'sort_order' => 1,
88
+
89
+ 'additional_fields' => array(array(
90
+ 'price' => @$area['price'] ?: 0.00,
91
+ 'price_type' => 'fixed',
92
+ 'sku' => "userText{$area['template_text_area_id']}",
93
+ ))
94
+ );
95
+ }
96
+ }
97
+
98
+ private function _determineOptionsFromCppAttributes()
99
+ {
100
+ // First pass - organise attributes into groups.
101
+ $groups = array();
102
+
103
+ foreach($this->_cppProduct->product_attributes as $attribute)
104
+ {
105
+ $key = $attribute['group_name'];
106
+
107
+ if(!isset($groups[$key]))
108
+ {
109
+ $groups[$key] = array();
110
+ }
111
+
112
+ $groups[$key][] = $attribute;
113
+ }
114
+
115
+ // Second pass - marshal to Mage optionData structures
116
+ foreach($groups as $name => $attributes)
117
+ {
118
+ $optionData = array(
119
+ 'title' => $name,
120
+ 'type' => Gateway3D_PersonaliseIt_Model_Catalog_Product_Option::OPTION_TYPE_DROP_DOWN,
121
+ 'is_require' => false,
122
+ 'sort_order' => 1,
123
+
124
+ 'additional_fields' => array()
125
+ );
126
+
127
+ foreach($attributes as $attribute)
128
+ {
129
+ $optionData['additional_fields'][] = array(
130
+ 'title' => @$attribute['attribute_name'] ?: '',
131
+ 'price' => @$attribute['price'] ?: 0.00,
132
+ 'price_type' => 'fixed',
133
+ 'sku' => @$attribute['sku'] ?: "userAttribute{$attribute['attribute_id']}"
134
+ );
135
+ }
136
+
137
+ $this->_optionData[] = $optionData;
138
+ }
139
+ }
140
+
141
+ private function _doesAnOptionAlreadyExistForCppAttributeGroup($attribute)
142
+ {
143
+
144
+ }
145
+
146
+ private function _loadSample()
147
+ {
148
+ $url = Mage::getStoreConfig("general/personaliseit-cpp/api_path") . "/p/1/sample";
149
+ $url = Mage::helper('personaliseit')->reduceUrlSlashes($url);
150
+
151
+ $service = new Gateway3D_PersonaliseIt_Service_Api_P1_Sample($url);
152
+ $sample = $service->retrieve($this->_id);
153
+
154
+ $this->_id = $sample->product_id;
155
+ $this->_type = self::TYPE_PRODUCT;
156
+ }
157
+
158
+ private function _loadProduct()
159
+ {
160
+ $url = Mage::getStoreConfig("general/personaliseit-cpp/api_path") . "/p/1/product";
161
+ $url = Mage::helper('personaliseit')->reduceUrlSlashes($url);
162
+
163
+ $service = new Gateway3D_PersonaliseIt_Service_Api_P1_Product($url);
164
+ $this->_cppProduct = $service->retrieve($this->_id);
165
+ }
166
+
167
+ private function _parseIframeUrls()
168
+ {
169
+ $fields = array(
170
+ 'easypromo3d_url',
171
+ 'personaliseit_iframe_url',
172
+ 'personaliseit_m_iframe_url',
173
+ 'personaliseit_fl_iframe_url',
174
+ 'personaliseit_gl_iframe_url'
175
+ );
176
+
177
+ foreach($fields as &$field)
178
+ {
179
+ if($this->_product->{$field})
180
+ {
181
+ $count = preg_match("/(su|p)=([0-9]*)/", $this->_product->{$field}, $matches);
182
+
183
+ if($count && count($matches) >= 3)
184
+ {
185
+ $this->_type = $matches[1];
186
+ $this->_id = $matches[2];
187
+
188
+ return;
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Product/Abstract.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ abstract class Gateway3D_PersonaliseIt_Model_Product_Abstract
11
+ {
12
+ protected $_product;
13
+
14
+ /**
15
+ * @return Mage_Catalog_Model_Product
16
+ */
17
+ public function getProduct()
18
+ {
19
+ return $this->_product;
20
+ }
21
+
22
+ public function load($id = null, $sku = null)
23
+ {
24
+ if($id)
25
+ {
26
+ $this->loadById($id);
27
+ }
28
+ else if($sku)
29
+ {
30
+ $this->loadBySku($sku);
31
+ }
32
+ else
33
+ {
34
+ throw new Exception('No ID or SKU specified');
35
+ }
36
+ }
37
+
38
+ public function loadById($id)
39
+ {
40
+ $product = Mage::getModel('catalog/product');
41
+
42
+ $product->load($id);
43
+
44
+ if(!$product->getId())
45
+ {
46
+ throw new Exception("Invalid ID {$id}");
47
+ }
48
+
49
+ $this->_product = $product;
50
+ }
51
+
52
+ public function loadBySku($sku)
53
+ {
54
+ $id = Mage::getModel('catalog/product')
55
+ ->getIdBySku($sku);
56
+
57
+ if(!$id)
58
+ {
59
+ throw new Exception("Invalid SKU {$sku}");
60
+ }
61
+
62
+ $this->loadById($id);
63
+ }
64
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Product/Callback.php ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ /**
11
+ * Class for processing a Personalise-iT app add to cart callback.
12
+ */
13
+ class Gateway3D_PersonaliseIt_Model_Product_Callback
14
+ extends Gateway3D_PersonaliseIt_Model_Product_Abstract
15
+ {
16
+ private $_data;
17
+
18
+ public function __construct(array $data)
19
+ {
20
+ $this->_data = $data;
21
+ }
22
+
23
+ public function process()
24
+ {
25
+ if(isset($this->_data['dynamic_pricing']) && is_array($this->_data['dynamic_pricing']))
26
+ {
27
+ $this->_marshalDynamicPricing();
28
+ }
29
+
30
+ $this->_processCart();
31
+ }
32
+
33
+ /**
34
+ * Marshal the dynamic_pricing structure into a form that can be understood
35
+ * by _processCart
36
+ *
37
+ * @return void
38
+ */
39
+ private function _marshalDynamicPricing()
40
+ {
41
+ $dynamicPricing = $this->_data['dynamic_pricing'];
42
+
43
+ if(!isset($dynamicPricing['attributes']) || !is_array($dynamicPricing['attributes']))
44
+ {
45
+ $dynamicPricing['attributes'] = array();
46
+ }
47
+
48
+ $this->_marshalDpQuantityElementToAttribute(
49
+ $dynamicPricing, 'image_colours', 'Number of Image Colours');
50
+
51
+ $this->_marshalDpQuantityElementToAttribute(
52
+ $dynamicPricing, 'print_areas', 'Number of Print Areas');
53
+
54
+ if(isset($dynamicPricing['attributes']))
55
+ {
56
+ $this->_marshalDynamicPricingToDropdowns($dynamicPricing['attributes']);
57
+ }
58
+
59
+ if(isset($dynamicPricing['colours']))
60
+ {
61
+ $this->_marshalDynamicPricingToMultiples('Colours', $dynamicPricing['colours']);
62
+ }
63
+
64
+ if(isset($dynamicPricing['effects']))
65
+ {
66
+ $this->_marshalDynamicPricingToMultiples('Effects', $dynamicPricing['effects']);
67
+ }
68
+ }
69
+
70
+ private function _marshalDpQuantityElementToAttribute(array &$dp, $element, $name)
71
+ {
72
+ if(isset($dp[$element]) && is_array($dp[$element]))
73
+ {
74
+ $dp['attributes'][] = array(
75
+ 'name' => $name,
76
+ 'value' => $dp[$element]['quantity'],
77
+ 'cost' => $dp[$element]['cost']
78
+ );
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Ensure that a valid "multiple" custom option exists with the given title
84
+ * and with the given values.
85
+ *
86
+ * This method also adds to _data['options'] for later processing.
87
+ *
88
+ * @param string $name Custom option title.
89
+ * @param array $values Custom option values.
90
+ * @return void
91
+ */
92
+ private function _marshalDynamicPricingToMultiples($name, array $values)
93
+ {
94
+ if(count($values))
95
+ {
96
+ $this->_data['options'][$name] = array_map(function($a)
97
+ {
98
+ return $a['name'];
99
+ }, $values);
100
+
101
+ // Search for a matching "dropdown" custom option.
102
+ $multiples = array_filter(
103
+ $this->_product->getOptions(),
104
+ array($this, '_filterOptionMultiple'));
105
+
106
+ $matchingOptions = array_values(array_filter($multiples, function($o) use ($name)
107
+ {
108
+ return $o->getTitle() == $name;
109
+ }));
110
+
111
+ // Create the custom option if it doesn't already exist.
112
+ if(count($matchingOptions) == 0)
113
+ {
114
+ $optionData = array(
115
+ 'title' => $name,
116
+ 'type' => Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE,
117
+ 'is_require'=> false,
118
+ 'sort_order'=> 1,
119
+
120
+ 'additional_fields' => array()
121
+ );
122
+
123
+ // Create values
124
+ foreach($values as $attribute)
125
+ {
126
+ $optionData['additional_fields'][] = array(
127
+ 'title' => $attribute['name'],
128
+ 'price' => $attribute['cost'],
129
+ 'price_type'=> 'fixed'
130
+ );
131
+ }
132
+
133
+ Gateway3D_PersonaliseIt_Helper_ProductCustomOptions::addOption($this->_product, $optionData);
134
+ }
135
+
136
+ // A matching custom option exists so let's check that the correct
137
+ // values also exist and create them if not.
138
+ else
139
+ {
140
+ $matchingOption = $matchingOptions[0];
141
+
142
+ $optionData = array(
143
+ 'additional_fields' => array()
144
+ );
145
+
146
+ foreach($values as $attribute)
147
+ {
148
+ // Check whether a value already exists.
149
+ $matchingValues = array_filter($matchingOption->getValues(), function($value) use ($attribute)
150
+ {
151
+ return $value->getTitle() == $attribute['name'];
152
+ });
153
+
154
+ // Create a value if one doesn't already exist.
155
+ if(count($matchingValues) == 0)
156
+ {
157
+ $optionData['additional_fields'][] = array(
158
+ 'title' => $attribute['name'],
159
+ 'price' => $attribute['cost'],
160
+ 'price_type'=> 'fixed'
161
+ );
162
+
163
+ Gateway3D_PersonaliseIt_Helper_ProductCustomOptions::update($matchingOption, $optionData);
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Ensure that valid "dropdown" custom options exist for the given collection
172
+ * of attributes.
173
+ *
174
+ * @param array $attributes
175
+ * @return void
176
+ */
177
+ private function _marshalDynamicPricingToDropdowns(array $attributes)
178
+ {
179
+ $dropdowns = array_filter(
180
+ $this->_product->getOptions(),
181
+ array($this, '_filterOptionDropdown'));
182
+
183
+ foreach($attributes as $attribute)
184
+ {
185
+ $name = $attribute['name'];
186
+ $value = $attribute['value'];
187
+
188
+ $this->_data['options'][$name] = $value;
189
+
190
+ $matchingOptions = array_values(array_filter($dropdowns, function($o) use ($attribute)
191
+ {
192
+ return $o->getTitle() == $attribute['name'];
193
+ }));
194
+
195
+ // Create if doesn't exist
196
+ if(count($matchingOptions) == 0)
197
+ {
198
+ $optionData = array(
199
+ 'title' => $attribute['name'],
200
+ 'type' => Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN,
201
+ 'is_require'=> false,
202
+ 'sort_order'=> 1,
203
+
204
+ 'additional_fields' => array()
205
+ );
206
+
207
+ $optionData['additional_fields'][] = array(
208
+ 'title' => $attribute['value'],
209
+ 'price' => $attribute['cost'],
210
+ 'price_type'=> 'fixed'
211
+ );
212
+
213
+ Gateway3D_PersonaliseIt_Helper_ProductCustomOptions::addOption($this->_product, $optionData);
214
+ }
215
+
216
+ else
217
+ {
218
+ $matchingOption = $matchingOptions[0];
219
+
220
+ // Check that a matching value exists
221
+ $matchingValues = array_keys(array_filter($matchingOption->getValues(), function($v) use ($attribute)
222
+ {
223
+ return $v->getTitle() == $attribute['value'];
224
+ }));
225
+
226
+ if(count($matchingValues) == 0)
227
+ {
228
+ $data = array(
229
+ 'additional_fields' => array(array(
230
+ 'title' => $attribute['value'],
231
+ 'price' => $attribute['cost'],
232
+ 'price_type'=> 'fixed'
233
+ ))
234
+ );
235
+
236
+ Gateway3D_PersonaliseIt_Helper_ProductCustomOptions::update($matchingOption, $data);
237
+ }
238
+ }
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Check whether a given custom option is a "dropdown".
244
+ *
245
+ * @param Mage_Catalog_Model_Product_Option $o
246
+ * @return bool True if the given option is a "dropdown".
247
+ */
248
+ private function _filterOptionDropdown(Mage_Catalog_Model_Product_Option $o)
249
+ {
250
+ return $o->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN;
251
+ }
252
+
253
+ /**
254
+ * Check whether a given custom option is a "multiple".
255
+ *
256
+ * @param Mage_Catalog_Model_Product_Option $o
257
+ * @return bool True if the given option is a "multiple".
258
+ */
259
+ private function _filterOptionMultiple(Mage_Catalog_Model_Product_Option $o)
260
+ {
261
+ return $o->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE;
262
+ }
263
+
264
+ /**
265
+ * Add the current product or it's associated group products to the cart.
266
+ *
267
+ * @return void
268
+ */
269
+ private function _processCart()
270
+ {
271
+ $cart = Mage::getModel("checkout/cart");
272
+
273
+ if($this->_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED)
274
+ {
275
+ $associatedProducts = $this->_product
276
+ ->getTypeInstance(true)
277
+ ->getAssociatedProducts($this->_product);
278
+
279
+ foreach($this->_data['grouped'] as $item)
280
+ {
281
+ if($item['quantity'] > 0)
282
+ {
283
+ $product = Mage::getModel('catalog/product');
284
+ $product->load($item['id']);
285
+
286
+ $this->_ensureProductHasCustomOptions($product);
287
+
288
+ $params = array(
289
+ 'options' => $this->_getOptions($product, $item),
290
+ 'qty' => $item['quantity']
291
+ );
292
+
293
+ $cart->addProduct($product, $params);
294
+ }
295
+ }
296
+ }
297
+ else
298
+ {
299
+ $this->_ensureProductHasCustomOptions($this->_product);
300
+
301
+ $params = array(
302
+ 'options' => $this->_getOptions($this->_product),
303
+ 'qty' => $this->_data['quantity']
304
+ );
305
+
306
+ $cart->addProduct($this->_product, $params);
307
+ }
308
+
309
+ //
310
+ $cart->save();
311
+ }
312
+
313
+ private function _getOptions(Mage_Catalog_Model_Product $product, $additionalData = array())
314
+ {
315
+ // Note:
316
+ // additionalData has precedence over _data
317
+ // So the ordering of the if statements is important!
318
+
319
+ $options = array();
320
+
321
+ foreach($product->getOptions() as $option)
322
+ {
323
+ $id = $option->getId();
324
+ $sku = $option->getSku();
325
+
326
+ if($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN)
327
+ {
328
+ if(isset($additionalData['options'][$id]))
329
+ {
330
+ $options[$id] = $additionalData['options'][$id];
331
+ }
332
+ else if(isset($this->_data['options'][$id]))
333
+ {
334
+ $options[$id] = $this->_data['options'][$id];
335
+ }
336
+ else if(isset($this->_data['options'][$option->getTitle()]))
337
+ {
338
+ $_value = $this->_data['options'][$option->getTitle()];
339
+
340
+ foreach($option->getValues() as $value)
341
+ {
342
+ if($value->getTitle() == $_value)
343
+ {
344
+ $options[$option->getId()] = $value->getId();
345
+ }
346
+ }
347
+ }
348
+ }
349
+ else if($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE)
350
+ {
351
+ if(isset($this->_data['options'][$option->getTitle()]))
352
+ {
353
+ $_values = $this->_data['options'][$option->getTitle()];
354
+
355
+ $values = array_filter($option->getValues(), function($value) use ($_values)
356
+ {
357
+ return in_array($value->getTitle(), $_values);
358
+ });
359
+
360
+ $ids = array_map(function($value) { return $value->getId(); }, $values);
361
+
362
+ $options[$option->getId()] = $ids;
363
+ }
364
+ }
365
+ else if(isset($additionalData[$sku]))
366
+ {
367
+ $options[$id] = $additionalData[$sku];
368
+ }
369
+ else if(isset($this->_data[$sku]))
370
+ {
371
+ $options[$id] = $this->_data[$sku];
372
+ }
373
+ }
374
+
375
+ return $options;
376
+ }
377
+
378
+ private function _ensureProductHasCustomOptions(Mage_Catalog_Model_Product $product, $required = array())
379
+ {
380
+ $printJobIdSku = Gateway3D_PersonaliseIt_Model_Cron_Sl::PRINT_JOB_ID_CUSTOM_OPTION_SKU;
381
+
382
+ $required = array_merge(array(
383
+ $printJobIdSku,
384
+ "thumburl"
385
+ ), $required);
386
+
387
+ Gateway3D_PersonaliseIt_Helper_ProductCustomOptions::ensureProductHasCustomOptions($product, $required);
388
+ }
389
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Product/Epa.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Model_Product_Epa
11
+ extends Gateway3D_PersonaliseIt_Model_Product_Abstract
12
+ {
13
+ public function getData()
14
+ {
15
+ $data = $this->_getProductData($this->_product);
16
+
17
+ $data['dynamic_pricing'] = $this->_getProductDynamicPricing($this->_product);
18
+ $data['grouped'] = array();
19
+
20
+ //
21
+ if($this->_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED)
22
+ {
23
+ $cheapestPrice = INF;
24
+
25
+ $associatedProducts = $this->_product
26
+ ->getTypeInstance(true)
27
+ ->getAssociatedProducts($this->_product);
28
+
29
+ foreach($associatedProducts as $associatedProduct)
30
+ {
31
+ $_associatedProduct = Mage::getModel('catalog/product');
32
+ $_associatedProduct->load($associatedProduct->getId());
33
+
34
+ $data['grouped'][] = $this->_getProductData($_associatedProduct);
35
+
36
+ // Grouped products don't have prices so use the cheapest
37
+ // associated product.
38
+ //
39
+ // Note that we don't compare on $data['price'] because it might
40
+ // be formatted with currency symbols etc
41
+ if($associatedProduct->getPrice() <= $cheapestPrice)
42
+ {
43
+ $data['price'] = $this->_getPrice($associatedProduct);
44
+ $cheapestPrice = $associatedProduct->getPrice();
45
+ }
46
+ }
47
+ }
48
+
49
+ //
50
+ return $data;
51
+ }
52
+
53
+ /**
54
+ * Get pricing information used for dynamic pricing.
55
+ *
56
+ * @param Mage_Core_Catalog_Model_Product $product
57
+ * @return array
58
+ */
59
+ private function _getProductDynamicPricing(Mage_Core_Catalog_Model_Product $product)
60
+ {
61
+ return array(
62
+ 'base' => $product->getPrice(),
63
+
64
+ 'per_print_area' => $this->_getProductDynamicPricingField(
65
+ $product, 'Number of Print Areas', Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN),
66
+
67
+ 'per_detected_colour' => $this->_getProductDynamicPricingField(
68
+ $product, 'Number of Image Colours', Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN),
69
+
70
+ 'per_stitch' => $this->_getProductDynamicPricingField(
71
+ $product, 'Number of Stitches', Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN),
72
+
73
+ 'effects' => $this->_getProductDynamicPricingField(
74
+ $product, 'Effects', Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE)
75
+ );
76
+ }
77
+
78
+ /**
79
+ * Gets a pricing structure for a matching custom option.
80
+ *
81
+ * @param Mage_Core_Catalog_Model_Product $product
82
+ * @param string $name Custom option title.
83
+ * @param string $type Custom option type.
84
+ * @return array|bool
85
+ */
86
+ private function _getProductDynamicPricingField(Mage_Core_Catalog_Model_Product $product, $name, $type)
87
+ {
88
+ foreach($product->getOptions() as $option)
89
+ {
90
+ $doesTitleMatch = $option->getTitle() == $name;
91
+ $doesTypeMatch = $option->getType() == $type;
92
+
93
+ $isDropDown = $option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN;
94
+ $isMulti = $option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE;
95
+
96
+ // In this case of a dropdown custom option, we assume that each
97
+ // option is a quantity and therefore only return a single value.
98
+ if($doesTypeMatch && $doesTitleMatch && $isDropDown)
99
+ {
100
+ foreach($option->getValues() as $value)
101
+ {
102
+ $title = $value->getTitle();
103
+
104
+ if(is_numeric($title) && $title > 0)
105
+ {
106
+ return $value->getPrice() / $title;
107
+ }
108
+ }
109
+ }
110
+
111
+ // In the case of a multiple custom option, we return the price
112
+ // of each possible value.
113
+ else if($doesTypeMatch && $doesTitleMatch && $isMulti)
114
+ {
115
+ return array_values(array_map(function($value)
116
+ {
117
+ $matches = array();
118
+
119
+ return array(
120
+ 'title' => $value->getTitle(),
121
+ 'price' => $value->getPrice()
122
+ );
123
+ }, $option->getValues()));
124
+ }
125
+ }
126
+
127
+ return false;
128
+ }
129
+
130
+ /**
131
+ * Gets the pricing structure for a given product.
132
+ *
133
+ * @param Mage_Catalog_Model_Product $product
134
+ * @return array
135
+ */
136
+ private function _getProductData($product)
137
+ {
138
+ $tiers = array();
139
+ $options = array();
140
+
141
+ // Tier prices
142
+ foreach($product->getTierPrice() as $tier)
143
+ {
144
+ $tiers[] = array(
145
+ 'quantity' => $tier['price_qty'],
146
+ 'price' => $this->_formatPrice($tier['price'])
147
+ );
148
+ }
149
+
150
+ // Drop down custom options
151
+ foreach($product->getOptions() as $option)
152
+ {
153
+ if($option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN)
154
+ {
155
+ $values = array();
156
+
157
+ foreach($option->getValues() as $value)
158
+ {
159
+ $values[] = array(
160
+ 'id' => $value->getId(),
161
+ 'name' => $value->getTitle(),
162
+ 'sku' => $value->getSku(),
163
+ 'price' => $this->_formatPrice($value->getPrice()),
164
+
165
+ 'minimum_quantity' => $product->getStockItem()->getMinSaleQty(),
166
+ 'maximum_quantity' => $product->getStockItem()->getMaxSaleQty(),
167
+ );
168
+ }
169
+
170
+ $options[] = array(
171
+ 'id' => $option->getId(),
172
+ 'name' => $option->getTitle(),
173
+ 'values' => $values
174
+ );
175
+ }
176
+ }
177
+
178
+ // average user rating
179
+ $storeId = Mage::app()->getStore()->getId();
180
+
181
+ $summaryData = Mage::getModel('review/review_summary')
182
+ ->setStoreId($storeId)
183
+ ->load($product->getId());
184
+
185
+ $rating = $summaryData->getRatingSummary()
186
+ ? $summaryData->getRatingSummary() / 100
187
+ : 0.0;
188
+
189
+ //
190
+ return array(
191
+ 'id' => $product->getId(),
192
+ 'sku' => $product->getSku(),
193
+
194
+ 'price' => $this->_getPrice($product),
195
+
196
+ 'name' => $product->getName(),
197
+ 'description' => $product->getDescription(),
198
+ 'rating' => $rating,
199
+
200
+ 'minimum_quantity' => $product->getStockItem()->getMinSaleQty(),
201
+ 'maximum_quantity' => $product->getStockItem()->getMaxSaleQty(),
202
+
203
+ 'increment_quantity'=> $product->getStockItem()->getEnableQtyIncrements()
204
+ ? $product->getStockItem()->getQtyIncrements()
205
+ : 1,
206
+
207
+ 'is_new' => self::_isProductNew($product),
208
+
209
+ 'options' => $options,
210
+ 'tiers' => $tiers,
211
+ );
212
+ }
213
+
214
+ /**
215
+ * Gets a formatted price for a product.
216
+ *
217
+ * @param Mage_Catalog_Model_Product $product
218
+ * @return string
219
+ */
220
+ private function _getPrice($product)
221
+ {
222
+ return $this->_formatPrice($product->getPrice());
223
+ }
224
+
225
+ /**
226
+ * Gets a price formatted according to Magento's current currency.
227
+ *
228
+ * @param mixed $price
229
+ * @return string
230
+ */
231
+ private function _formatPrice($price)
232
+ {
233
+ $price = number_format($price, 2);
234
+
235
+ return Mage::helper('core')
236
+ ->currency($price, true, false);
237
+ }
238
+
239
+ /**
240
+ * Calculates whether a product is new.
241
+ *
242
+ * @param Mage_Catalog_Model_Product $product
243
+ * @return boolean
244
+ */
245
+ private static function _isProductNew(Mage_Catalog_Model_Product $product)
246
+ {
247
+ if($product->getNewsFromDate())
248
+ {
249
+ return Mage::app()->getLocale()->isStoreDateInInterval(
250
+ Mage::app()->getStore(),
251
+ $product->getNewsFromDate(),
252
+ $product->getNewsToDate()
253
+ );
254
+ }
255
+ else
256
+ {
257
+ return false;
258
+ }
259
+ }
260
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Product/Rating.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Model_Product_Rating
11
+ extends Gateway3D_PersonaliseIt_Model_Product_Abstract
12
+ {
13
+ public function setRating($rating = 1)
14
+ {
15
+ // Don't allow a rating < 1 or > 5
16
+ $rating = max(1, min(5, $rating));
17
+
18
+ // Limitation:
19
+ //
20
+ // Currently we can only use the first rating that we find because
21
+ // there is nothing to tell us which rating to use!
22
+ $ratingCollection = Mage::getModel('rating/rating')
23
+ ->getResourceCollection()
24
+ ->addEntityFilter('product')
25
+ ->setPositionOrder()
26
+ ->addRatingPerStoreName(Mage::app()->getStore()->getId())
27
+ ->setStoreFilter(Mage::app()->getStore()->getId())
28
+ ->load()
29
+ ->addOptionToItems();
30
+
31
+ $ratingId = null;
32
+
33
+ foreach($ratingCollection as $_rating)
34
+ {
35
+ $ratingId = $_rating->getId();
36
+ break;
37
+ }
38
+
39
+ if($ratingId === null)
40
+ {
41
+ throw new Exception('No rating found');
42
+ }
43
+
44
+ // Now create the review
45
+ $review = Mage::getModel('review/review')
46
+ ->setEntityPkValue($this->_product->getId())
47
+ ->setStatusId(Mage_Review_Model_Review::STATUS_APPROVED)
48
+ ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
49
+ ->setTitle("")
50
+ ->setDetail("")
51
+ ->setEntityId(1)
52
+ ->setStoreId(Mage::app()->getStore()->getId())
53
+ ->setStores(array(Mage::app()->getStore()->getId()))
54
+ ->setNickname("")
55
+ ->save();
56
+
57
+ // Add the rating to the review
58
+ Mage::getModel('rating/rating')
59
+ ->setRatingId($ratingId)
60
+ ->setReviewId($review->getId())
61
+ ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
62
+ ->addOptionVote(floor($rating), $this->_product->getId());
63
+
64
+ // ?? Recalculate the review's rating summary?
65
+ $review->aggregate();
66
+
67
+ //
68
+ return true;
69
+ }
70
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Resource/Eav/Mysql4/Setup.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2013 Gateway 3D Ltd.
8
+ */
9
+ class Gateway3D_PersonaliseIt_Model_Resource_Eav_Mysql4_Setup
10
+ extends Mage_Eav_Model_Entity_Setup
11
+ {
12
+ public function getDefaultEntities(){
13
+ return array(
14
+ 'catalog_product' => array(
15
+ 'entity_model' => 'catalog/product',
16
+ 'attribute_model' => 'catalog/resource_eav_attribute',
17
+ 'table' => 'catalog/product',
18
+ 'additional_attribute_table' => 'catalog/eav_attribute',
19
+ 'entity_attribute_collection' => 'catalog/product_attribute_collection',
20
+ 'attributes' => array(
21
+
22
+ 'personaliseit_gl_iframe_url'=> array(
23
+ 'section' =>'general',
24
+ 'group' => 'Gateway3D Personalise-iT',
25
+ 'label' => 'WebGL iFrame URL',
26
+ 'type' => 'text',
27
+ 'input' => 'text',
28
+ 'default' => '',
29
+ 'class' => '',
30
+ 'backend' => '',
31
+ 'frontend' => '',
32
+ 'source' => '',
33
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
34
+ 'visible' => true,
35
+ 'required' => false,
36
+ 'user_defined' => false,
37
+ 'searchable' => false,
38
+ 'filterable' => false,
39
+ 'comparable' => false,
40
+ 'visible_on_front' => false,
41
+ 'visible_in_advanced_search' => false,
42
+ 'unique' => false
43
+ ),
44
+
45
+ 'personaliseit_fl_iframe_url'=> array(
46
+ 'section' =>'general',
47
+ 'group' => 'Gateway3D Personalise-iT',
48
+ 'label' => 'Flash iFrame URL',
49
+ 'type' => 'text',
50
+ 'input' => 'text',
51
+ 'default' => '',
52
+ 'class' => '',
53
+ 'backend' => '',
54
+ 'frontend' => '',
55
+ 'source' => '',
56
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
57
+ 'visible' => true,
58
+ 'required' => false,
59
+ 'user_defined' => false,
60
+ 'searchable' => false,
61
+ 'filterable' => false,
62
+ 'comparable' => false,
63
+ 'visible_on_front' => false,
64
+ 'visible_in_advanced_search' => false,
65
+ 'unique' => false
66
+ ),
67
+
68
+ 'personaliseit_m_iframe_url'=>array(
69
+ 'section' =>'general',
70
+ 'group' => 'Gateway3D Personalise-iT',
71
+ 'label' => 'Default Mobile iFrame URL',
72
+ 'type' => 'text',
73
+ 'input' => 'text',
74
+ 'default' => '',
75
+ 'class' => '',
76
+ 'backend' => '',
77
+ 'frontend' => '',
78
+ 'source' => '',
79
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
80
+ 'visible' => true,
81
+ 'required' => false,
82
+ 'user_defined' => false,
83
+ 'searchable' => false,
84
+ 'filterable' => false,
85
+ 'comparable' => false,
86
+ 'visible_on_front' => false,
87
+ 'visible_in_advanced_search' => false,
88
+ 'unique' => false
89
+ ),
90
+
91
+ 'personaliseit_iframe_url'=>array(
92
+ 'section'=>'general',
93
+ 'group' => 'Gateway3D Personalise-iT',
94
+ 'label' => 'Default iFrame URL',
95
+ 'type' => 'text',
96
+ 'input' => 'text',
97
+ 'default' => '',
98
+ 'class' => '',
99
+ 'backend' => '',
100
+ 'frontend' => '',
101
+ 'source' => '',
102
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
103
+ 'visible' => true,
104
+ 'required' => false,
105
+ 'user_defined' => false,
106
+ 'searchable' => false,
107
+ 'filterable' => false,
108
+ 'comparable' => false,
109
+ 'visible_on_front' => false,
110
+ 'visible_in_advanced_search' => false,
111
+ 'unique' => false
112
+ ),
113
+
114
+ 'easypromo3d_url'=>array(
115
+ 'section'=>'general',
116
+ 'group' => 'Gateway3D Personalise-iT',
117
+ 'label' => 'Legacy Easypromo3D URL',
118
+ 'type' => 'text',
119
+ 'input' => 'text',
120
+ 'default' => '',
121
+ 'class' => '',
122
+ 'backend' => '',
123
+ 'frontend' => '',
124
+ 'source' => '',
125
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
126
+ 'visible' => true,
127
+ 'required' => false,
128
+ 'user_defined' => false,
129
+ 'searchable' => false,
130
+ 'filterable' => false,
131
+ 'comparable' => false,
132
+ 'visible_on_front' => false,
133
+ 'visible_in_advanced_search' => false,
134
+ 'unique' => false
135
+ ),
136
+
137
+ 'personaliseit_company_ref_id'=>array(
138
+ 'section'=>'general',
139
+ 'group' => 'Gateway3D Personalise-iT',
140
+ 'label' => '(Supplier) Company Ref ID',
141
+ 'type' => 'varchar',
142
+ 'input' => 'text',
143
+ 'default' => '',
144
+ 'class' => '',
145
+ 'backend' => '',
146
+ 'frontend' => '',
147
+ 'source' => '',
148
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
149
+ 'visible' => true,
150
+ 'required' => false,
151
+ 'user_defined' => false,
152
+ 'searchable' => false,
153
+ 'filterable' => false,
154
+ 'comparable' => false,
155
+ 'visible_on_front' => false,
156
+ 'visible_in_advanced_search' => false,
157
+ 'unique' => false
158
+ ),
159
+
160
+ 'personaliseit_pod_ref'=>array(
161
+ 'section'=>'general',
162
+ 'group' => 'Gateway3D Personalise-iT',
163
+ 'label' => 'Print-on-Demand Sample Ref',
164
+ 'type' => 'varchar',
165
+ 'input' => 'text',
166
+ 'default' => '',
167
+ 'class' => '',
168
+ 'backend' => '',
169
+ 'frontend' => '',
170
+ 'source' => '',
171
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
172
+ 'visible' => true,
173
+ 'required' => false,
174
+ 'user_defined' => false,
175
+ 'searchable' => false,
176
+ 'filterable' => false,
177
+ 'comparable' => false,
178
+ 'visible_on_front' => false,
179
+ 'visible_in_advanced_search' => false,
180
+ 'unique' => false
181
+ ),
182
+
183
+ 'personaliseit_is_plain' => array(
184
+ 'section' => 'general',
185
+ 'group' => 'Gateway3D Personalise-iT',
186
+ 'label' => 'Is Plain?',
187
+ 'type' => 'int',
188
+ 'input' => 'boolean',
189
+ 'default' => '',
190
+ 'class' => '',
191
+ 'backend' => '',
192
+ 'frontend' => '',
193
+ 'source' => 'eav/entity_attribute_source_table',
194
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
195
+ 'visible' => true,
196
+ 'required' => false,
197
+ 'user_defined' => false,
198
+ 'searchable' => false,
199
+ 'filterable' => false,
200
+ 'comparable' => false,
201
+ 'visible_on_front' => false,
202
+ 'visible_in_advanced_search' => false,
203
+ 'unique' => false
204
+ ),
205
+
206
+ 'personaliseit_use_mageid' => array(
207
+ 'section' => 'general',
208
+ 'group' => 'Gateway3D Personalise-iT',
209
+ 'label' => 'Use Magento product ID in iFrame callbacks?',
210
+ 'type' => 'int',
211
+ 'input' => 'boolean',
212
+ 'default' => '1',
213
+ 'class' => '',
214
+ 'backend' => '',
215
+ 'frontend' => '',
216
+ 'source' => 'eav/entity_attribute_source_table',
217
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
218
+ 'visible' => true,
219
+ 'required' => false,
220
+ 'user_defined' => false,
221
+ 'searchable' => false,
222
+ 'filterable' => false,
223
+ 'comparable' => false,
224
+ 'visible_on_front' => false,
225
+ 'visible_in_advanced_search' => false,
226
+ 'unique' => false
227
+ ),
228
+
229
+ 'personaliseit_dp_enabled' => array(
230
+ 'section' => 'general',
231
+ 'group' => 'Gateway3D Personalise-iT',
232
+ 'label' => 'Enable delayed preview',
233
+ 'type' => 'int',
234
+ 'input' => 'boolean',
235
+ 'default' => '0',
236
+ 'class' => '',
237
+ 'backend' => '',
238
+ 'frontend' => '',
239
+ 'source' => 'eav/entity_attribute_source_table',
240
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
241
+ 'visible' => true,
242
+ 'required' => false,
243
+ 'user_defined' => false,
244
+ 'searchable' => false,
245
+ 'filterable' => false,
246
+ 'comparable' => false,
247
+ 'visible_on_front' => false,
248
+ 'visible_in_advanced_search' => false,
249
+ 'unique' => false
250
+ ),
251
+
252
+ 'personaliseit_dp_pid' => array(
253
+ 'section' => 'general',
254
+ 'group' => 'Gateway3D Personalise-iT',
255
+ 'label' => 'Automatic print job creation product ID',
256
+ 'type' => 'int',
257
+ 'input' => 'text',
258
+ 'default' => '0',
259
+ 'class' => '',
260
+ 'backend' => '',
261
+ 'frontend' => '',
262
+ 'source' => 'eav/entity_attribute_source_table',
263
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
264
+ 'visible' => true,
265
+ 'required' => false,
266
+ 'user_defined' => false,
267
+ 'searchable' => false,
268
+ 'filterable' => false,
269
+ 'comparable' => false,
270
+ 'visible_on_front' => false,
271
+ 'visible_in_advanced_search' => false,
272
+ 'unique' => false
273
+ )
274
+ ),
275
+ ),
276
+ );
277
+ }
278
+ }
279
+
app/code/local/Gateway3D/PersonaliseIt/Model/Source/Orderstatus.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Model_Source_Orderstatus
11
+ {
12
+ public function toOptionArray()
13
+ {
14
+ return array(
15
+ array('value' => Gateway3D_PersonaliseIt_Service_Dto_Sl_Order::STATUS_ITEMS_READY, 'label' => 'Received'),
16
+ array('value' => Gateway3D_PersonaliseIt_Service_Dto_Sl_Order::STATUS_ON_HOLD, 'label' => 'On Hold')
17
+ );
18
+ }
19
+ }
app/code/local/Gateway3D/PersonaliseIt/Model/Status/Callback.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Model_Status_Callback
11
+ {
12
+ /**
13
+ * @var Mage_Sales_Model_Order
14
+ */
15
+ private $_order;
16
+
17
+ public function load($ref)
18
+ {
19
+ $collection = Mage::getResourceModel('sales/order_collection')
20
+ ->addAttributeToSelect('*')
21
+ ->addFieldToFilter('status_callback_ref', $ref)
22
+ ->addFieldToFilter('sent', 1)
23
+ ->addFieldToFilter('shipped', 0)
24
+ ->addOrder('created_at', 'desc');
25
+
26
+ if(count($collection) === 1)
27
+ {
28
+ foreach($collection as $order)
29
+ {
30
+ $this->_order = $order;
31
+
32
+ break;
33
+ }
34
+ }
35
+ else
36
+ {
37
+ throw new Exception('Invalid ref');
38
+ }
39
+ }
40
+
41
+ public function update($status, $statusName)
42
+ {
43
+ switch($status)
44
+ {
45
+ case Gateway3D_PersonaliseIt_Service_Dto_Sl_Order::STATUS_DISPATCHED:
46
+ case Gateway3D_PersonaliseIt_Service_Dto_Sl_Order::STATUS_SUPPLIER_DISPATCHED_NOTIFIED:
47
+ $this->_ship();
48
+ break;
49
+
50
+ default:
51
+ $this->_order->addStatusHistoryComment("Status callback: {$statusName} ({$status})");
52
+ $this->_order->save();
53
+ break;
54
+ }
55
+
56
+ return true;
57
+ }
58
+
59
+ private function _ship()
60
+ {
61
+ if($this->_order->canShip())
62
+ {
63
+ $qtys = array();
64
+
65
+ foreach($this->_order->getAllItems() as $item)
66
+ {
67
+ $qtys[$item->getId()] = $item->getQtyToShip();
68
+ }
69
+
70
+ $shipment = Mage::getModel('sales/service_order', $this->_order)->prepareShipment($qtys);
71
+
72
+ $shipment->register();
73
+
74
+ $shipment->setEmailSent(true);
75
+
76
+ $shipment->getOrder()->setCustomerNoteNotify(true);
77
+
78
+ $shipment->getOrder()->setIsInProcess(true);
79
+
80
+ Mage::getModel('core/resource_transaction')
81
+ ->addObject($shipment)
82
+ ->addObject($shipment->getOrder())
83
+ ->save();
84
+
85
+ $shipment->sendEmail(true, '');
86
+
87
+ $this->_order->shipped = true;
88
+ $this->_order->save();
89
+ }
90
+ }
91
+ }
app/code/local/Gateway3D/PersonaliseIt/controllers/CppController.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Gateway3D_PersonaliseIt_CppController
4
+ extends Mage_Adminhtml_Controller_Action
5
+ {
6
+ public function importOptionsAction()
7
+ {
8
+ $id = $this->getRequest()->getParam('id', 0);
9
+
10
+ $product = Mage::getModel('catalog/product')
11
+ ->load($id);
12
+
13
+ try
14
+ {
15
+ $model = new Gateway3D_PersonaliseIt_Model_ImportOptions($product);
16
+ $model->import();
17
+ }
18
+ catch(Exception $e)
19
+ {
20
+ $this->_getSession()->addError($e->getMessage());
21
+ }
22
+ }
23
+ }
app/code/local/Gateway3D/PersonaliseIt/controllers/ProductController.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2013 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_ProductController
11
+ extends Mage_Core_Controller_Front_Action
12
+ {
13
+ /**
14
+ * /personalise-it/product/epa/
15
+ */
16
+ public function epaAction()
17
+ {
18
+ $model = new Gateway3D_PersonaliseIt_Model_Product_Epa();
19
+
20
+ $sku = $this->getRequest()->getParam('sku', '');
21
+ $id = $this->getRequest()->getParam('id', '');
22
+ $callback = $this->getRequest()->getParam('callback', '');
23
+ $callback = preg_replace("/[^0-9a-zA-Z\$_]/", "", $callback);
24
+
25
+ //
26
+ try
27
+ {
28
+ $model->load($id, $sku);
29
+ $data = $model->getData();
30
+ }
31
+ catch(Exception $e)
32
+ {
33
+ $data = array(
34
+ 'error' => array(
35
+ 'message' => $e->getMessage()
36
+ )
37
+ );
38
+ }
39
+
40
+ //
41
+ $json = Zend_Json::encode($data);
42
+ $jsonp = "{$callback}({$json})";
43
+
44
+ $this->getResponse()->clearAllHeaders();
45
+ $this->getResponse()->setHeader('Content-Length', strlen($jsonp));
46
+ $this->getResponse()->setHeader('Content-Type', 'text/plain');
47
+ $this->getResponse()->sendHeaders();
48
+
49
+ echo $jsonp;
50
+
51
+ exit;
52
+ }
53
+
54
+ public function ratingAction()
55
+ {
56
+ $model = new Gateway3D_PersonaliseIt_Model_Product_Rating();
57
+
58
+ $sku = $this->getRequest()->getParam('sku', '');
59
+ $id = $this->getRequest()->getParam('id', '');
60
+ $rating = $this->getRequest()->getParam('rating', 0);
61
+ $callback = $this->getRequest()->getParam('callback', '');
62
+ $callback = preg_replace("/[^0-9a-zA-Z\$_]/", "", $callback);
63
+
64
+ //
65
+ try
66
+ {
67
+ $model->load($id, $sku);
68
+ $data = $model->setRating($rating);
69
+ }
70
+ catch(Exception $e)
71
+ {
72
+ $data = array(
73
+ 'error' => array(
74
+ 'message' => $e->getMessage()
75
+ )
76
+ );
77
+ }
78
+
79
+ //
80
+ $json = Zend_Json::encode($data);
81
+ $jsonp = "{$callback}({$json})";
82
+
83
+ $this->getResponse()->clearAllHeaders();
84
+ $this->getResponse()->setHeader('Content-Length', strlen($jsonp));
85
+ $this->getResponse()->setHeader('Content-Type', 'text/plain');
86
+ $this->getResponse()->sendHeaders();
87
+
88
+ echo $jsonp;
89
+
90
+ exit;
91
+ }
92
+
93
+ public function callbackAction()
94
+ {
95
+ $data = $this->_getData();
96
+ $model = new Gateway3D_PersonaliseIt_Model_Product_Callback($data);
97
+
98
+ $sku = $this->getRequest()->getParam('sku', '');
99
+ $id = $this->getRequest()->getParam('id', '');
100
+
101
+ // Fallback to SKU specified in data object
102
+ if(!$id && !$sku && isset($data['sku']))
103
+ {
104
+ $sku = $data['sku'];
105
+ }
106
+
107
+ // Load the model
108
+ $model->load($id, $sku);
109
+
110
+ //
111
+ $this->loadLayout();
112
+
113
+ $block = $this->getLayout()->getBlock('root');
114
+
115
+ //
116
+ try
117
+ {
118
+ $model->process();
119
+
120
+ $block->setData('message', __('Please wait while we download your custom design to the shopping basket...'));
121
+ $block->setData('redirect', Mage::getUrl('checkout/cart'));
122
+
123
+ }
124
+ catch(Exception $e)
125
+ {
126
+ $block->setData('message', $e->getMessage());
127
+ $block->setData('redirect', $model->getProduct()->getProductUrl());
128
+ }
129
+
130
+ //
131
+
132
+ $this->renderLayout();
133
+ }
134
+
135
+ private function _getData()
136
+ {
137
+ $type = $_SERVER['CONTENT_TYPE'];
138
+
139
+ switch($type)
140
+ {
141
+ case 'application/json':
142
+ $json = $this->getRequest()->getRawBody();
143
+ break;
144
+
145
+ case 'application/x-www-form-urlencoded':
146
+ $json = $_POST['data'];
147
+ break;
148
+
149
+ default:
150
+ throw new Exception('Invalid content-type');
151
+ }
152
+
153
+ $data = Zend_Json::decode($json);
154
+
155
+ return $data;
156
+ }
157
+ }
app/code/local/Gateway3D/PersonaliseIt/controllers/ProductsController.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2013 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_ProductsController
11
+ extends Mage_Core_Controller_Front_Action
12
+ {
13
+ /**
14
+ * /product-selector/products/
15
+ */
16
+ public function indexAction()
17
+ {
18
+ $this->loadLayout();
19
+ $this->renderLayout();
20
+ }
21
+ }
app/code/local/Gateway3D/PersonaliseIt/controllers/StatusController.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2013 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_StatusController
11
+ extends Mage_Core_Controller_Front_Action
12
+ {
13
+ /**
14
+ * /personalise-it/status/callback/
15
+ */
16
+ public function callbackAction()
17
+ {
18
+ $model = new Gateway3D_PersonaliseIt_Model_Status_Callback();
19
+
20
+ $ref = $this->getRequest()->getParam('ref', '');
21
+
22
+ $request = Zend_Json::decode($this->getRequest()->getRawBody());
23
+ $status = @$request['status'];
24
+ $statusName = @$request['status_name'];
25
+
26
+ //
27
+ try
28
+ {
29
+ $model->load($ref);
30
+ $response = $model->update($status, $statusName);
31
+ }
32
+ catch(Exception $e)
33
+ {
34
+ $response = array(
35
+ 'error' => array(
36
+ 'message' => $e->getMessage()
37
+ )
38
+ );
39
+ }
40
+
41
+ //
42
+ $json = Zend_Json::encode($response);
43
+
44
+ $this->getResponse()->clearAllHeaders();
45
+ $this->getResponse()->setHeader('Content-Type', 'application/json');
46
+ $this->getResponse()->sendHeaders();
47
+
48
+ echo $json;
49
+
50
+ exit;
51
+ }
52
+ }
app/code/local/Gateway3D/PersonaliseIt/etc/config.xml ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2013 Gateway 3D Ltd.
8
+ */
9
+ -->
10
+
11
+ <config>
12
+ <modules>
13
+ <Gateway3D_PersonaliseIt>
14
+ <version>1.6.0.0</version>
15
+ </Gateway3D_PersonaliseIt>
16
+ </modules>
17
+ <global>
18
+ <models>
19
+ <personaliseit>
20
+ <class>Gateway3D_PersonaliseIt_Model</class>
21
+ <resourceModel>personaliseit_mysql4</resourceModel>
22
+ </personaliseit>
23
+
24
+ <catalog>
25
+ <rewrite>
26
+ <product_option>Gateway3D_PersonaliseIt_Model_Catalog_Product_Option</product_option>
27
+ </rewrite>
28
+ </catalog>
29
+ </models>
30
+
31
+ <helpers>
32
+ <personaliseit>
33
+ <class>Gateway3D_PersonaliseIt_Helper</class>
34
+ </personaliseit>
35
+ </helpers>
36
+
37
+ <resources>
38
+ <personaliseit_setup>
39
+ <setup>
40
+ <module>Gateway3D_PersonaliseIt</module>
41
+ <class>Gateway3D_PersonaliseIt_Model_Resource_Eav_Mysql4_Setup</class>
42
+ </setup>
43
+ <connection>
44
+ <use>core_setup</use>
45
+ </connection>
46
+ </personaliseit_setup>
47
+ <personaliseit_write>
48
+ <connection>
49
+ <use>core_write</use>
50
+ </connection>
51
+ </personaliseit_write>
52
+ <personaliseit_read>
53
+ <connection>
54
+ <use>core_read</use>
55
+ </connection>
56
+ </personaliseit_read>
57
+ </resources>
58
+
59
+ <catalog>
60
+ <product>
61
+ <options>
62
+ <custom>
63
+ <groups>
64
+ <hidden translate="label" module="personaliseit">
65
+ <label>Hidden</label>
66
+ <render>adminhtml/catalog_product_edit_tab_options_type_text</render>
67
+
68
+ <types>
69
+ <hidden translate="label" module="personaliseit">
70
+ <label>Hidden</label>
71
+ </hidden>
72
+ </types>
73
+ </hidden>
74
+ </groups>
75
+ </custom>
76
+ </options>
77
+ </product>
78
+ </catalog>
79
+
80
+ <blocks>
81
+ <adminhtml>
82
+ <rewrite>
83
+ <catalog_product_edit_tab_options>Gateway3D_PersonaliseIt_Block_Adminhtml_Catalog_Product_Edit_Tab_Options</catalog_product_edit_tab_options>
84
+ </rewrite>
85
+ <rewrite>
86
+ <catalog_product_edit_tab_options_option>Gateway3D_PersonaliseIt_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Option</catalog_product_edit_tab_options_option>
87
+ </rewrite>
88
+ </adminhtml>
89
+
90
+ <catalog>
91
+ <rewrite>
92
+ <product_view_options>Gateway3D_PersonaliseIt_Block_Product_View_Options</product_view_options>
93
+ </rewrite>
94
+ </catalog>
95
+ </blocks>
96
+ </global>
97
+ <frontend>
98
+ <routers>
99
+ <personaliseit>
100
+ <use>standard</use>
101
+ <args>
102
+ <module>Gateway3D_PersonaliseIt</module>
103
+ <frontName>personalise-it</frontName>
104
+ </args>
105
+ </personaliseit>
106
+ </routers>
107
+ <layout>
108
+ <updates>
109
+ <personaliseit>
110
+ <file>personaliseit.xml</file>
111
+ </personaliseit>
112
+ </updates>
113
+ </layout>
114
+ </frontend>
115
+ <adminhtml>
116
+ <layout>
117
+ <updates>
118
+ <personaliseit>
119
+ <file>personaliseit.xml</file>
120
+ </personaliseit>
121
+ </updates>
122
+ </layout>
123
+ </adminhtml>
124
+ <crontab>
125
+ <jobs>
126
+ <personaliseit>
127
+ <schedule>
128
+ <cron_expr>*/10 * * * *</cron_expr>
129
+ </schedule>
130
+ <run>
131
+ <model>personaliseit/cron_delayedPrintJob::start</model>
132
+ <model>personaliseit/cron_sl::start</model>
133
+ </run>
134
+ </personaliseit>
135
+ </jobs>
136
+ </crontab>
137
+
138
+ <admin>
139
+ <routers>
140
+ <adminhtml>
141
+ <args>
142
+ <modules>
143
+ <Gateway3D_PersonaliseIt before="Mage_Adminhtml">Gateway3D_PersonaliseIt</Gateway3D_PersonaliseIt>
144
+ </modules>
145
+ </args>
146
+ </adminhtml>
147
+ </routers>
148
+ </admin>
149
+
150
+ <default>
151
+ <general>
152
+ <personaliseit-delayed-preview>
153
+ <api_path>https://my.gateway3d.com/acp/api/p/2/print-job</api_path>
154
+ </personaliseit-delayed-preview>
155
+
156
+ <personaliseit-sl>
157
+ <api_path>https://my.gateway3d.com/acp/api/sl/2.1/order</api_path>
158
+ </personaliseit-sl>
159
+
160
+ <personaliseit-cpp>
161
+ <api_path>https://my.gateway3d.com/acp/api/</api_path>
162
+ </personaliseit-cpp>
163
+ </general>
164
+ </default>
165
+ </config>
app/code/local/Gateway3D/PersonaliseIt/etc/system.xml ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2013 Gateway 3D Ltd.
8
+ */
9
+ -->
10
+
11
+ <config>
12
+ <sections>
13
+ <general>
14
+ <groups>
15
+ <personaliseit-product-selector translate="label" module="personaliseit">
16
+ <label>G3D Personalise-iT Product Selector Settings</label>
17
+ <frontend_type>text</frontend_type>
18
+ <sort_order>1</sort_order>
19
+ <show_in_default>1</show_in_default>
20
+ <show_in_website>1</show_in_website>
21
+ <show_in_store>0</show_in_store>
22
+ <fields>
23
+ <iframe_url translate="label">
24
+ <label>iFrame URL</label>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>4</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ </iframe_url>
31
+
32
+ <mobile_iframe_url translate="label">
33
+ <label>Mobile iFrame URL</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>8</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ </mobile_iframe_url>
40
+ </fields>
41
+ </personaliseit-product-selector>
42
+
43
+ <personaliseit-sl translate="label" module="personaliseit">
44
+ <label>G3D Personalise-iT Supplier Link Settings</label>
45
+ <frontend_type>text</frontend_type>
46
+ <sort_order>1</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>0</show_in_store>
50
+ <fields>
51
+ <api_path translate="label">
52
+ <label>API Path</label>
53
+ <frontend_type>text</frontend_type>
54
+ <sort_order>30</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>0</show_in_store>
58
+ </api_path>
59
+ <api_key translate="label">
60
+ <label>API Key</label>
61
+ <frontend_type>text</frontend_type>
62
+ <sort_order>35</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>0</show_in_store>
66
+ <validate>required-entry validate-length minimum-length-27 maximum-length-27</validate>
67
+ </api_key>
68
+ <default_order_status translate="label">
69
+ <label>Default Order Status</label>
70
+ <frontend_type>select</frontend_type>
71
+ <sort_order>40</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <show_in_website>1</show_in_website>
74
+ <show_in_store>0</show_in_store>
75
+ <source_model>personaliseit/source_orderstatus</source_model>
76
+ </default_order_status>
77
+ <enable_order_status_polling translate="label">
78
+ <label>Enable Order Status Polling (Legacy)</label>
79
+ <frontend_type>select</frontend_type>
80
+ <sort_order>45</sort_order>
81
+ <show_in_default>1</show_in_default>
82
+ <show_in_website>1</show_in_website>
83
+ <show_in_store>0</show_in_store>
84
+ <source_model>adminhtml/system_config_source_yesno</source_model>
85
+ </enable_order_status_polling>
86
+ </fields>
87
+ </personaliseit-sl>
88
+
89
+ <personaliseit-delayed-preview translate="label" module="personaliseit">
90
+ <label>G3D Personalise-iT Delayed Preview Settings</label>
91
+ <frontend_type>text</frontend_type>
92
+ <sort_order>1</sort_order>
93
+ <show_in_default>1</show_in_default>
94
+ <show_in_website>1</show_in_website>
95
+ <show_in_store>0</show_in_store>
96
+ <fields>
97
+ <api_path translate="label">
98
+ <label>API Path</label>
99
+ <frontend_type>text</frontend_type>
100
+ <sort_order>30</sort_order>
101
+ <show_in_default>1</show_in_default>
102
+ <show_in_website>1</show_in_website>
103
+ <show_in_store>0</show_in_store>
104
+ </api_path>
105
+ </fields>
106
+ </personaliseit-delayed-preview>
107
+
108
+ <personaliseit-cpp translate="label" module="personaliseit">
109
+ <label>G3D CPP Settings</label>
110
+ <frontend_type>text</frontend_type>
111
+ <sort_order>1</sort_order>
112
+ <show_in_default>1</show_in_default>
113
+ <show_in_website>1</show_in_website>
114
+ <show_in_store>0</show_in_store>
115
+ <fields>
116
+ <api_path translate="label">
117
+ <label>API Path</label>
118
+ <frontend_type>text</frontend_type>
119
+ <sort_order>30</sort_order>
120
+ <show_in_default>1</show_in_default>
121
+ <show_in_website>1</show_in_website>
122
+ <show_in_store>0</show_in_store>
123
+ </api_path>
124
+ </fields>
125
+ </personaliseit-cpp>
126
+ </groups>
127
+ </general>
128
+ </sections>
129
+ </config>
130
+
app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->installEntities();
5
+
app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.0.0-1.1.0.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->addAttribute('catalog_product', 'personaliseit_gl_iframe_url', array(
6
+ 'section' =>'general',
7
+ 'group' => 'Gateway3D Personalise-iT',
8
+ 'label' => 'WebGL iFrame URL',
9
+ 'type' => 'varchar',
10
+ 'input' => 'text',
11
+ 'default' => '',
12
+ 'class' => '',
13
+ 'backend' => '',
14
+ 'frontend' => '',
15
+ 'source' => '',
16
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
17
+ 'visible' => true,
18
+ 'required' => false,
19
+ 'user_defined' => false,
20
+ 'searchable' => false,
21
+ 'filterable' => false,
22
+ 'comparable' => false,
23
+ 'visible_on_front' => false,
24
+ 'visible_in_advanced_search' => false,
25
+ 'unique' => false
26
+ ));
27
+
28
+ $installer->addAttribute('catalog_product', 'personaliseit_fl_iframe_url', array(
29
+ 'section' =>'general',
30
+ 'group' => 'Gateway3D Personalise-iT',
31
+ 'label' => 'Flash iFrame URL',
32
+ 'type' => 'varchar',
33
+ 'input' => 'text',
34
+ 'default' => '',
35
+ 'class' => '',
36
+ 'backend' => '',
37
+ 'frontend' => '',
38
+ 'source' => '',
39
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
40
+ 'visible' => true,
41
+ 'required' => false,
42
+ 'user_defined' => false,
43
+ 'searchable' => false,
44
+ 'filterable' => false,
45
+ 'comparable' => false,
46
+ 'visible_on_front' => false,
47
+ 'visible_in_advanced_search' => false,
48
+ 'unique' => false
49
+ ));
50
+
51
+ $installer->addAttribute('catalog_product', 'easypromo3d_url', array(
52
+ 'section' => 'general',
53
+ 'group' => 'Gateway3D Personalise-iT',
54
+ 'label' => 'Legacy Easypromo3D URL',
55
+ 'type' => 'varchar',
56
+ 'input' => 'text',
57
+ 'default' => '',
58
+ 'class' => '',
59
+ 'backend' => '',
60
+ 'frontend' => '',
61
+ 'source' => '',
62
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
63
+ 'visible' => true,
64
+ 'required' => false,
65
+ 'user_defined' => false,
66
+ 'searchable' => false,
67
+ 'filterable' => false,
68
+ 'comparable' => false,
69
+ 'visible_on_front' => false,
70
+ 'visible_in_advanced_search' => false,
71
+ 'unique' => false
72
+ ));
73
+
74
+ $installer->addAttribute('catalog_product', 'personaliseit_company_ref_id', array(
75
+ 'section' =>'general',
76
+ 'group' => 'Gateway3D Personalise-iT',
77
+ 'label' => '(Supplier) Company Ref ID',
78
+ 'type' => 'varchar',
79
+ 'input' => 'text',
80
+ 'default' => '',
81
+ 'class' => '',
82
+ 'backend' => '',
83
+ 'frontend' => '',
84
+ 'source' => '',
85
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
86
+ 'visible' => true,
87
+ 'required' => false,
88
+ 'user_defined' => false,
89
+ 'searchable' => false,
90
+ 'filterable' => false,
91
+ 'comparable' => false,
92
+ 'visible_on_front' => false,
93
+ 'visible_in_advanced_search' => false,
94
+ 'unique' => false
95
+ ));
96
+
97
+ $installer->addAttribute('catalog_product', 'personaliseit_pod_ref', array(
98
+ 'section' =>'general',
99
+ 'group' => 'Gateway3D Personalise-iT',
100
+ 'label' => 'Print-on-Demand Sample Ref',
101
+ 'type' => 'varchar',
102
+ 'input' => 'text',
103
+ 'default' => '',
104
+ 'class' => '',
105
+ 'backend' => '',
106
+ 'frontend' => '',
107
+ 'source' => '',
108
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
109
+ 'visible' => true,
110
+ 'required' => false,
111
+ 'user_defined' => false,
112
+ 'searchable' => false,
113
+ 'filterable' => false,
114
+ 'comparable' => false,
115
+ 'visible_on_front' => false,
116
+ 'visible_in_advanced_search' => false,
117
+ 'unique' => false
118
+ ));
119
+
120
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'sent', 'int not null default 0');
121
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'shipped', 'int not null default 0');
122
+ $installer->getConnection()->addColumn($installer->getTable('sales/order_item'), 'sl_order_id', 'int not null default 0');
app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.1.1-1.1.2.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $entityTypeId = $installer->getEntityTypeId('catalog_product');
6
+
7
+ $attributes = array(
8
+ 'personaliseit_gl_iframe_url',
9
+ 'personaliseit_fl_iframe_url',
10
+ 'personaliseit_m_iframe_url',
11
+ 'personaliseit_iframe_url',
12
+ 'easypromo3d_url',
13
+ );
14
+
15
+ foreach($attributes as $attribute)
16
+ {
17
+ $idAttributeOldSelect = $this->getAttribute($entityTypeId, $attribute, 'attribute_id');
18
+
19
+ $installer->updateAttribute($entityTypeId, $idAttributeOldSelect, 'backend_type', 'text');
20
+ }
app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.1.7.1-1.2.0.0.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'status_callback_ref', 'varchar(256) not null default ""');
app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.2.0.3-1.3.0.0.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->addAttribute('catalog_product', 'personaliseit_is_plain', array(
6
+ 'section' => 'general',
7
+ 'group' => 'Gateway3D Personalise-iT',
8
+ 'label' => 'Is Plain?',
9
+ 'type' => 'int',
10
+ 'input' => 'boolean',
11
+ 'default' => '',
12
+ 'class' => '',
13
+ 'backend' => '',
14
+ 'frontend' => '',
15
+ 'source' => 'eav/entity_attribute_source_table',
16
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
17
+ 'visible' => true,
18
+ 'required' => false,
19
+ 'user_defined' => false,
20
+ 'searchable' => false,
21
+ 'filterable' => false,
22
+ 'comparable' => false,
23
+ 'visible_on_front' => false,
24
+ 'visible_in_advanced_search' => false,
25
+ 'unique' => false
26
+ ));
app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.3.5.4-1.3.6.0.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->addAttribute('catalog_product', 'personaliseit_use_mageid', array(
6
+ 'section' => 'general',
7
+ 'group' => 'Gateway3D Personalise-iT',
8
+ 'label' => 'Use Magento product ID in iFrame callbacks?',
9
+ 'type' => 'int',
10
+ 'input' => 'boolean',
11
+ 'default' => '1',
12
+ 'class' => '',
13
+ 'backend' => '',
14
+ 'frontend' => '',
15
+ 'source' => 'eav/entity_attribute_source_table',
16
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
17
+ 'visible' => true,
18
+ 'required' => false,
19
+ 'user_defined' => false,
20
+ 'searchable' => false,
21
+ 'filterable' => false,
22
+ 'comparable' => false,
23
+ 'visible_on_front' => false,
24
+ 'visible_in_advanced_search' => false,
25
+ 'unique' => false
26
+ ));
app/code/local/Gateway3D/PersonaliseIt/sql/personaliseit_setup/mysql4-upgrade-1.3.6.0-1.4.0.0.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->addAttribute('catalog_product', 'personaliseit_dp_enabled', array(
6
+ 'section' => 'general',
7
+ 'group' => 'Gateway3D Personalise-iT',
8
+ 'label' => 'Enable delayed preview',
9
+ 'type' => 'int',
10
+ 'input' => 'boolean',
11
+ 'default' => '0',
12
+ 'class' => '',
13
+ 'backend' => '',
14
+ 'frontend' => '',
15
+ 'source' => 'eav/entity_attribute_source_table',
16
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
17
+ 'visible' => true,
18
+ 'required' => false,
19
+ 'user_defined' => false,
20
+ 'searchable' => false,
21
+ 'filterable' => false,
22
+ 'comparable' => false,
23
+ 'visible_on_front' => false,
24
+ 'visible_in_advanced_search' => false,
25
+ 'unique' => false
26
+ ));
27
+
28
+ $installer->addAttribute('catalog_product', 'personaliseit_dp_pid', array(
29
+ 'section' => 'general',
30
+ 'group' => 'Gateway3D Personalise-iT',
31
+ 'label' => 'Automatic print job creation product ID',
32
+ 'type' => 'int',
33
+ 'input' => 'text',
34
+ 'default' => '0',
35
+ 'class' => '',
36
+ 'backend' => '',
37
+ 'frontend' => '',
38
+ 'source' => 'eav/entity_attribute_source_table',
39
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
40
+ 'visible' => true,
41
+ 'required' => false,
42
+ 'user_defined' => false,
43
+ 'searchable' => false,
44
+ 'filterable' => false,
45
+ 'comparable' => false,
46
+ 'visible_on_front' => false,
47
+ 'visible_in_advanced_search' => false,
48
+ 'unique' => false
49
+ ));
app/design/adminhtml/default/default/template/personaliseit/catalog/product/edit/options.phtml ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <div class="entry-edit custom-options product-custom-options">
28
+ <div id="dynamic-price-warrning" style="display:none">
29
+ <ul class="messages">
30
+ <li class="error-msg">
31
+ <ul>
32
+ <li><?php echo $this->__('Bundle with dynamic pricing cannot include custom defined options. Options will not be saved.') ?></li>
33
+ </ul>
34
+ </li>
35
+ </ul>
36
+ </div>
37
+ <div class="entry-edit-head">
38
+ <h4><?php echo Mage::helper('catalog')->__('Custom Options') ?></h4>
39
+ <div class="right">
40
+ <?php echo $this->getImportFromCppButtonHtml() ?>
41
+ <?php echo $this->getAddButtonHtml() ?>
42
+ </div>
43
+ </div>
44
+
45
+ <div id="product_options_container" class="box">
46
+ <div id="product_options_container_top"></div>
47
+ <?php echo $this->getOptionsBoxHtml() ?>
48
+ </div>
49
+ </div>
50
+
51
+ <script type="text/javascript">
52
+ // re-bind form elements onchange
53
+ varienWindowOnload(true);
54
+ //show error message
55
+ if ($('price_type')) {
56
+ if ($('price_type').value == '0' && $('dynamic-price-warrning')) {
57
+ $('dynamic-price-warrning').show();
58
+ }
59
+ }
60
+ </script>
app/design/adminhtml/default/default/template/personaliseit/item_column_renderer_name.phtml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($_item = $this->getItem()): ?>
2
+ <h5 class="title"><?php echo $this->htmlEscape($_item->getName()) ?></h5>
3
+ <div><strong><?php echo $this->helper('sales')->__('SKU') ?>:</strong> <?php echo implode('<br />', Mage::helper('catalog')->splitSku($this->htmlEscape($this->getSku()))); ?></div>
4
+ <dl class="item-options">
5
+ <?php foreach ($this->getOrderOptions() as $_option): ?>
6
+ <dt><?php echo $_option['label'] ?></dt>
7
+ <dd>
8
+ <?php if (isset($_option['custom_view']) && $_option['custom_view']): ?>
9
+ <?php echo $this->getCustomizedOptionValue($_option); ?>
10
+ <?php else:
11
+ $_prepend=''; $_append='';
12
+ if(preg_match('/^https?:/i',$_option['value'])){
13
+ $_prepend='<a target="_new" href="'.$this->htmlEscape($_option['value']).'">'; $_append='</a>';
14
+ }
15
+ ?>
16
+ <?php echo $_prepend.Mage::helper('core/string')->truncate($_option['value'], 55, '', $_remainder).$_append;?>
17
+ <?php if ($_remainder):?>
18
+ ... <span id="<?php echo $_id = 'id' . uniqid()?>"><?php echo $_remainder ?></span>
19
+ <script type="text/javascript">
20
+ $('<?php echo $_id ?>').hide();
21
+ $('<?php echo $_id ?>').up().observe('mouseover', function(){$('<?php echo $_id ?>').show();});
22
+ $('<?php echo $_id ?>').up().observe('mouseout', function(){$('<?php echo $_id ?>').hide();});
23
+ </script>
24
+ <?php endif;?>
25
+ <?php endif;?>
26
+ </dd>
27
+ <?php endforeach; ?>
28
+ </dl>
29
+ <?php echo $this->htmlEscape($_item->getDescription()) ?>
30
+ <?php endif; ?>
app/design/adminhtml/default/default/template/personaliseit/option.phtml ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php echo $this->getTemplatesHtml() ?>
28
+
29
+ <script type="text/javascript">
30
+ //<![CDATA[
31
+ var firstStepTemplate = '<div class="option-box" id="option_{{id}}">'+
32
+ '<table id="<?php echo $this->getFieldId() ?>_{{id}}" class="option-header" cellpadding="0" cellspacing="0">'+
33
+ '<input type="hidden" id="<?php echo $this->getFieldId() ?>_{{id}}_is_delete" name="<?php echo $this->getFieldName() ?>[{{id}}][is_delete]" value="" />'+
34
+ '<input type="hidden" id="<?php echo $this->getFieldId() ?>_{{id}}_previous_type" name="<?php echo $this->getFieldName() ?>[{{id}}][previous_type]" value="{{type}}" />'+
35
+ '<input type="hidden" id="<?php echo $this->getFieldId() ?>_{{id}}_previous_group" name="<?php echo $this->getFieldName() ?>[{{id}}][previous_group]" value="" />'+
36
+ '<input type="hidden" id="<?php echo $this->getFieldId() ?>_{{id}}_id" name="<?php echo $this->getFieldName() ?>[{{id}}][id]" value="{{id}}" />'+
37
+ '<input type="hidden" id="<?php echo $this->getFieldId() ?>_{{id}}_option_id" name="<?php echo $this->getFieldName() ?>[{{id}}][option_id]" value="{{option_id}}" />'+
38
+ '<thead>'+
39
+ '<tr>'+
40
+ '<th class="opt-title"><?php echo Mage::helper('catalog')->__('Title') ?> <span class="required">*</span></th>'+
41
+ '<th class="opt-type"><?php echo Mage::helper('catalog')->__('Input Type') ?> <span class="required">*</span></th>'+
42
+ '<th class="opt-req"><?php echo $this->jsQuoteEscape(Mage::helper('catalog')->__('Is Required')) ?></th>'+
43
+ '<th class="opt-order"><?php echo Mage::helper('catalog')->__('Sort Order') ?></th>'+
44
+ '<th class="a-right"><?php echo $this->jsQuoteEscape($this->getDeleteButtonHtml()) ?></th>'+
45
+ '</tr>'+
46
+ '</thead>'+
47
+ '<tr>'+
48
+ '<td><input type="text" class="required-entry input-text" id="<?php echo $this->getFieldId() ?>_{{id}}_title" name="<?php echo $this->getFieldName() ?>[{{id}}][title]" value="{{title}}">{{checkboxScopeTitle}}</td>'+
49
+ '<td><?php echo $this->getTypeSelectHtml() ?></td>'+
50
+ '<td class="opt-req"><?php echo $this->getRequireSelectHtml() ?></td>'+
51
+ '<td><input type="text" class="validate-zero-or-greater input-text" name="<?php echo $this->getFieldName() ?>[{{id}}][sort_order]" value="{{sort_order}}"></td>'+
52
+ '<td>&nbsp;</td>'+
53
+ '</tr></table></div>';
54
+
55
+ var productOption = {
56
+ div : $('product_options_container_top'),
57
+ templateSyntax : /(^|.|\r|\n)({{(\w+)}})/,
58
+ templateText : firstStepTemplate,
59
+ itemCount : 1,
60
+ add : function(data) {
61
+ this.template = new Template(this.templateText, this.templateSyntax);
62
+
63
+ if(!data.id){
64
+ data = {};
65
+ data.id = this.itemCount;
66
+ data.type = '';
67
+ data.option_id = 0;
68
+ } else {
69
+ this.itemCount = data.item_count;
70
+ }
71
+
72
+ Element.insert(this.div, {'after':this.template.evaluate(data)});
73
+
74
+ //set selected type
75
+ if (data.type) {
76
+ $A($('<?php echo $this->getFieldId() ?>_'+data.id+'_type').options).each(function(option){
77
+ if (option.value==data.type) option.selected = true;
78
+ });
79
+ }
80
+
81
+ //set selected is_require
82
+ if (data.is_require) {
83
+ $A($('<?php echo $this->getFieldId() ?>_'+data.id+'_is_require').options).each(function(option){
84
+ if (option.value==data.is_require) option.selected = true;
85
+ });
86
+ }
87
+
88
+ if (data.checkboxScopeTitle) {
89
+ //set disabled
90
+ if ($('<?php echo $this->getFieldId() ?>_'+data.option_id+'_title') && data.scopeTitleDisabled) {
91
+ $('<?php echo $this->getFieldId() ?>_'+data.option_id+'_title').disable();
92
+ }
93
+ }
94
+
95
+ this.itemCount++;
96
+ this.bindRemoveButtons();
97
+ productOptionType.bindSelectInputType();
98
+ },
99
+ remove : function(event){
100
+ var element = $(Event.findElement(event, 'div'));
101
+ if(element){
102
+ $('product_'+element.readAttribute('id')+'_'+'is_delete').value = '1';
103
+ element.addClassName('no-display');
104
+ element.addClassName('ignore-validate');
105
+ element.hide();
106
+ }
107
+ },
108
+ bindRemoveButtons : function(){
109
+ var buttons = $$('div.product-custom-options .delete-product-option');
110
+ for(var i=0;i<buttons.length;i++){
111
+ if(!$(buttons[i]).binded){
112
+ $(buttons[i]).binded = true;
113
+ Event.observe(buttons[i], 'click', this.remove.bind(this));
114
+ }
115
+ }
116
+ var inputs = $$('div.product-custom-options button', 'div.product-custom-options input', 'div.product-custom-options select', 'div.product-custom-options textarea');
117
+ <?php if ($this->isReadonly()):?>
118
+ for (var i=0, l = inputs.length; i < l; i ++) {
119
+ inputs[i].disabled = true;
120
+ if (inputs[i].tagName.toLowerCase()=='button') {
121
+ inputs[i].addClassName('disabled');
122
+ }
123
+ }
124
+ <?php else: ?>
125
+ inputs.each(function(el) { Event.observe(el, 'change', el.setHasChanges.bind(el)); } )
126
+ <?php endif;?>
127
+ }
128
+ }
129
+
130
+
131
+ var productOptionType = {
132
+ templateSyntax : /(^|.|\r|\n)({{(\w+)}})/,
133
+ loadStepTwo : function(event){
134
+ var element = $(Event.findElement(event, 'select'));
135
+
136
+ var group = '';
137
+ var previousGroupElm = $(element.readAttribute('id').sub('_type', '_previous_group'));
138
+
139
+ switch(element.getValue()){
140
+ case 'field':
141
+ case 'area':
142
+ case 'hidden':
143
+ template = OptionTemplateText;
144
+ group = 'text';
145
+ break;
146
+ case 'file':
147
+ template = OptionTemplateFile;
148
+ group = 'file';
149
+ break;
150
+ case 'drop_down':
151
+ case 'radio':
152
+ case 'checkbox':
153
+ case 'multiple':
154
+ template = OptionTemplateSelect;
155
+ group = 'select';
156
+ break;
157
+ case 'date':
158
+ case 'date_time':
159
+ case 'time':
160
+ template = OptionTemplateDate;
161
+ group = 'date';
162
+ break;
163
+ default:
164
+ template = '';
165
+ group = 'unknown';
166
+ break;
167
+ }
168
+
169
+ if (previousGroupElm.getValue() != group) {
170
+ if ($(element.readAttribute('id')+'_'+previousGroupElm.getValue())) {
171
+ formElm = $(element.readAttribute('id')+'_'+previousGroupElm.getValue()).descendants();
172
+ formElm.each(function(elm){
173
+ if (elm.tagName == 'input' || elm.tagName == 'select') {
174
+ elm.name = '__delete__'+elm.readAttribute('name');
175
+ }
176
+ });
177
+
178
+ $(element.readAttribute('id')+'_'+previousGroupElm.getValue()).addClassName('no-display');
179
+ $(element.readAttribute('id')+'_'+previousGroupElm.getValue()).addClassName('ignore-validate');
180
+ $(element.readAttribute('id')+'_'+previousGroupElm.getValue()).hide();
181
+ }
182
+
183
+ previousGroupElm.value = group;
184
+
185
+ if ($(element.readAttribute('id')+'_'+group)) {
186
+ formElm = $(element.readAttribute('id')+'_'+group).descendants();
187
+ formElm.each(function(elm){
188
+ if (elm.match('input') || elm.match('select')) {
189
+ elm.name = elm.readAttribute('name').sub('__delete__', '');
190
+ }
191
+ });
192
+ $(element.readAttribute('id')+'_'+group).removeClassName('no-display');
193
+ $(element.readAttribute('id')+'_'+group).removeClassName('ignore-validate');
194
+ $(element.readAttribute('id')+'_'+group).show();
195
+
196
+ } else {
197
+ template = '<div id="'+element.readAttribute('id')+'_'+group+'" class="grid tier form-list">'+template+'</div><div id="'+element.readAttribute('id')+'_'+group+'_advice"></div';
198
+ this.secondTemplate = new Template(template, this.templateSyntax);
199
+
200
+ data = {};
201
+ if (!data.option_id) {
202
+ data = {};
203
+ data.option_id = $(element.readAttribute('id').sub('_type', '_id')).getValue();
204
+ }
205
+
206
+ Element.insert(element.readAttribute('id').sub('_type', ''), {'after':this.secondTemplate.evaluate(data)});
207
+
208
+ switch(element.getValue()){
209
+ case 'drop_down':
210
+ case 'radio':
211
+ case 'checkbox':
212
+ case 'multiple':
213
+ selectOptionType.bindAddButton();
214
+ break;
215
+ }
216
+ }
217
+ }
218
+ },
219
+ addDataToValues : function(data){
220
+
221
+ switch(data.type){
222
+ case 'field':
223
+ case 'area':
224
+ case 'hidden':
225
+ template = OptionTemplateText;
226
+ group = 'text';
227
+ break;
228
+ case 'file':
229
+ template = OptionTemplateFile;
230
+ group = 'file';
231
+ break;
232
+ case 'drop_down':
233
+ case 'radio':
234
+ case 'checkbox':
235
+ case 'multiple':
236
+ template = OptionTemplateSelect;
237
+ group = 'select';
238
+ break;
239
+ case 'date':
240
+ case 'date_time':
241
+ case 'time':
242
+ template = OptionTemplateDate;
243
+ group = 'date';
244
+ break;
245
+ }
246
+
247
+ $('<?php echo $this->getFieldId() ?>_'+data.id+'_previous_group').value = group;
248
+
249
+ template = '<div id="<?php echo $this->getFieldId() ?>_{{id}}_type_'+group+'" class="grid tier form-list">'+template+'</div><div id="<?php echo $this->getFieldId() ?>_{{id}}_type_'+group+'_advice"></div>';
250
+
251
+ this.secondTemplate = new Template(template, this.templateSyntax);
252
+
253
+ Element.insert($('<?php echo $this->getFieldId() ?>_'+data.option_id), {'after':this.secondTemplate.evaluate(data)});
254
+
255
+ if (data.checkboxScopePrice) {
256
+ //set disabled
257
+ if ($('<?php echo $this->getFieldId() ?>_'+data.option_id+'_price') && data.scopePriceDisabled) {
258
+ $('<?php echo $this->getFieldId() ?>_'+data.option_id+'_price').disable();
259
+ $('<?php echo $this->getFieldId() ?>_'+data.option_id+'_price_type').disable();
260
+ }
261
+ }
262
+
263
+ switch(data.type){
264
+ case 'drop_down':
265
+ case 'radio':
266
+ case 'checkbox':
267
+ case 'multiple':
268
+ data.optionValues.each(function(value) {
269
+ selectOptionType.add(value);
270
+ });
271
+ selectOptionType.bindAddButton();
272
+ break;
273
+ }
274
+
275
+ if (data.price_type) {
276
+ $A($('<?php echo $this->getFieldId() ?>_'+data.option_id+'_price_type').options).each(function(option){
277
+ if (option.value==data.price_type) option.selected = true;
278
+ });
279
+ }
280
+
281
+ },
282
+ bindSelectInputType : function(){
283
+ var types = $$('.select-product-option-type');
284
+ for(var i=0;i<types.length;i++){
285
+ if(!$(types[i]).binded){
286
+ $(types[i]).binded = true;
287
+ Event.observe(types[i], 'change', function(event){
288
+ productOptionType.loadStepTwo(event);
289
+ });
290
+ }
291
+ }
292
+ }
293
+ }
294
+
295
+ var productOptionScope = {
296
+ addScope : function(event){
297
+ var element = $(Event.element(event));
298
+ fieldToDisable = $(element.readAttribute('id').sub('_use_default', ''));
299
+
300
+ if (fieldToDisable.disabled) {
301
+ if (fieldToDisable.hasClassName('product-option-price')) {//need change to cheking value of element
302
+ $(fieldToDisable.readAttribute('id')+'_type').enable();
303
+ }
304
+ fieldToDisable.enable();
305
+ } else {
306
+ if (fieldToDisable.hasClassName('product-option-price')) {//need change to cheking value of element
307
+ $(fieldToDisable.readAttribute('id')+'_type').disable();
308
+ }
309
+ fieldToDisable.disable();
310
+ }
311
+ },
312
+ bindScopeCheckbox : function(){
313
+ var checkboxes = $$('.product-option-scope-checkbox');
314
+ for (var i=0;i<checkboxes.length;i++) {
315
+ if (!$(checkboxes[i]).binded) {
316
+ $(checkboxes[i]).binded = true;
317
+ Event.observe(checkboxes[i], 'click', this.addScope.bind(this));
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ if($('option_panel')){
324
+ $('option_panel').remove();
325
+ }
326
+
327
+ productOption.bindRemoveButtons();
328
+
329
+ if($('<?php echo $this->getAddButtonId() ?>')){
330
+ Event.observe('<?php echo $this->getAddButtonId() ?>', 'click', productOption.add.bind(productOption));
331
+ }
332
+
333
+ if($('<?php echo $this->getImportFromCppButtonId() ?>')) {
334
+ Event.observe('<?php echo $this->getImportFromCppButtonId() ?>', 'click', function() {
335
+ new Ajax.Request('<?php echo $this->getUrl('adminhtml/cpp/importOptions', array('id' => $this->getProduct()->getId())) ?>', {
336
+ type: 'POST',
337
+
338
+ onComplete: function(transport) {
339
+ window.location = '<?php echo $this->getUrl('*/*/edit', array(
340
+ '_current' => true,
341
+ 'back' => 'edit',
342
+ 'tab' => 'product_info_tabs_customer_options',
343
+ 'active_tab' => null
344
+ )) ?>'.replace('isAjax=1', '');
345
+ }.bind(this)
346
+ });
347
+ });
348
+ }
349
+
350
+ //validation for selected input type
351
+ Validation.addAllThese([
352
+ ['required-option-select', <?php echo $this->helper('core')->jsonEncode(Mage::helper('catalog')->__('Select type of option')) ?>, function(v, elm) {
353
+ if (elm.getValue() == '') {
354
+ return false;
355
+ }
356
+ return true;
357
+ }]]);
358
+
359
+ //adding data to templates
360
+ <?php foreach ($this->getOptionValues() as $_value): ?>
361
+ productOption.add(<?php echo $_value->toJson() ?>);
362
+ productOptionType.addDataToValues(<?php echo $_value->toJson() ?>);
363
+ <?php endforeach; ?>
364
+
365
+ //bind scope checkboxes
366
+ productOptionScope.bindScopeCheckbox();
367
+ //]]>
368
+ </script>
369
+
370
+ <div><?php if (!$this->isReadonly()):?><input type="hidden" name="affect_product_custom_options" value="1" /><?php endif;?></div>
app/design/frontend/base/default/layout/personaliseit.xml ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <catalog_product_view>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>js</type>
7
+ <name>personalise-it/delayed-preview.js</name>
8
+ </action>
9
+
10
+ <action method="addItem">
11
+ <type>js</type>
12
+ <name>prototype/window.js</name>
13
+ </action>
14
+
15
+ <action method="addItem">
16
+ <type>js_css</type>
17
+ <name>prototype/windows/themes/default.css</name>
18
+ </action>
19
+
20
+ <action method="addCss">
21
+ <name>lib/prototype/windows/themes/magento.css</name>
22
+ </action>
23
+ </reference>
24
+
25
+ <reference name="product.info.media">
26
+ <action method="setTemplate"><template>personaliseit/product/view/media.phtml</template></action>
27
+ </reference>
28
+
29
+ <reference name="product.info.addtocart">
30
+ <action method="setTemplate"><template>personaliseit/product/view/addtocart.phtml</template></action>
31
+ </reference>
32
+ </catalog_product_view>
33
+
34
+ <checkout_cart_index>
35
+ <reference name="checkout.cart">
36
+ <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>personaliseit/cart/item/default.phtml</template></action>
37
+ <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>personaliseit/cart/item/default.phtml</template></action>
38
+ <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>personaliseit/cart/item/default.phtml</template></action>
39
+ </reference>
40
+ </checkout_cart_index>
41
+
42
+ <personaliseit_products_index>
43
+ <remove name="right" />
44
+ <remove name="left" />
45
+
46
+ <reference name="root">
47
+ <action method="setTemplate">
48
+ <template>page/1column.phtml</template>
49
+ </action>
50
+ </reference>
51
+
52
+ <reference name="content">
53
+ <block type="core/template" name="personaliseit_products_index" template="personaliseit/products/index.phtml"></block>
54
+ </reference>
55
+ </personaliseit_products_index>
56
+
57
+ <personaliseit_product_callback>
58
+ <remove name="right" />
59
+ <remove name="left" />
60
+
61
+ <reference name="root">
62
+ <action method="setTemplate">
63
+ <template>page/1column.phtml</template>
64
+ </action>
65
+ </reference>
66
+
67
+ <reference name="content">
68
+ <block type="core/template" output="toHtml" name="root" template="personaliseit/product/callback.phtml"></block>
69
+ </reference>
70
+ </personaliseit_product_callback>
71
+ </layout>
app/design/frontend/base/default/template/personaliseit/cart/item/default.phtml ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $_item = $this->getItem();
29
+ $isVisibleProduct = $_item->getProduct()->isVisibleInSiteVisibility();
30
+ $canApplyMsrp = Mage::helper('catalog')->canApplyMsrp($_item->getProduct(), Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_BEFORE_ORDER_CONFIRM);
31
+
32
+ $productThumbnail = $this->getProductThumbnail()->resize(75);
33
+
34
+ $productOptions = $_item->getProduct()->getOptions();
35
+ $options = $this->getOptionList();
36
+
37
+ if($productOptions && $options)
38
+ {
39
+ foreach($options as $option)
40
+ {
41
+ if(
42
+ isset($productOptions[$option['option_id']]) &&
43
+ $productOptions[$option['option_id']]->getSku() == "thumburl")
44
+ {
45
+ $productThumbnail = $option['value'];
46
+ }
47
+ }
48
+ }
49
+ ?>
50
+ <tr>
51
+ <td><?php if ($this->hasProductUrl()):?><a href="<?php echo $this->getProductUrl() ?>" title="<?php echo $this->escapeHtml($this->getProductName()) ?>" class="product-image"><?php endif;?><img src="<?php echo $productThumbnail; ?>" width="75" height="75" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" /><?php if ($this->hasProductUrl()):?></a><?php endif;?></td>
52
+ <td>
53
+ <h2 class="product-name">
54
+ <?php if ($this->hasProductUrl()):?>
55
+ <a href="<?php echo $this->getProductUrl() ?>"><?php echo $this->escapeHtml($this->getProductName()) ?></a>
56
+ <?php else: ?>
57
+ <?php echo $this->escapeHtml($this->getProductName()) ?>
58
+ <?php endif; ?>
59
+ </h2>
60
+ <?php if ($_options = $this->getOptionList()):?>
61
+ <dl class="item-options">
62
+ <?php foreach ($_options as $_option) : ?>
63
+
64
+ <?php if($_option['option_type'] === Gateway3D_PersonaliseIt_Model_Catalog_Product_Option::OPTION_GROUP_HIDDEN) { continue; } ?>
65
+
66
+ <?php $_formatedOptionValue = $this->getFormatedOptionValue($_option) ?>
67
+ <dt><?php echo $this->escapeHtml($_option['label']) ?></dt>
68
+ <dd<?php if (isset($_formatedOptionValue['full_view'])): ?> class="truncated"<?php endif; ?>><?php echo $_formatedOptionValue['value'] ?>
69
+ <?php if (isset($_formatedOptionValue['full_view'])): ?>
70
+ <div class="truncated_full_value">
71
+ <dl class="item-options">
72
+ <dt><?php echo $this->escapeHtml($_option['label']) ?></dt>
73
+ <dd><?php echo $_formatedOptionValue['full_view'] ?></dd>
74
+ </dl>
75
+ </div>
76
+ <?php endif; ?>
77
+ </dd>
78
+ <?php endforeach; ?>
79
+ </dl>
80
+ <?php endif;?>
81
+ <?php if ($messages = $this->getMessages()): ?>
82
+ <?php foreach ($messages as $message): ?>
83
+ <p class="item-msg <?php echo $message['type'] ?>">* <?php echo $this->escapeHtml($message['text']) ?></p>
84
+ <?php endforeach; ?>
85
+ <?php endif; ?>
86
+ <?php $addInfoBlock = $this->getProductAdditionalInformationBlock(); ?>
87
+ <?php if ($addInfoBlock): ?>
88
+ <?php echo $addInfoBlock->setItem($_item)->toHtml() ?>
89
+ <?php endif;?>
90
+ </td>
91
+ <td class="a-center">
92
+ <?php if ($isVisibleProduct): ?>
93
+ <a href="<?php echo $this->getConfigureUrl() ?>" title="<?php echo $this->__('Edit item parameters') ?>"><?php echo $this->__('Edit') ?></a>
94
+ <?php endif ?>
95
+ </td>
96
+ <?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
97
+ <td class="a-center">
98
+ <?php if ($isVisibleProduct): ?>
99
+ <a href="<?php echo $this->helper('wishlist')->getMoveFromCartUrl($_item->getId()); ?>" class="link-wishlist use-ajax"><?php echo $this->__('Move'); ?></a>
100
+ <?php endif ?>
101
+ </td>
102
+ <?php endif ?>
103
+
104
+ <?php if ($canApplyMsrp): ?>
105
+ <td class="a-right"<?php if ($this->helper('tax')->displayCartBothPrices()): ?> colspan="2"<?php endif; ?>>
106
+ <span class="cart-price">
107
+ <span class="cart-msrp-unit"><?php echo $this->__('See price before order confirmation.'); ?></span>
108
+ <?php $helpLinkId = 'cart-msrp-help-' . $_item->getId(); ?>
109
+ <a id="<?php echo $helpLinkId ?>" href="#" class="map-help-link"><?php echo $this->__("What's this?"); ?></a>
110
+ <script type="text/javascript">
111
+ Catalog.Map.addHelpLink($('<?php echo $helpLinkId ?>'), "<?php echo $this->__("What's this?") ?>");
112
+ </script>
113
+ </span>
114
+ </td>
115
+ <?php else: ?>
116
+
117
+ <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
118
+ <td class="a-right">
119
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
120
+ <span class="cart-tax-total" onclick="taxToggle('eunit-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
121
+ <?php else: ?>
122
+ <span class="cart-price">
123
+ <?php endif; ?>
124
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
125
+ <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?>
126
+ <?php else: ?>
127
+ <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()) ?>
128
+ <?php endif; ?>
129
+
130
+ </span>
131
+
132
+
133
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
134
+
135
+ <div class="cart-tax-info" id="eunit-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
136
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
137
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
138
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount'],true,true); ?></span>
139
+ <?php endforeach; ?>
140
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
141
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
142
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span>
143
+ <?php endforeach; ?>
144
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
145
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
146
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span>
147
+ <?php endforeach; ?>
148
+ <?php endif; ?>
149
+ </div>
150
+
151
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
152
+ <div class="cart-tax-total" onclick="taxToggle('eunit-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
153
+ <span class="weee"><?php echo Mage::helper('weee')->__('Total'); ?>: <?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?></span>
154
+ </div>
155
+ <?php endif; ?>
156
+ <?php endif; ?>
157
+ </td>
158
+ <?php endif; ?>
159
+ <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
160
+ <td>
161
+ <?php $_incl = $this->helper('checkout')->getPriceInclTax($_item); ?>
162
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
163
+ <span class="cart-tax-total" onclick="taxToggle('unit-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
164
+ <?php else: ?>
165
+ <span class="cart-price">
166
+ <?php endif; ?>
167
+
168
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
169
+ <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedAmount()); ?>
170
+ <?php else: ?>
171
+ <?php echo $this->helper('checkout')->formatPrice($_incl-$_item->getWeeeTaxDisposition()) ?>
172
+ <?php endif; ?>
173
+
174
+ </span>
175
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
176
+
177
+ <div class="cart-tax-info" id="unit-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
178
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
179
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
180
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount'],true,true); ?></span>
181
+ <?php endforeach; ?>
182
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
183
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
184
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span>
185
+ <?php endforeach; ?>
186
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
187
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
188
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['amount_incl_tax'],true,true); ?></span>
189
+ <?php endforeach; ?>
190
+ <?php endif; ?>
191
+ </div>
192
+
193
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
194
+ <div class="cart-tax-total" onclick="taxToggle('unit-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
195
+ <span class="weee"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>: <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedAmount()); ?></span>
196
+ </div>
197
+ <?php endif; ?>
198
+ <?php endif; ?>
199
+ </td>
200
+ <?php endif; ?>
201
+ <?php endif; ?>
202
+ <td class="a-center">
203
+ <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" />
204
+ </td>
205
+ <?php if (($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) && !$_item->getNoSubtotal()): ?>
206
+ <td class="a-right">
207
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
208
+ <span class="cart-tax-total" onclick="taxToggle('esubtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
209
+ <?php else: ?>
210
+ <span class="cart-price">
211
+ <?php endif; ?>
212
+
213
+ <?php if ($canApplyMsrp): ?>
214
+ <span class="cart-msrp-subtotal">--</span>
215
+ <?php else: ?>
216
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
217
+ <?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?>
218
+ <?php else: ?>
219
+ <?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()) ?>
220
+ <?php endif; ?>
221
+ <?php endif; ?>
222
+
223
+ </span>
224
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
225
+
226
+ <div class="cart-tax-info" id="esubtotal-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
227
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
228
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
229
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount'],true,true); ?></span>
230
+ <?php endforeach; ?>
231
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
232
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
233
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span>
234
+ <?php endforeach; ?>
235
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
236
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
237
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span>
238
+ <?php endforeach; ?>
239
+ <?php endif; ?>
240
+ </div>
241
+
242
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
243
+ <div class="cart-tax-total" onclick="taxToggle('esubtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
244
+ <span class="weee"><?php echo Mage::helper('weee')->__('Total'); ?>: <?php echo $this->helper('checkout')->formatPrice($_item->getRowTotal()+$_item->getWeeeTaxAppliedRowAmount()+$_item->getWeeeTaxRowDisposition()); ?></span>
245
+ </div>
246
+ <?php endif; ?>
247
+ <?php endif; ?>
248
+ </td>
249
+ <?php endif; ?>
250
+ <?php if (($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) && !$_item->getNoSubtotal()): ?>
251
+ <td>
252
+ <?php $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); ?>
253
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
254
+ <span class="cart-tax-total" onclick="taxToggle('subtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
255
+ <?php else: ?>
256
+ <span class="cart-price">
257
+ <?php endif; ?>
258
+
259
+ <?php if ($canApplyMsrp): ?>
260
+ <span class="cart-msrp-subtotal">--</span>
261
+ <?php else: ?>
262
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, array(0, 1, 4), 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
263
+ <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedRowAmount()); ?>
264
+ <?php else: ?>
265
+ <?php echo $this->helper('checkout')->formatPrice($_incl-$_item->getWeeeTaxRowDisposition()) ?>
266
+ <?php endif; ?>
267
+ <?php endif; ?>
268
+
269
+ </span>
270
+
271
+
272
+ <?php if (Mage::helper('weee')->getApplied($_item)): ?>
273
+
274
+ <div class="cart-tax-info" id="subtotal-item-tax-details<?php echo $_item->getId(); ?>" style="display:none;">
275
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
276
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
277
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount'],true,true); ?></span>
278
+ <?php endforeach; ?>
279
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
280
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
281
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span>
282
+ <?php endforeach; ?>
283
+ <?php elseif (Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
284
+ <?php foreach (Mage::helper('weee')->getApplied($_item) as $tax): ?>
285
+ <span class="weee"><?php echo $tax['title']; ?>: <?php echo Mage::helper('checkout')->formatPrice($tax['row_amount_incl_tax'],true,true); ?></span>
286
+ <?php endforeach; ?>
287
+ <?php endif; ?>
288
+ </div>
289
+
290
+ <?php if (Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales') && $_item->getWeeeTaxAppliedAmount()): ?>
291
+ <div class="cart-tax-total" onclick="taxToggle('subtotal-item-tax-details<?php echo $_item->getId(); ?>', this, 'cart-tax-total-expanded');">
292
+ <span class="weee"><?php echo Mage::helper('weee')->__('Total incl. tax'); ?>: <?php echo $this->helper('checkout')->formatPrice($_incl+$_item->getWeeeTaxAppliedRowAmount()); ?></span>
293
+ </div>
294
+ <?php endif; ?>
295
+ <?php endif; ?>
296
+ </td>
297
+ <?php endif; ?>
298
+ <td class="a-center"><a href="<?php echo $this->getDeleteUrl()?>" title="<?php echo $this->__('Remove item')?>" class="btn-remove btn-remove2"><?php echo $this->__('Remove item')?></a></td>
299
+ </tr>
app/design/frontend/base/default/template/personaliseit/product/callback.phtml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script>
5
+ setTimeout(function() {
6
+ window.top.location = "<?= $this->redirect ?>";
7
+ }, 250);
8
+ </script>
9
+
10
+ <title>Adding to Cart...</title>
11
+ </head>
12
+ <body>
13
+ <h2 style="font-family: Arial, Helvetica, sans-serif; font-size: 1.8em; color: #888"><?= $this->message ?></h2>
14
+ </body>
15
+ </html>
app/design/frontend/base/default/template/personaliseit/product/view/addtocart.phtml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_product = $this->getProduct(); ?>
28
+ <?php $prevewButtonTitle = $this->__('Preview'); ?>
29
+ <?php $buttonTitle = $this->__('Add to Cart'); ?>
30
+ <?php if($_product->isSaleable()): ?>
31
+ <div class="add-to-cart">
32
+ <?php if(!$_product->isGrouped()): ?>
33
+ <label for="qty"><?php echo $this->__('Qty:') ?></label>
34
+ <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
35
+ <?php endif; ?>
36
+ <?php if($_product->personaliseit_dp_enabled): ?>
37
+ <button type="button" title="<?php echo $prevewButtonTitle ?>" class="button btn-cart" onclick="delayedPreview.preview()"><span><span><?php echo $prevewButtonTitle ?></span></span></button>
38
+ <?php endif; ?>
39
+ <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
40
+ <?php echo $this->getChildHtml('', true, true) ?>
41
+ </div>
42
+ <?php endif; ?>
app/design/frontend/base/default/template/personaliseit/product/view/media.phtml ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+ * @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Product media data template
29
+ *
30
+ * @see Mage_Catalog_Block_Product_View_Media
31
+ */
32
+ ?>
33
+
34
+ <?php
35
+ $product = $_product = $this->getProduct();
36
+ $_helper = $this->helper('catalog/output');
37
+
38
+ $messageEventHelper = new Gateway3D_PersonaliseIt_Helper_MessageEvent;
39
+
40
+ // Build EPA and callback URLs
41
+ $params = $product->personaliseit_use_mageid
42
+ ? array('id' => $_product->getId())
43
+ : array();
44
+
45
+ $params['_nosid'] = true;
46
+
47
+ $epa = Mage::getUrl('personaliseit/product/epa', $params);
48
+ $callback = Mage::getUrl('personaliseit/product/callback', $params);
49
+
50
+ // Build URLs
51
+ $query = http_build_query(array(
52
+ 'a2cpost' => 1,
53
+ 'epa' => $epa,
54
+ 'ep3dUrl' => $callback,
55
+ 'guid' => $product->personaliseit_company_ref_id,
56
+ 'meo' => $messageEventHelper->getOrigin(Mage::getBaseUrl()),
57
+ 'mei' => $messageEventHelper->getId()
58
+ ));
59
+
60
+ $urlParams = array(
61
+ 'a2cpost' => 1,
62
+ 'epa' => $epa,
63
+ 'ep3dUrl' => $callback,
64
+ 'guid' => $product->personaliseit_company_ref_id,
65
+ 'meo' => $messageEventHelper->getOrigin(Mage::getBaseUrl()),
66
+ 'mei' => $messageEventHelper->getId()
67
+ );
68
+
69
+ // URL fields and the order of preference.
70
+ $_urls = array(
71
+ 'webgl' => 'personaliseit_gl_iframe_url',
72
+ 'flash' => 'personaliseit_fl_iframe_url',
73
+ 'mobile' => 'personaliseit_m_iframe_url',
74
+ 'standard' => 'personaliseit_iframe_url',
75
+ 'legacy' => 'easypromo3d_url',
76
+ );
77
+
78
+ $urls = array_map(function($u) use ($product, $query, $messageEventHelper, $urlParams)
79
+ {
80
+ $present = !!$product->{$u};
81
+
82
+ $_urlParams = $urlParams;
83
+
84
+ foreach($urlParams as $key => $value)
85
+ {
86
+ if(preg_match("/{$key}=/", $product->{$u}))
87
+ {
88
+ unset($_urlParams[$key]);
89
+ }
90
+ }
91
+
92
+ $query = http_build_query($_urlParams);
93
+ $url = "{$product->$u}&{$query}";
94
+
95
+ return $present
96
+ ? array(
97
+ 'url' => $url,
98
+ 'origin' => $messageEventHelper->getOrigin($url))
99
+ : false;
100
+ }, $_urls);
101
+
102
+ $hasUrl = count(array_filter($urls, function($url) {
103
+ return $url;
104
+ })) > 0;
105
+ ?>
106
+
107
+ <style>
108
+ #personalise-it-iframe {
109
+ border: 0; width: 100%; height: 100%;
110
+ }
111
+ </style>
112
+
113
+ <?php if($hasUrl && $product->personaliseit_company_ref_id && !$product->personaliseit_dp_enabled): ?>
114
+ <iframe id="personalise-it-iframe" style="" src=""></iframe>
115
+ <?php else: ?>
116
+ <?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
117
+ <p class="product-image product-image-zoom">
118
+ <?php
119
+ $_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->escapeHtml($this->getImageLabel()).'" title="'.$this->escapeHtml($this->getImageLabel()).'" />';
120
+ echo $_helper->productAttribute($_product, $_img, 'image');
121
+ ?>
122
+ </p>
123
+ <p class="zoom-notice" id="track_hint"><?php echo $this->__('Double click on above image to view full picture') ?></p>
124
+ <div class="zoom">
125
+ <img id="zoom_out" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_out.gif') ?>" alt="<?php echo $this->__('Zoom Out') ?>" title="<?php echo $this->__('Zoom Out') ?>" class="btn-zoom-out" />
126
+ <div id="track">
127
+ <div id="handle"></div>
128
+ </div>
129
+ <img id="zoom_in" src="<?php echo $this->getSkinUrl('images/slider_btn_zoom_in.gif') ?>" alt="<?php echo $this->__('Zoom In') ?>" title="<?php echo $this->__('Zoom In') ?>" class="btn-zoom-in" />
130
+ </div>
131
+ <script type="text/javascript">
132
+ //<![CDATA[
133
+ Event.observe(window, 'load', function() {
134
+ product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
135
+ });
136
+ //]]>
137
+ </script>
138
+ <?php else: ?>
139
+ <p class="product-image">
140
+ <?php
141
+ $_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(265).'" alt="'.$this->escapeHtml($this->getImageLabel()).'" title="'.$this->escapeHtml($this->getImageLabel()).'" />';
142
+ echo $_helper->productAttribute($_product, $_img, 'image');
143
+ ?>
144
+ </p>
145
+ <?php endif; ?>
146
+ <?php if (count($this->getGalleryImages()) > 0): ?>
147
+ <div class="more-views">
148
+ <h2><?php echo $this->__('More Views') ?></h2>
149
+ <ul>
150
+ <?php foreach ($this->getGalleryImages() as $_image): ?>
151
+ <li>
152
+ <a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->escapeHtml($_image->getLabel()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->escapeHtml($_image->getLabel()) ?>" /></a>
153
+ </li>
154
+ <?php endforeach; ?>
155
+ </ul>
156
+ </div>
157
+ <?php endif; ?>
158
+ <?php endif; ?>
159
+
160
+ <?php if($hasUrl && $product->personaliseit_company_ref_id): ?>
161
+ <script>
162
+ var urls = <?php echo json_encode($urls); ?>;
163
+
164
+ // Remove the mobile URL if we're not on a mobile.
165
+ var isMobile = window.matchMedia && window.matchMedia("(max-width: 800px)").matches;
166
+
167
+ if(!isMobile) {
168
+ urls['mobile'] = false;
169
+ }
170
+
171
+ // Remove the WebGL URL if there is no WebGL support.
172
+ var hasWebGl = !!document.createElement('canvas').getContext("webgl") || !!document.createElement('canvas').getContext('experimental-webgl');
173
+
174
+ if(!hasWebGl) {
175
+ urls['webgl'] = false;
176
+ }
177
+
178
+ // Remove the Flash URL if there is no Flash support.
179
+ var hasFlash = ((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false));
180
+
181
+ if(!hasFlash) {
182
+ urls['flash'] = false;
183
+ }
184
+
185
+ // Find the first available iframe URL.
186
+ var url = "";
187
+ var origin = "";
188
+
189
+ for(var type in urls) {
190
+ if(urls[type]) {
191
+ url = urls[type].url;
192
+ origin = urls[type].origin;
193
+ break;
194
+ }
195
+ }
196
+
197
+ <?php if(!$product->personaliseit_dp_enabled): ?>
198
+ document.getElementById('personalise-it-iframe').src = url;
199
+ <?php else: ?>
200
+ var delayedPreview = new PersonaliseIt.DelayedPreview(url, '<?= $messageEventHelper->getId() ?>', origin);
201
+ <?php
202
+ foreach($product->getOptions() as $o)
203
+ {
204
+ $matches = array();
205
+
206
+ if(preg_match('/^userText([0-9]*)$/', $o->sku, $matches))
207
+ {
208
+ ?>
209
+
210
+ delayedPreview.addTextField('options_' + <?= $o->option_id ?> + '_text', <?= $matches[1] ?>);
211
+
212
+ <?php
213
+ }
214
+ }
215
+ ?>
216
+ <?php endif; ?>
217
+ </script>
218
+ <?php endif; ?>
app/design/frontend/base/default/template/personaliseit/products/index.phtml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+ $params = array('_nosid' => true);
3
+
4
+ $epa = Mage::getUrl('personaliseit/product/epa', $params);
5
+ $callback = Mage::getUrl('personaliseit/product/callback', $params);
6
+
7
+ $query = http_build_query(array(
8
+ 'a2cpost' => 1,
9
+ 'epa' => $epa,
10
+ 'ep3dUrl' => $callback,
11
+ ));
12
+
13
+ $urls = array(
14
+ 'mobile' => 'mobile_iframe_url',
15
+ 'standard' => 'iframe_url',
16
+ );
17
+
18
+ foreach($urls as &$url)
19
+ {
20
+ $url = trim(Mage::getStoreConfig("general/personaliseit-product-selector/{$url}"));
21
+ }
22
+ ?>
23
+
24
+ <iframe id="personalise-it-iframe" style="border: 0; width: 100%; height: 100%;" src=""></iframe>
25
+
26
+ <script>
27
+ var urls = <?php echo json_encode($urls); ?>;
28
+
29
+ // Remove the mobile URL if we're not on a mobile.
30
+ var isMobile = window.matchMedia && window.matchMedia("(max-width: 800px)").matches;
31
+
32
+ if(!isMobile) {
33
+ urls['mobile'] = false;
34
+ }
35
+
36
+ // Find the first available iframe URL.
37
+ var url = "";
38
+
39
+ for(var type in urls) {
40
+ if(urls[type]) {
41
+ url = urls[type];
42
+ break;
43
+ }
44
+ }
45
+
46
+ document.getElementById('personalise-it-iframe').src = url;
47
+ </script>
48
+
app/etc/modules/Gateway3D_PersonaliseIt.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2013 Gateway 3D Ltd.
8
+ */
9
+ -->
10
+
11
+ <config>
12
+ <modules>
13
+ <Gateway3D_PersonaliseIt>
14
+ <active>true</active>
15
+ <codePool>local</codePool>
16
+ </Gateway3D_PersonaliseIt>
17
+ </modules>
18
+ </config>
19
+
js/personalise-it/delayed-preview.js ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var PersonaliseIt = PersonaliseIt || {};
2
+
3
+ PersonaliseIt.DelayedPreview = (function() {
4
+ function DelayedPreview(url, id, origin) {
5
+ this.url = url;
6
+ this.id = id;
7
+ this.origin = origin;
8
+
9
+ this.textFields = {};
10
+ this.busyCount = 1;
11
+
12
+ window.addEventListener("message", function(e) {
13
+ if(e.origin === origin && e.data.id === id) {
14
+ switch(e.data.name) {
15
+ case 'SHOW_BUSY': this.busyCount++; break;
16
+
17
+ case 'HIDE_BUSY': // fall through
18
+ case 'RENDERER_READY':
19
+ this.busyCount--; break;
20
+ }
21
+ }
22
+ });
23
+ }
24
+
25
+ DelayedPreview.prototype.addTextField = function(optionId, areaId) {
26
+ this.textFields[optionId] = areaId;
27
+ };
28
+
29
+ DelayedPreview.prototype.update = function(iframeWindow) {
30
+ for(var optionId in this.textFields) {
31
+ var text = $$('#' + optionId)[0].value;
32
+
33
+ iframeWindow.postMessage({
34
+ id: this.id,
35
+ name: 'SET_TEXT_AREA_TEXT',
36
+
37
+ body: {
38
+ areaId: this.textFields[optionId],
39
+ text: text
40
+ }
41
+ }, this.origin);
42
+ }
43
+ };
44
+
45
+ DelayedPreview.prototype.preview = function() {
46
+ this.busyCount = 0;
47
+
48
+ var popup = new Window({
49
+ id:'preview',
50
+ className: 'magento',
51
+ url: this.url,
52
+
53
+ width: 820,
54
+ height: 600,
55
+
56
+ minimizable: false,
57
+ maximizable: false,
58
+
59
+ showEffectOptions: {
60
+ duration: 0.4
61
+ },
62
+
63
+ hideEffectOptions:{
64
+ duration: 0.4
65
+ },
66
+
67
+ onload: (function() {
68
+ var window = $$('#preview_content')[0].contentWindow;
69
+
70
+ var int = setInterval((function() {
71
+ if(this.busyCount === 0) {
72
+ clearInterval(int);
73
+
74
+ this.update(window);
75
+ }
76
+ }).bind(this), 100);
77
+ }).bind(this),
78
+
79
+ destroyOnClose: true
80
+ });
81
+
82
+ popup.setZIndex(100);
83
+ popup.showCenter(true);
84
+ };
85
+
86
+ return DelayedPreview;
87
+ })();
lib/Gateway3D/PersonaliseIt/Service/Api/Abstract.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ /**
11
+ * Abstract class for building API services.
12
+ */
13
+ abstract class Gateway3D_PersonaliseIt_Service_Api_Abstract
14
+ {
15
+ /**
16
+ * API endpoint.
17
+ *
18
+ * @var string
19
+ */
20
+ protected $_url = "";
21
+
22
+ /**
23
+ * Http client.
24
+ *
25
+ * @var Zend_Http_Client
26
+ */
27
+ protected $_client = null;
28
+
29
+ /**
30
+ * Http client response.
31
+ *
32
+ * @var Zend_Http_Response
33
+ */
34
+ protected $_response = null;
35
+
36
+ public function __construct($url)
37
+ {
38
+ $this->_url = $url;
39
+ }
40
+
41
+ /**
42
+ * Execute a create request on the endpoint.
43
+ *
44
+ * @param Gateway3D_PersonaliseIt_Service_Dto $dto
45
+ * @param array $options
46
+ * @return Gateway3D_PersonaliseIt_Service_Dto
47
+ */
48
+ public function create(Gateway3D_PersonaliseIt_Service_Dto_Abstract $dto, $options = array())
49
+ {
50
+ $url = $this->_getCreateUrl();
51
+
52
+ $this->_initClient($url, Zend_Http_Client::POST, $dto->toArray());
53
+
54
+ return $this->_marshalToDto($dto, $this->_getResponse());
55
+ }
56
+
57
+ /**
58
+ * Execute an update request on the endpoint.
59
+ *
60
+ * @param Gateway3D_PersonaliseIt_Service_Dto $dto
61
+ * @param array $options
62
+ * @return Gateway3D_PersonaliseIt_Service_Dto
63
+ */
64
+ public function update(Gateway3D_PersonaliseIt_Service_Dto_Abstract $dto, $options = array())
65
+ {
66
+ $url = $this->_getUpdateUrl($dto->getId());
67
+
68
+ $this->_initClient($url, Zend_Http_Client::PUT, $dto->toArray());
69
+
70
+ return $this->_marshalToDto($dto, $this->_getResponse());
71
+ }
72
+
73
+ /**
74
+ * Retrieves an entity from the endpoint.
75
+ *
76
+ * @param Gateway3D_PersonaliseIt_Service_Dto $dto
77
+ * @param array $options
78
+ * @return Gateway3D_PersonaliseIt_Service_Dto
79
+ */
80
+ public function retrieve($idOrDto, $options = array())
81
+ {
82
+ if($idOrDto instanceof Gateway3D_PersonaliseIt_Service_Dto_Abstract)
83
+ {
84
+ $dto = $idOrDto;
85
+ }
86
+ else
87
+ {
88
+ $dto = $this->_newDto();
89
+ $dto->setId($idOrDto);
90
+ }
91
+
92
+ $url = $this->_getRetrieveUrl($dto->getId());
93
+
94
+ $this->_initClient($url, Zend_Http_Client::GET);
95
+
96
+ return $this->_marshalToDto($dto, $this->_getResponse());
97
+ }
98
+
99
+ /**
100
+ * Builds a URL to be used for creation requests.
101
+ */
102
+ abstract protected function _getCreateUrl();
103
+
104
+ /**
105
+ * Builds a URL to be used for update requests.
106
+ */
107
+ abstract protected function _getUpdateUrl($id);
108
+
109
+ /**
110
+ * Builds a URL to be used for retrieval requests.
111
+ */
112
+ abstract protected function _getRetrieveUrl($id);
113
+
114
+ /**
115
+ * Create a new DTO specific for the current API.
116
+ */
117
+ abstract protected function _newDto();
118
+
119
+ /**
120
+ * Marshals an array into a Dto object.
121
+ *
122
+ * @param Gateway3D_PersonaliseIt_Service_Dto $dto
123
+ * @param array $data
124
+ */
125
+ protected function _marshalToDto(Gateway3D_PersonaliseIt_Service_Dto_Abstract $dto, array $data)
126
+ {
127
+ foreach($data as $k => $v)
128
+ {
129
+ if(property_exists($dto, $k))
130
+ {
131
+ $dto->{$k} = $v;
132
+ }
133
+ }
134
+
135
+ return $dto;
136
+ }
137
+
138
+ /**
139
+ * Initialises the http client.
140
+ *
141
+ * @param string $url
142
+ * @param string $method
143
+ * @param array $data Content of request.
144
+ */
145
+ protected function _initClient($url, $method, array $data = null)
146
+ {
147
+ $this->_client = new Zend_Http_Client($url);
148
+ $this->_client->setMethod($method);
149
+
150
+ if(is_array($data))
151
+ {
152
+ $this->_client->setRawData(Zend_Json::encode($data));
153
+ }
154
+ }
155
+
156
+ protected function _getResponse()
157
+ {
158
+ $this->_response = $this->_client->request();
159
+
160
+ try
161
+ {
162
+ $object = Zend_Json::decode($this->_response->getBody());
163
+ }
164
+ catch(Zend_Json_Exception $e)
165
+ {
166
+ Mage::throwException("Invalid JSON: {$this->_response->getBody()}");
167
+ }
168
+
169
+ if($this->_response->isError())
170
+ {
171
+ $message = $object['error']['message'];
172
+ Mage::throwException($message);
173
+ }
174
+ else
175
+ {
176
+ return $object;
177
+ }
178
+ }
179
+ }
lib/Gateway3D/PersonaliseIt/Service/Api/P1/Product.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Api_P1_Product
11
+ extends Gateway3D_PersonaliseIt_Service_Api_Abstract
12
+ {
13
+ protected function _getCreateUrl()
14
+ {
15
+ $this->_notSupported();
16
+ }
17
+
18
+ protected function _getUpdateUrl($id)
19
+ {
20
+ $this->_notSupported();
21
+ }
22
+
23
+ protected function _getRetrieveUrl($id)
24
+ {
25
+ return "{$this->_url}/?id={$id}";
26
+ }
27
+
28
+ protected function _newDto()
29
+ {
30
+ return new Gateway3D_PersonaliseIt_Service_Dto_P1_Product;
31
+ }
32
+
33
+ private function _notSupported()
34
+ {
35
+ Mage::throwException("Operation not supported");
36
+ }
37
+ }
38
+
lib/Gateway3D/PersonaliseIt/Service/Api/P1/Sample.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Api_P1_Sample
11
+ extends Gateway3D_PersonaliseIt_Service_Api_Abstract
12
+ {
13
+ protected function _getCreateUrl()
14
+ {
15
+ $this->_notSupported();
16
+ }
17
+
18
+ protected function _getUpdateUrl($id)
19
+ {
20
+ $this->_notSupported();
21
+ }
22
+
23
+ protected function _getRetrieveUrl($id)
24
+ {
25
+ return "{$this->_url}/?id={$id}";
26
+ }
27
+
28
+ protected function _newDto()
29
+ {
30
+ return new Gateway3D_PersonaliseIt_Service_Dto_P1_Sample;
31
+ }
32
+
33
+ private function _notSupported()
34
+ {
35
+ Mage::throwException("Operation not supported");
36
+ }
37
+ }
38
+
lib/Gateway3D/PersonaliseIt/Service/Api/P2/PrintJob.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Api_P2_PrintJob
11
+ extends Gateway3D_PersonaliseIt_Service_Api_Abstract
12
+ {
13
+ const OPTION_IMPLICIT = 'implicit';
14
+
15
+ public function create(Gateway3D_PersonaliseIt_Service_Dto $dto, $options = array())
16
+ {
17
+ $url = $this->_getCreateUrl();
18
+
19
+ $data = array('options' => $options, 'print_job' => $dto->toArray());
20
+
21
+ $this->_initClient($url, Zend_Http_Client::POST, $data);
22
+
23
+ return $this->_marshalToDto($dto, $this->_getResponse());
24
+ }
25
+
26
+ protected function _getCreateUrl()
27
+ {
28
+ return $this->_url;
29
+ }
30
+
31
+ protected function _getUpdateUrl($id)
32
+ {
33
+ $this->_notSupported();
34
+ }
35
+
36
+ protected function _getRetrieveUrl($id)
37
+ {
38
+ $this->_notSupported();
39
+ }
40
+
41
+ protected function _newDto()
42
+ {
43
+ return new Gateway3D_PersonaliseIt_Service_Dto_P2_PrintJob;
44
+ }
45
+
46
+ private function _notSupported()
47
+ {
48
+ Mage::throwException("Operation not supported");
49
+ }
50
+ }
51
+
lib/Gateway3D/PersonaliseIt/Service/Api/Sl/Order.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Api_Sl_Order
11
+ extends Gateway3D_PersonaliseIt_Service_Api_Abstract
12
+ {
13
+ protected $_key = "";
14
+
15
+ public function __construct($url, $key)
16
+ {
17
+ parent::__construct($url);
18
+
19
+ $this->_key = $key;
20
+ }
21
+
22
+ protected function _getCreateUrl()
23
+ {
24
+ return "{$this->_url}?k={$this->_key}";
25
+ }
26
+
27
+ protected function _getUpdateUrl($id)
28
+ {
29
+ return "{$this->_url}?o={$id}&k={$this->_key}";
30
+ }
31
+
32
+ protected function _getRetrieveUrl($id)
33
+ {
34
+ return "{$this->_url}?o={$id}&k={$this->_key}";
35
+ }
36
+
37
+ protected function _newDto()
38
+ {
39
+ return new Gateway3D_PersonaliseIt_Service_Dto_Sl_Order;
40
+ }
41
+ }
42
+
lib/Gateway3D/PersonaliseIt/Service/Dto/Abstract.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ abstract class Gateway3D_PersonaliseIt_Service_Dto_Abstract
11
+ implements Gateway3D_PersonaliseIt_Service_Dto_Interface
12
+ {
13
+ public function toArray()
14
+ {
15
+ return (array)$this;
16
+ }
17
+ }
lib/Gateway3D/PersonaliseIt/Service/Dto/Interface.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ interface Gateway3D_PersonaliseIt_Service_Dto_Interface
11
+ {
12
+ function getId();
13
+ function setId($id);
14
+ function toArray();
15
+ }
lib/Gateway3D/PersonaliseIt/Service/Dto/P1/Product.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Dto_P1_Product
11
+ extends Gateway3D_PersonaliseIt_Service_Dto_Abstract
12
+ {
13
+ public $id = 0;
14
+ public $text_areas = array();
15
+ public $product_attributes = array();
16
+
17
+ public function getId()
18
+ {
19
+ return $this->id;
20
+ }
21
+
22
+ public function setId($id)
23
+ {
24
+ $this->id = $id;
25
+ }
26
+ }
lib/Gateway3D/PersonaliseIt/Service/Dto/P1/Sample.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Dto_P1_Sample
11
+ extends Gateway3D_PersonaliseIt_Service_Dto_Abstract
12
+ {
13
+ public $sample_id = 0;
14
+ public $product_id = 0;
15
+
16
+ public function getId()
17
+ {
18
+ return $this->sample_id;
19
+ }
20
+
21
+ public function setId($id)
22
+ {
23
+ $this->sample_id = $id;
24
+ }
25
+ }
lib/Gateway3D/PersonaliseIt/Service/Dto/P2/PrintJob.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Dto_P2_PrintJob
11
+ extends Gateway3D_PersonaliseIt_Service_Dto_Abstract
12
+ {
13
+ public $print_job_id = 0;
14
+ public $product_id = 0;
15
+ public $print_job_company_id = 0;
16
+ public $items = array();
17
+
18
+ public function getId()
19
+ {
20
+ return $this->print_job_id;
21
+ }
22
+
23
+ public function setId($id)
24
+ {
25
+ $this->print_job_id;
26
+ }
27
+ }
lib/Gateway3D/PersonaliseIt/Service/Dto/Sl/Order.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Dto_Sl_Order
11
+ extends Gateway3D_PersonaliseIt_Service_Dto_Abstract
12
+ {
13
+ const STATUS_UNKNOWN = 0;
14
+ const STATUS_ITEMS_READY = 1;
15
+ const STATUS_BATCH_READY = 2;
16
+ const STATUS_IN_PRODUCTION = 4;
17
+ const STATUS_DISPATCHED = 8;
18
+ const STATUS_REPRINT = 16;
19
+ const STATUS_REJECTED = 32;
20
+
21
+ const STATUS_SUPPLIER_DISPATCHED_NOTIFIED = 64;
22
+
23
+ const STATUS_CANCELLED = 128;
24
+ const STATUS_ON_HOLD = 256;
25
+
26
+ public $id = 0;
27
+ public $ref = '';
28
+ public $external_ref = '';
29
+ public $additional_info = '';
30
+ public $company_ref_id = 0;
31
+ public $status = 0;
32
+
33
+ public $sale_datetime = '';
34
+ public $completion_datetime = '';
35
+ public $creation_datetime = '';
36
+
37
+ public $has_been_completed = false;
38
+
39
+ public $shipping_address_1 = '';
40
+ public $shipping_address_2 = '';
41
+ public $shipping_address_3 = '';
42
+ public $shipping_address_4 = '';
43
+ public $shipping_address_5 = '';
44
+ public $shipping_postcode = '';
45
+ public $shipping_country = '';
46
+ public $shipping_country_code = '';
47
+
48
+ public $shipping_method = '';
49
+ public $shipping_carrier = '';
50
+ public $shipping_tracking = '';
51
+
52
+ public $billing_address_1 = '';
53
+ public $billing_address_2 = '';
54
+ public $billing_address_3 = '';
55
+ public $billing_address_4 = '';
56
+ public $billing_address_5 = '';
57
+ public $billing_postcode = '';
58
+ public $billing_country = '';
59
+
60
+ public $payment_trans_id = '';
61
+
62
+ public $customer_name = '';
63
+ public $customer_email = '';
64
+
65
+ public $has_error = false;
66
+ public $error_message = '';
67
+
68
+ public $items = array();
69
+
70
+ public function getId()
71
+ {
72
+ return $this->id;
73
+ }
74
+
75
+ public function setId($id)
76
+ {
77
+ $this->id = $id;
78
+ }
79
+ }
lib/Gateway3D/PersonaliseIt/Service/Dto/Sl/Order/Item.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * @category Gateway3D
5
+ * @package Personalise-iT
6
+ * @author James Ball <james@gateway3d.co.uk>
7
+ * @copyright Copyright (c) 2015 Gateway 3D Ltd.
8
+ */
9
+
10
+ class Gateway3D_PersonaliseIt_Service_Dto_Sl_Order_Item
11
+ extends Gateway3D_PersonaliseIt_Service_Dto_Abstract
12
+ {
13
+ const TYPE_UNKNOWN = 0;
14
+ const TYPE_EXTERNAL_URL = 1;
15
+ const TYPE_PRINT_JOB = 2;
16
+ const TYPE_PRINT_ON_DEMAND = 3;
17
+ const TYPE_PLAIN = 4;
18
+
19
+ const STATUS_UNKNOWN = 0;
20
+ const STATUS_READY = 1;
21
+ const STATUS_IN_PRODUCTION = 2;
22
+ const STATUS_DISPATCHED = 3;
23
+
24
+ public $id = 0;
25
+ public $order_id = 0;
26
+ public $sku = '';
27
+ public $description = '';
28
+ public $quantity = 0;
29
+ public $type = 0;
30
+ public $status = 0;
31
+ public $ref = '';
32
+ public $external_ref = '';
33
+ public $print_job_id = 0;
34
+ public $print_on_demand_ref = '';
35
+
36
+ public function getId()
37
+ {
38
+ return $this->id;
39
+ }
40
+
41
+ public function setId($id)
42
+ {
43
+ $this->id = $id;
44
+ }
45
+ }
package.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Gateway3D_PersonaliseIt</name>
4
+ <version>1.6.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/GPL-3.0">GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>PERSONALISE-IT ECOMMERCE EXTENSION FOR MAGENTO enables you to add personalised products to your magento website and back office system.</summary>
10
+ <description>Personalise-iT eCommerce Extension for Magento&#xD;
11
+ Enables you to add personalised products to your magento website and back office system&#xD;
12
+ &#xD;
13
+ Adds an attribute for product URL that will display as an iframe on product detail page - only potential additional development is to update your page CSS - dependant on Magento theme should take no more than a few hours&#xD;
14
+ Enables personalised products to be added from the iframe directly to your standard Magento shopping basket&#xD;
15
+ Enables you to add to a single product or install a product selector&#xD;
16
+ Integrates with Magento to get latest prices for single and grouped products&#xD;
17
+ Enables easy import of personalised products data from the Gateway3D ACP&#xD;
18
+ </description>
19
+ <notes>1. package release</notes>
20
+ <authors><author><name>James Ball</name><user>gateway3d</user><email>andrew@gateway3d.com</email></author></authors>
21
+ <date>2015-05-06</date>
22
+ <time>09:21:28</time>
23
+ <contents><target name="magelocal"><dir name="Gateway3D"><dir name="PersonaliseIt"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><dir name="Tab"><dir name="Options"><file name="Option.php" hash="de7ec2e5d3726236fc1be2d32e7449c9"/></dir><file name="Options.php" hash="8f30014e12e91e0953f88ba7db8ca0f1"/></dir></dir></dir></dir></dir><dir name="Product"><dir name="View"><file name="Options.php" hash="e4c65343b18699801cac12926b899a8a"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="6fa3c5a7ddaee7f85574913ca3f5c453"/><file name="MessageEvent.php" hash="68b3bbd29ef744cc003e19983f8aa9ff"/><file name="ProductCustomOptions.php" hash="c0c814759d98f7d2d2c76e5c69138688"/></dir><dir name="Model"><dir name="Catalog"><dir name="Product"><dir name="Option"><dir name="Type"><file name="Hidden.php" hash="24e4219bcef522d5541c80e76d81d417"/></dir></dir><file name="Option.php" hash="6e5d86d3461efe2ec628167452810540"/></dir></dir><dir name="Cron"><file name="Abstract.php" hash="23ff66caca4b72339b440974189b9ff8"/><file name="DelayedPrintJob.php" hash="dc9ad2fb74dd140eb8059e27967142d0"/><file name="Sl.php" hash="403deafd2faa7bec02269e0af3da008c"/></dir><file name="ImportOptions.php" hash="a2a2bb0edb75cc19f09516dd6dfa812e"/><dir name="Product"><file name="Abstract.php" hash="42d7cc2abc7ac71ff4f3c273e0d2eab2"/><file name="Callback.php" hash="6cdea1ba267dfc8d8f2336d752919b54"/><file name="Epa.php" hash="90bdd24d82eb740487534d03950f2554"/><file name="Rating.php" hash="ef560672e4ebabf7ee48400fd844e2c6"/></dir><dir name="Resource"><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="1cc4352f5731c8791909e91e37c16dbe"/></dir></dir></dir><dir name="Source"><file name="Orderstatus.php" hash="cab06992d625e25c03230c2d83e5181b"/></dir><dir name="Status"><file name="Callback.php" hash="3a570645736683a389ad64e20862b3d0"/></dir></dir><dir name="controllers"><file name="CppController.php" hash="8c67cacf5709a556e491dbfebe966032"/><file name="ProductController.php" hash="c05170bda82b874c6f6af2e7eccb2754"/><file name="ProductsController.php" hash="ecc1571d47195ed50425cff021cdb763"/><file name="StatusController.php" hash="b5ac639a2c016ba6069444539b0f192c"/></dir><dir name="etc"><file name="config.xml" hash="ecfe65679696b236b611f5e5b3646dd3"/><file name="system.xml" hash="c7d794ce6fdc37dd901ad4cc4154e34c"/></dir><dir name="sql"><dir name="personaliseit_setup"><file name="mysql4-install-1.0.0.php" hash="1fce9f7b040554ef5a94548d1a475fa4"/><file name="mysql4-upgrade-1.0.0-1.1.0.php" hash="4a595f9829b6860bc95b53bdc9502ff9"/><file name="mysql4-upgrade-1.1.1-1.1.2.php" hash="6191fd474af43bc3eb2ddbd8d77502d9"/><file name="mysql4-upgrade-1.1.7.1-1.2.0.0.php" hash="4f1bde8b6caecd92eac47fbbff54670b"/><file name="mysql4-upgrade-1.2.0.3-1.3.0.0.php" hash="c1ad1ae7db03f5d1558e6bbe5c63cdce"/><file name="mysql4-upgrade-1.3.5.4-1.3.6.0.php" hash="e4bfb0b95cfcae3142eee04fe1b5c7c8"/><file name="mysql4-upgrade-1.3.6.0-1.4.0.0.php" hash="35ef54c4aa462e673cad55c8b1f66657"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="personaliseit"><dir name="catalog"><dir name="product"><dir name="edit"><file name="options.phtml" hash="8778b1db29eeaea9ac0f48c23bea908c"/></dir></dir></dir><file name="item_column_renderer_name.phtml" hash="22f10bce29cdc670790c31b23df39c85"/><file name="option.phtml" hash="dc54dc21176e7b36175f58956162340e"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="personaliseit.xml" hash="7c81f0d446b9d42ef6f3f15ebe810c24"/></dir><dir name="template"><dir name="personaliseit"><dir name="cart"><dir name="item"><file name="default.phtml" hash="3473fca9da1e0c7a1b6be2a4582b07db"/></dir></dir><dir name="product"><file name="callback.phtml" hash="8a5fa1a137a7cc867d738f238cbf5f09"/><dir name="view"><file name="addtocart.phtml" hash="31b3cb1ce58bf5683ac42aad40c7a53c"/><file name="media.phtml" hash="920bdaa1e1729e1b9c0fe9370218b53c"/></dir></dir><dir name="products"><file name="index.phtml" hash="26565d0b4e509c5fed580b29b8c072e0"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Gateway3D_PersonaliseIt.xml" hash="16c34b7b2a594b1cec6dee88ff1528ea"/></dir></target><target name="mageweb"><dir name="js"><dir name="personalise-it"><file name="delayed-preview.js" hash="ae30ade52d17cc34858f6487f0422b96"/></dir></dir></target><target name="magelib"><dir name="Gateway3D"><dir name="PersonaliseIt"><dir name="Service"><dir name="Api"><file name="Abstract.php" hash="0a04cec6523526979e199ab85de241d2"/><dir name="P1"><file name="Product.php" hash="2af118282a6259397da3b674eed96978"/><file name="Sample.php" hash="26939ac32c06825bcbba37a445219b4a"/></dir><dir name="P2"><file name="PrintJob.php" hash="09126773651feea4f4316797539a34ac"/></dir><dir name="Sl"><file name="Order.php" hash="efb4e24a9dac06385cb89559b0779eef"/></dir></dir><dir name="Dto"><file name="Abstract.php" hash="5eb3756ee49227e089b92db44d5bdc04"/><file name="Interface.php" hash="1023c3de30572c812bc1d4e1027184d3"/><dir name="P1"><file name="Product.php" hash="7c3f1f9afa6be2d207195323ebe9ac78"/><file name="Sample.php" hash="cd6583fee38465fe0063cb5479c7cdb4"/></dir><dir name="P2"><file name="PrintJob.php" hash="d4fc0358846d23ecdd2647a55dcaafe9"/></dir><dir name="Sl"><dir name="Order"><file name="Item.php" hash="08e26b54602bb477e1cd70d3c642f8be"/></dir><file name="Order.php" hash="929bcee73f1b95b3827394452ef2fb29"/></dir></dir></dir></dir></dir></target></contents>
24
+ <compatible/>
25
+ <dependencies><required><php><min>4.4.0</min><max>6.0.0</max></php></required></dependencies>
26
+ </package>