Skip to content

Commit

Permalink
Merge pull request #2 from DmitryKorol/master
Browse files Browse the repository at this point in the history
offers, customer upload on event, orders update
  • Loading branch information
gwinn authored Sep 8, 2016
2 parents c8217c8 + aeffa5b commit 7d3a1bb
Show file tree
Hide file tree
Showing 10 changed files with 922 additions and 187 deletions.
158 changes: 140 additions & 18 deletions app/code/community/Retailcrm/Retailcrm/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
<?php
/**
* Data helper
* Default extension helper class
* PHP version 5.3
*
* @author RetailCRM
* @category Model
* @package RetailCrm\Model
* @author RetailDriver LLC <[email protected]>
* @license http://opensource.org/licenses/MIT MIT License
* @link http://www.magentocommerce.com/magento-connect/retailcrm-1.html
*/

/**
* Data helper class
*
* @category Model
* @package RetailCrm\Model
* @author RetailDriver LLC <[email protected]>
* @license http://opensource.org/licenses/MIT MIT License
* @link http://www.magentocommerce.com/magento-connect/retailcrm-1.html
*
* @SuppressWarnings(PHPMD.CamelCaseClassName)
*/
class Retailcrm_Retailcrm_Helper_Data extends Mage_Core_Helper_Abstract
{
Expand All @@ -20,39 +37,144 @@ class Retailcrm_Retailcrm_Helper_Data extends Mage_Core_Helper_Abstract
*/
const XML_API_KEY = 'retailcrm/general/api_key';

/**
* Return api url
*
* @param integer|string|Mage_Core_Model_Store $store
* @return int
*/
/**
* Get api url
*
* @param Mage_Core_Model_Store $store store instance
*
* @SuppressWarnings(PHPMD.StaticAccess)
*
* @return int
*/
public function getApiUrl($store = null)
{
return abs((int)Mage::getStoreConfig(self::XML_API_URL, $store));
}

/**
* Return api key
*
* @param integer|string|Mage_Core_Model_Store $store
* @return int
*/
/**
* Get api key
*
* @param Mage_Core_Model_Store $store store instance
*
* @SuppressWarnings(PHPMD.StaticAccess)
*
* @return int
*/
public function getApiKey($store = null)
{
return abs((int)Mage::getStoreConfig(self::XML_API_KEY, $store));
}

public function rewrittenProductUrl($productId, $categoryId, $storeId)
/**
* Get api key
*
* @param string $baseUrl base url
* @param mixed $coreUrl url rewritte
* @param integer $productId product id
* @param integer $storeId product store id
* @param integer $categoryId product category id
*
* @SuppressWarnings(PHPMD.StaticAccess)
*
* @return string
*/
public function rewrittenProductUrl(
$baseUrl,
$coreUrl,
$productId,
$storeId,
$categoryId = null
)
{
$coreUrl = Mage::getModel('core/url_rewrite');
$idPath = sprintf('product/%d', $productId);
if ($categoryId) {
$idPath = sprintf('%s/%d', $idPath, $categoryId);
$idPath = sprintf('%s/%d', $idPath, $categoryId);
}
$coreUrl->setStoreId($storeId);
$coreUrl->loadByIdPath($idPath);

return Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true ) . $coreUrl->getRequestPath();
return $baseUrl . $coreUrl->getRequestPath();
}

/**
* Get country code
*
* @param string $string country iso code
*
* @SuppressWarnings(PHPMD.StaticAccess)
*
* @return string
*/
public function getCountryCode($string)
{
$country = empty($string) ? 'RU' : $string;
$xmlObj = new Varien_Simplexml_Config(
sprintf(
"%s%s%s",
Mage::getModuleDir('etc', 'Retailcrm_Retailcrm'),
DS,
'country.xml'
)
);
$xmlData = $xmlObj->getNode();

if ($country != 'RU') {
foreach ($xmlData as $elem) {
if ($elem->name == $country || $elem->english == $country) {
$country = $elem->alpha;
break;
}
}
}

return (string) $country;
}

