Motech_DefaultProductStatus - Version 1.0.1

Version Notes

Added support for duplicated products.

Download this release

Release Info

Developer Justin Saad
Extension Motech_DefaultProductStatus
Version 1.0.1
Comparing to
See all releases


Code changes from version 1.0.0 to 1.0.1

app/code/community/Motech/DefaultProductStatus/Model/Product.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Motech_DefaultProductStatus_Model_Product extends Mage_Catalog_Model_Product
4
+ {
5
+
6
+
7
+ /**
8
+ * Create duplicate
9
+ *
10
+ * @return Mage_Catalog_Model_Product
11
+ */
12
+ public function duplicate()
13
+ {
14
+ $this->getWebsiteIds();
15
+ $this->getCategoryIds();
16
+
17
+ $duplicatestatus = Mage::getStoreConfig('motech_catalog/defaultproductstatus/defaultduplicatedproductstatus');
18
+
19
+ $newProduct = Mage::getModel('catalog/product')->setData($this->getData())
20
+ ->setIsDuplicate(true)
21
+ ->setOriginalId($this->getId())
22
+ ->setSku(null)
23
+ ->setStatus($duplicatestatus)
24
+ ->setCreatedAt(null)
25
+ ->setUpdatedAt(null)
26
+ ->setId(null)
27
+ ->setStoreId(Mage::app()->getStore()->getId());
28
+
29
+ Mage::dispatchEvent(
30
+ 'catalog_model_product_duplicate',
31
+ array('current_product'=>$this, 'new_product'=>$newProduct)
32
+ );
33
+
34
+ /* @var $newProduct Mage_Catalog_Model_Product */
35
+
36
+ // $newOptionsArray = array();
37
+ // $newProduct->setCanSaveCustomOptions(true);
38
+ // foreach ($this->getOptions() as $_option) {
39
+ // /* @var $_option Mage_Catalog_Model_Product_Option */
40
+ // $newOptionsArray[] = $_option->prepareOptionForDuplicate();
41
+ // }
42
+ // $newProduct->setProductOptions($newOptionsArray);
43
+
44
+ /* Prepare Related*/
45
+ $data = array();
46
+ $this->getLinkInstance()->useRelatedLinks();
47
+ $attributes = array();
48
+ foreach ($this->getLinkInstance()->getAttributes() as $_attribute) {
49
+ if (isset($_attribute['code'])) {
50
+ $attributes[]=$_attribute['code'];
51
+ }
52
+ }
53
+ foreach ($this->getRelatedLinkCollection() as $_link) {
54
+ $data[$_link->getLinkedProductId()] = $_link->toArray($attributes);
55
+ }
56
+ $newProduct->setRelatedLinkData($data);
57
+
58
+ /* Prepare UpSell*/
59
+ $data = array();
60
+ $this->getLinkInstance()->useUpSellLinks();
61
+ $attributes = array();
62
+ foreach ($this->getLinkInstance()->getAttributes() as $_attribute) {
63
+ if (isset($_attribute['code'])) {
64
+ $attributes[]=$_attribute['code'];
65
+ }
66
+ }
67
+ foreach ($this->getUpSellLinkCollection() as $_link) {
68
+ $data[$_link->getLinkedProductId()] = $_link->toArray($attributes);
69
+ }
70
+ $newProduct->setUpSellLinkData($data);
71
+
72
+ /* Prepare Cross Sell */
73
+ $data = array();
74
+ $this->getLinkInstance()->useCrossSellLinks();
75
+ $attributes = array();
76
+ foreach ($this->getLinkInstance()->getAttributes() as $_attribute) {
77
+ if (isset($_attribute['code'])) {
78
+ $attributes[]=$_attribute['code'];
79
+ }
80
+ }
81
+ foreach ($this->getCrossSellLinkCollection() as $_link) {
82
+ $data[$_link->getLinkedProductId()] = $_link->toArray($attributes);
83
+ }
84
+ $newProduct->setCrossSellLinkData($data);
85
+
86
+ /* Prepare Grouped */
87
+ $data = array();
88
+ $this->getLinkInstance()->useGroupedLinks();
89
+ $attributes = array();
90
+ foreach ($this->getLinkInstance()->getAttributes() as $_attribute) {
91
+ if (isset($_attribute['code'])) {
92
+ $attributes[]=$_attribute['code'];
93
+ }
94
+ }
95
+ foreach ($this->getGroupedLinkCollection() as $_link) {
96
+ $data[$_link->getLinkedProductId()] = $_link->toArray($attributes);
97
+ }
98
+ $newProduct->setGroupedLinkData($data);
99
+
100
+ $newProduct->save();
101
+
102
+ $this->getOptionInstance()->duplicate($this->getId(), $newProduct->getId());
103
+ $this->getResource()->duplicate($this->getId(), $newProduct->getId());
104
+
105
+ // TODO - duplicate product on all stores of the websites it is associated with
106
+ /*if ($storeIds = $this->getWebsiteIds()) {
107
+ foreach ($storeIds as $storeId) {
108
+ $this->setStoreId($storeId)
109
+ ->load($this->getId());
110
+
111
+ $newProduct->setData($this->getData())
112
+ ->setSku(null)
113
+ ->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
114
+ ->setId($newId)
115
+ ->save();
116
+ }
117
+ }*/
118
+ return $newProduct;
119
+ }
120
+
121
+ }
app/code/community/Motech/DefaultProductStatus/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
 
