Version Notes
Stable version
Download this release
Release Info
| Developer | Dan Dumitrascu |
| Extension | IMerchandise_Sync |
| Version | 1.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0
- app/code/community/IMerchandise/.DS_Store +0 -0
- app/code/community/IMerchandise/Sync/.DS_Store +0 -0
- app/code/community/IMerchandise/Sync/Helper/Data.php +6 -0
- app/code/community/IMerchandise/Sync/Model/Core/Api.php +156 -0
- app/code/community/IMerchandise/Sync/etc/api.xml +91 -0
- app/code/community/IMerchandise/Sync/etc/config.xml +19 -0
- app/etc/modules/IMerchandise_Sync.xml +11 -0
- package.xml +18 -0
app/code/community/IMerchandise/.DS_Store
ADDED
|
Binary file
|
app/code/community/IMerchandise/Sync/.DS_Store
ADDED
|
Binary file
|
app/code/community/IMerchandise/Sync/Helper/Data.php
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class IMerchandise_Sync_Helper_Data extends Mage_Core_Helper_Abstract
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
}
|
| 6 |
+
?>
|
app/code/community/IMerchandise/Sync/Model/Core/Api.php
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class IMerchandise_Sync_Model_Core_Api extends Mage_Api_Model_Resource_Abstract
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
public function getCurrentRootCategoryID(){
|
| 6 |
+
$catID=Mage::app()->getStore()->getRootCategoryId();
|
| 7 |
+
return (string)$catID;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
public function createConfigAttribute($productSku,$attributeId,$label){
|
| 11 |
+
|
| 12 |
+
// Load the product
|
| 13 |
+
$product = Mage::getModel('catalog/product')->setStoreId(0);
|
| 14 |
+
$product=Mage::getModel('catalog/product')->loadByAttribute('sku',$productSku);
|
| 15 |
+
|
| 16 |
+
if (!$product) {
|
| 17 |
+
$this->_fault('configurable_product_does_not_exist');
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
$attribute = Mage::getModel('catalog/entity_attribute')->setStoreId(0);
|
| 21 |
+
$attribute->load($attributeId);
|
| 22 |
+
|
| 23 |
+
if ($product && $attribute){
|
| 24 |
+
// Check that the configurable attribute doesn't already exist for the configurable product.
|
| 25 |
+
$product_configurable_attributes = $product->getTypeInstance()->getConfigurableAttributesAsArray();
|
| 26 |
+
foreach($product_configurable_attributes as $attrib){
|
| 27 |
+
if ($attributeId==$attrib["attribute_id"]){
|
| 28 |
+
$this->_fault('configurable_attribute_already_exists');
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
$configurableAttribute = Mage::getModel("catalog/product_type_configurable_attribute");
|
| 32 |
+
$configurableAttribute->setProductId($product->getId());
|
| 33 |
+
$configurableAttribute->setAttributeId($attributeId);
|
| 34 |
+
$configurableAttribute->setPosition(0);
|
| 35 |
+
$configurableAttribute->setStoreId(0);
|
| 36 |
+
$configurableAttribute->setLabel($label);
|
| 37 |
+
$configurableAttribute->save();
|
| 38 |
+
$configurableAttribute->setValues(null);
|
| 39 |
+
$configurableAttribute->save();
|
| 40 |
+
return $configurableAttribute->getId();
|
| 41 |
+
}
|
| 42 |
+
return false;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public function assignProductsToConfigurable($configurableProductSku,array $productSkus){
|
| 46 |
+
$configurable_product=Mage::getModel('catalog/product')->loadByAttribute('sku',$configurableProductSku);
|
| 47 |
+
if (!$configurable_product) {
|
| 48 |
+
$this->_fault('configurable_product_does_not_exist');
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
$children_id_array=Mage::getResourceSingleton('catalog/product_type_configurable')->getChildrenIds($configurable_product->getId());
|
| 52 |
+
|
| 53 |
+
$childrenIds=$children_id_array[0];
|
| 54 |
+
/**
|
| 55 |
+
foreach ($children_id_array as $key->$value){
|
| 56 |
+
$childrenIds[$value]=$value;
|
| 57 |
+
}
|
| 58 |
+
*/
|
| 59 |
+
$product = Mage::getModel('catalog/product');
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
foreach($productSkus as $sku){
|
| 63 |
+
$productId = $product->getIdBySku($sku);
|
| 64 |
+
if ($productId){
|
| 65 |
+
if(!array_key_exists($productId,$childrenIds)){
|
| 66 |
+
$childrenIds[$productId]=$productId;
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
$configurable_product->setConfigurableProductsData($childrenIds);
|
| 71 |
+
//$configurable_product->setHasOptions(true);
|
| 72 |
+
$configurable_product->setRequiredOptions(true);
|
| 73 |
+
Mage::log('Product from iMerchandise Sync:');
|
| 74 |
+
Mage::log($configurable_product);
|
| 75 |
+
$configurable_product->save();
|
| 76 |
+
return true;
|
| 77 |
+
|
| 78 |
+
}
|
| 79 |
+
public function createAttributeOption($attributeId,$option_label){
|
| 80 |
+
$attribute = Mage::getModel('catalog/product')
|
| 81 |
+
->setStoreId(0)
|
| 82 |
+
->getResource()
|
| 83 |
+
->getAttribute($attributeId);
|
| 84 |
+
if (!$attribute->getId()) {
|
| 85 |
+
$this->_fault('attribute_does_not_exist');
|
| 86 |
+
}
|
| 87 |
+
foreach ($attribute->getSource()->getAllOptions(true) as $option){
|
| 88 |
+
if (strcmp($option_label,$option['label']) == 0){
|
| 89 |
+
$this->_fault('attribute_option_already_exists');
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
$option=array();
|
| 93 |
+
$option['attribute_id'] = $attributeId;
|
| 94 |
+
$option['value']['new_option'][0] = $option_label;
|
| 95 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
| 96 |
+
$setup->addAttributeOption($option);
|
| 97 |
+
// Since the addAtributeOption does not return a value, we will have to parse out the new option by name and return it's id.
|
| 98 |
+
|
| 99 |
+
$attribute->save();
|
| 100 |
+
|
| 101 |
+
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
|
| 102 |
+
->addFieldToFilter('attribute_id',$attributeId)
|
| 103 |
+
->join('attribute_option_value','main_table.option_id=attribute_option_value.option_id')
|
| 104 |
+
->addFieldToFilter('value',$option_label);
|
| 105 |
+
$new_option = $collection->getFirstItem();
|
| 106 |
+
|
| 107 |
+
return $new_option->getId();
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
private function getProductEntityTypeId()
|
| 112 |
+
{
|
| 113 |
+
return Mage::getModel('catalog/product')->getResource()->getEntityType();
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
public function createAssignAttribute($code, $label){
|
| 117 |
+
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
|
| 118 |
+
$data=array(
|
| 119 |
+
'label' => $label,
|
| 120 |
+
'type' => 'varchar',
|
| 121 |
+
'input' => 'select',
|
| 122 |
+
'backend' => 'eav/entity_attribute_backend_array',
|
| 123 |
+
'frontend' => '',
|
| 124 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
|
| 125 |
+
'visible' => true,
|
| 126 |
+
'required' => true,
|
| 127 |
+
'user_defined' => true,
|
| 128 |
+
'searchable' => false,
|
| 129 |
+
'filterable' => false,
|
| 130 |
+
'comparable' => false,
|
| 131 |
+
'option' => array (
|
| 132 |
+
'value' => array()
|
| 133 |
+
),
|
| 134 |
+
'visible_on_front' => false,
|
| 135 |
+
'visible_in_advanced_search' => false,
|
| 136 |
+
'unique' => false,
|
| 137 |
+
'configurable' =>true
|
| 138 |
+
);
|
| 139 |
+
$model = $setup->addAttribute('catalog_product', $code,$data);
|
| 140 |
+
$attribute=$setup->getAttribute('catalog_product', $code);
|
| 141 |
+
return $attribute['attribute_id'];
|
| 142 |
+
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
public function skuExists($sku){
|
| 146 |
+
$product=Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
|
| 147 |
+
if ($product)
|
| 148 |
+
{
|
| 149 |
+
return true;
|
| 150 |
+
}
|
| 151 |
+
return false;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
}
|
| 156 |
+
?>
|
app/code/community/IMerchandise/Sync/etc/api.xml
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<config>
|
| 2 |
+
<api>
|
| 3 |
+
<resources>
|
| 4 |
+
<imerchandise_sync translate="title" module="im_sync">
|
| 5 |
+
<title>iMerchandise Sync API calls</title>
|
| 6 |
+
<model>im_sync/core_api</model>
|
| 7 |
+
<acl>imerchandise/sync</acl>
|
| 8 |
+
<methods>
|
| 9 |
+
<getCurrentRootCategoryID translate="title" module="im_sync">
|
| 10 |
+
<title>Returns the id of the root category of the current store</title>
|
| 11 |
+
<acl>imerchandise/sync/allaccess</acl>
|
| 12 |
+
</getCurrentRootCategoryID>
|
| 13 |
+
<createConfigAttribute translate="title" module="im_sync">
|
| 14 |
+
<title>Create a configurable attribute for a configurable product</title>
|
| 15 |
+
<acl>imerchandise/sync/allaccess</acl>
|
| 16 |
+
</createConfigAttribute>
|
| 17 |
+
<assignProductsToConfigurable translate="title" module="im_sync">
|
| 18 |
+
<title>Assign a simple product to a configurable product</title>
|
| 19 |
+
<acl>imerchandise/sync/allaccess</acl>
|
| 20 |
+
</assignProductsToConfigurable>
|
| 21 |
+
<createAttributeOption translate="title" module="im_sync">
|
| 22 |
+
<title>Create an option for an existing product attribute</title>
|
| 23 |
+
<acl>imerchandise/sync/allaccess</acl>
|
| 24 |
+
</createAttributeOption>
|
| 25 |
+
<skuExists translate="title" module="im_sync">
|
| 26 |
+
<title>Checks if a sku exists</title>
|
| 27 |
+
<acl>imerchandise/sync/allaccess</acl>
|
| 28 |
+
</skuExists>
|
| 29 |
+
<createAssignAttribute translate="title" module="im_sync">
|
| 30 |
+
<title>Creates an attribute to be used by configurable products</title>
|
| 31 |
+
<acl>imerchandise/sync/allaccess</acl>
|
| 32 |
+
</createAssignAttribute>
|
| 33 |
+
|
| 34 |
+
</methods>
|
| 35 |
+
<faults module="core">
|
| 36 |
+
<configurable_product_does_not_exist>
|
| 37 |
+
<code>100</code>
|
| 38 |
+
<message>Configurable product does not exist.</message>
|
| 39 |
+
</configurable_product_does_not_exist>
|
| 40 |
+
<attribute_does_not_exist>
|
| 41 |
+
<code>101</code>
|
| 42 |
+
<message>Configurable attribute does not exist.</message>
|
| 43 |
+
</attribute_does_not_exist>
|
| 44 |
+
<configurable_attribute_already_exists>
|
| 45 |
+
<code>102</code>
|
| 46 |
+
<message>Configurable attribute already exists for configurable product.</message>
|
| 47 |
+
</configurable_attribute_already_exists>
|
| 48 |
+
<attribute_create_error>
|
| 49 |
+
<code>103</code>
|
| 50 |
+
<message>Couldn't create the a attribute.</message>
|
| 51 |
+
</attribute_create_error>
|
| 52 |
+
<option_does_not_exist>
|
| 53 |
+
<code>104</code>
|
| 54 |
+
<message>Option does not exist.</message>
|
| 55 |
+
</option_does_not_exist>
|
| 56 |
+
<attribute_option_already_exists>
|
| 57 |
+
<code>105</code>
|
| 58 |
+
<message>Option already exists for attribute.</message>
|
| 59 |
+
</attribute_option_already_exists>
|
| 60 |
+
<category_does_not_exist>
|
| 61 |
+
<code>106</code>
|
| 62 |
+
<message>Category does not exist.</message>
|
| 63 |
+
</category_does_not_exist>
|
| 64 |
+
<product_does_not_exist>
|
| 65 |
+
<code>107</code>
|
| 66 |
+
<message>Product does not exist</message>
|
| 67 |
+
</product_does_not_exist>
|
| 68 |
+
</faults>
|
| 69 |
+
</imerchandise_sync>
|
| 70 |
+
</resources>
|
| 71 |
+
<resources_alias>
|
| 72 |
+
<core>im_sync</core>
|
| 73 |
+
</resources_alias>
|
| 74 |
+
<acl>
|
| 75 |
+
<resources>
|
| 76 |
+
<imerchandise translate="title" module="im_sync">
|
| 77 |
+
<title>iMerchandise</title>
|
| 78 |
+
<sort_order>100</sort_order>
|
| 79 |
+
<sync translate="title" module="im_sync">
|
| 80 |
+
<title>Sync</title>
|
| 81 |
+
<sort_order>100</sort_order>
|
| 82 |
+
<allaccess translate="title" module="im_sync">
|
| 83 |
+
<title>iMerchandise Sync access.</title>
|
| 84 |
+
<sort_order>10</sort_order>
|
| 85 |
+
</allaccess>
|
| 86 |
+
</sync>
|
| 87 |
+
</imerchandise>
|
| 88 |
+
</resources>
|
| 89 |
+
</acl>
|
| 90 |
+
</api>
|
| 91 |
+
</config>
|
app/code/community/IMerchandise/Sync/etc/config.xml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<config>
|
| 2 |
+
<modules>
|
| 3 |
+
<IMerchandise_Sync>
|
| 4 |
+
<version>0.0.0.1</version>
|
| 5 |
+
</IMerchandise_Sync>
|
| 6 |
+
</modules>
|
| 7 |
+
<global>
|
| 8 |
+
<models>
|
| 9 |
+
<im_sync>
|
| 10 |
+
<class>IMerchandise_Sync_Model</class>
|
| 11 |
+
</im_sync>
|
| 12 |
+
</models>
|
| 13 |
+
<helpers>
|
| 14 |
+
<im_sync>
|
| 15 |
+
<class>IMerchandise_Sync_Helper</class>
|
| 16 |
+
</im_sync>
|
| 17 |
+
</helpers>
|
| 18 |
+
</global>
|
| 19 |
+
</config>
|
app/etc/modules/IMerchandise_Sync.xml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<config>
|
| 2 |
+
<modules>
|
| 3 |
+
<IMerchandise_Sync>
|
| 4 |
+
<active>true</active>
|
| 5 |
+
<codePool>community</codePool>
|
| 6 |
+
<depends>
|
| 7 |
+
<Mage_Api />
|
| 8 |
+
</depends>
|
| 9 |
+
</IMerchandise_Sync>
|
| 10 |
+
</modules>
|
| 11 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>IMerchandise_Sync</name>
|
| 4 |
+
<version>1.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Is used by iMerchandise iOS application for synchronizing with Magento.</summary>
|
| 10 |
+
<description>Is used by iMerchandise iOS application for synchronizing with Magento.</description>
|
| 11 |
+
<notes>Stable version</notes>
|
| 12 |
+
<authors><author><name>Dan Dumitrascu</name><user>ddumitrascu</user><email>ddumitrascu@gmail.com</email></author></authors>
|
| 13 |
+
<date>2013-06-11</date>
|
| 14 |
+
<time>15:11:36</time>
|
| 15 |
+
<contents><target name="magecommunity"><dir name="IMerchandise"><dir name="Sync"><dir name="Helper"><file name="Data.php" hash="9627ae65741b47f72c8fe9b46812a3f4"/></dir><dir name="Model"><dir name="Core"><file name="Api.php" hash="e18b8d0a7011ca7c3aa6fb78ab82965e"/></dir></dir><dir name="etc"><file name="api.xml" hash="524b180f4f32490800c40cd84e880203"/><file name="config.xml" hash="d65b53ec4c2a5346db82ac60560a2f0c"/></dir><file name=".DS_Store" hash="c510d69530e48d2dc10dc588e527decd"/></dir><file name=".DS_Store" hash="3455fdd0e64ee39aaea229612fc7ccbf"/></dir></target><target name="mageetc"><dir name="modules"><file name="IMerchandise_Sync.xml" hash="9b6b5c7a238ce5609895d1afc47e576e"/></dir></target></contents>
|
| 16 |
+
<compatible/>
|
| 17 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Api</name><channel>community</channel><min>1.6.0.0</min><max>1.7</max></package></required></dependencies>
|
| 18 |
+
</package>
|