/**
* Get exchage time
*
* @param string $datetime datetime string
*
* @return \DateTime
*/
public function getExchangeTime($datetime)
{
return $datetime = empty($datetime)
? new DateTime(
date(
'Y-m-d H:i:s',
strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))
)
)
: new DateTime($datetime);
}

/**
* Recursive array filter
*
* @param array $haystack input array
*
* @SuppressWarnings(PHPMD.StaticAccess)
* @SuppressWarnings(PHPMD.ElseExpression)
*
* @return array
*/
public function filterRecursive($haystack)
{
foreach ($haystack as $key => $value) {
if (is_array($value)) {
$haystack[$key] = self::filterRecursive($haystack[$key]);
}
if (is_null($haystack[$key])
|| $haystack[$key] === ''
|| count($haystack[$key]) == 0
) {
unset($haystack[$key]);
} elseif (!is_array($value)) {
$haystack[$key] = trim($value);
}
}

return $haystack;
}
}
43 changes: 43 additions & 0 deletions app/code/community/Retailcrm/Retailcrm/Model/Attribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
class Retailcrm_Retailcrm_Model_Attribute
{
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
->getItems();

$data = array();

foreach($attributes as $attribute) {
if(empty($attribute->getFrontendLabel())) continue;

$data[] = array(
'label' => $attribute->getFrontendLabel(),
'value' => $attribute->getAttributeCode()
);
}

return $data;
}

/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return array();

return array(
0 => Mage::helper('adminhtml')->__('Data1'),
1 => Mage::helper('adminhtml')->__('Data2'),
2 => Mage::helper('adminhtml')->__('Data3'),
);
}
}
75 changes: 75 additions & 0 deletions app/code/community/Retailcrm/Retailcrm/Model/Customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Customer class
*
* @category Model
* @package RetailCrm\Model
* @author RetailDriver LLC <[email protected]>
* @license http://opensource.org/licenses/MIT MIT License
* @link http://www.magentocommerce.com/magento-connect/retailcrm-1.html
*
* @SuppressWarnings(PHPMD.CamelCaseClassName)
*/
class Retailcrm_Retailcrm_Model_Customer extends Retailcrm_Retailcrm_Model_Exchange
{
/**
* Customer create
*
* @SuppressWarnings(PHPMD.StaticAccess)
* @SuppressWarnings(PHPMD.ElseExpression)
* @param mixed $data
*
* @return bool
*/
public function customerRegister($data)
{
$customer = array(
'externalId' => $data->getId(),
'email' => $data->getEmail(),
'firstName' => $data->getFirstname(),
'patronymic' => $data->getMiddlename(),
'lastName' => $data->getLastname(),
'createdAt' => date('Y-m-d H:i:s', strtotime($data->getCreatedAt()))
);

$this->_api->customersEdit($customer);
}

/**
* Customers export
*
* @SuppressWarnings(PHPMD.StaticAccess)
* @SuppressWarnings(PHPMD.ElseExpression)
*
* @return bool
*/
public function customersExport()
{
$customers = array();
$customerCollection = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('email')
->addAttributeToSelect('firstname')
->addAttributeToSelect('lastname');
foreach ($customerCollection as $customerData)
{
$customer = array(
'externalId' => $customerData->getId(),
'email' => $customerData->getData('email'),
'firstName' => $customerData->getData('firstname'),
'lastName' => $customerData->getData('lastname')
);
$customers[] = $customer;
}
unset($customerCollection);
$chunked = array_chunk($customers, 50);
unset($customers);
foreach ($chunked as $chunk) {
//file_put_contents('/var/www/konzeptual/data/www/konzeptual.ru/tempC.txt', var_export($chunk,true)); die();
$this->_api->customersUpload($chunk);
time_nanosleep(0, 250000000);
}
unset($chunked);
return true;
}
}
Loading

0 comments on commit 7d3a1bb

Please sign in to comment.