4
  <modules>
5
  <Treestone_DefaultProductStatus>
6
- <version>1.0.0</version>
7
  </Treestone_DefaultProductStatus>
8
  </modules>
9
 
@@ -37,6 +37,11 @@
37
  <defaultproductstatus>
38
  <class>Motech_DefaultProductStatus_Model</class>
39
  </defaultproductstatus>
 
 
 
 
 
40
  </models>
41
  </global>
42
 
3
 
4
  <modules>
5
  <Treestone_DefaultProductStatus>
6
+ <version>1.0.1</version>
7
  </Treestone_DefaultProductStatus>
8
  </modules>
9
 
37
  <defaultproductstatus>
38
  <class>Motech_DefaultProductStatus_Model</class>
39
  </defaultproductstatus>
40
+ <catalog>
41
+ <rewrite>
42
+ <product>Motech_DefaultProductStatus_Model_Product</product>
43
+ </rewrite>
44
+ </catalog>
45
  </models>
46
  </global>
47
 
app/code/community/Motech/DefaultProductStatus/etc/system.xml CHANGED
@@ -27,7 +27,7 @@
27
 
28
  <fields>
29
  <defaultproductstatus translate="label">
30
- <label>Default Product Status</label>
31
  <frontend_type>select</frontend_type>
32
  <source_model>Motech_DefaultProductStatus_Model_ProductStatusOptions</source_model>
33
  <backend_model>defaultproductstatus/saveconfig</backend_model>
@@ -37,6 +37,17 @@
37
  <show_in_store>1</show_in_store>
38
  <comment>Defines the default product status to use when adding a new product</comment>
39
  </defaultproductstatus>
 
 
 
 
 
 
 
 
 
 
 
40
  </fields>
41
  </defaultproductstatus>
42
  </groups>
27
 
28
  <fields>
29
  <defaultproductstatus translate="label">
30
+ <label>Default New Product Status</label>
31
  <frontend_type>select</frontend_type>
32
  <source_model>Motech_DefaultProductStatus_Model_ProductStatusOptions</source_model>
33
  <backend_model>defaultproductstatus/saveconfig</backend_model>
37
  <show_in_store>1</show_in_store>
38
  <comment>Defines the default product status to use when adding a new product</comment>
39
  </defaultproductstatus>
40
+ <defaultduplicatedproductstatus translate="label">
41
+ <label>Default Duplicated Product Status</label>
42
+ <frontend_type>select</frontend_type>
43
+ <source_model>Motech_DefaultProductStatus_Model_ProductStatusOptions</source_model>
44
+ <!--<backend_model>defaultproductstatus/saveconfig</backend_model>-->
45
+ <sort_order>5</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <comment>Defines the default product status to use when duplicating a product</comment>
50
+ </defaultduplicatedproductstatus>
51
  </fields>
52
  </defaultproductstatus>
53
  </groups>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Motech_DefaultProductStatus</name>
4
- <version>1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL 3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Allows you to set the default new product status.</summary>
10
- <description>Allows you to set the default new product status.</description>
11
- <notes>Allows you to set the default new product status.</notes>
12
  <authors><author><name>Justin Saad</name><user>Motech</user><email>support@motechnetwork.com</email></author></authors>
13
  <date>2012-12-13</date>
14
- <time>04:24:38</time>
15
- <contents><target name="magecommunity"><dir name="Motech"><dir name="DefaultProductStatus"><dir name="Block"><file name="Settings.php" hash="259fe226c520785f05c0c77841f7a0ef"/></dir><dir name="Model"><file name="ProductStatusOptions.php" hash="d808918fa065c02549d0bc020699e23b"/><file name="Saveconfig.php" hash="e7dfbb6451cd517f56365c3f9efe8041"/></dir><dir name="etc"><file name="config.xml" hash="1b34bb1acfc7d0fc07ccb3a45baf8517"/><file name="system.xml" hash="dfd1776eb8322dc777810b4189647b62"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Motech_DefaultProductStatus.xml" hash="8ec2b32a6997e8878ff6634a0b6987f7"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Motech_DefaultProductStatus</name>
4
+ <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL 3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Allows you to set the default product status for new and duplicated products.</summary>
10
+ <description>Allows you to set the default product status for new and duplicated products.</description>
11
+ <notes>Added support for duplicated products.</notes>
12
  <authors><author><name>Justin Saad</name><user>Motech</user><email>support@motechnetwork.com</email></author></authors>
13
  <date>2012-12-13</date>
14
+ <time>16:56:58</time>
15
+ <contents><target name="magecommunity"><dir name="Motech"><dir name="DefaultProductStatus"><dir name="Block"><file name="Settings.php" hash="259fe226c520785f05c0c77841f7a0ef"/></dir><dir name="Model"><file name="Product.php" hash="19ca2004503c5faa49dbe402d8110194"/><file name="ProductStatusOptions.php" hash="d808918fa065c02549d0bc020699e23b"/><file name="Saveconfig.php" hash="e7dfbb6451cd517f56365c3f9efe8041"/></dir><dir name="etc"><file name="config.xml" hash="286196d47392c993b03a1fdb591f52b8"/><file name="system.xml" hash="1873e17855dfb1063e8b02f9aab16e47"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Motech_DefaultProductStatus.xml" hash="8ec2b32a6997e8878ff6634a0b6987f7"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>