Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Polcode_Crm_Model_Data_Import extends Polcode_Crm_Model_Loggable {
- /**
- * @var Polcode_Crm_Model_Proxy_Interface
- */
- protected $_proxy;
- public function setProxy(Polcode_Crm_Model_Proxy_Interface $proxy) {
- $this->_proxy = $proxy;
- return $this;
- }
- public function sync() {
- $this->log('customers');
- $this->_syncCustomers();
- $this->log('products');
- $this->_syncProducts();
- }
- protected function _syncCustomers() {
- /* @var getCustomers Polcode_Crm_Model_Proxy_Sugar */
- $customers = $this->_proxy->getCustomers();
- foreach ($customers as $customer) {
- $this->saveCrmCustomer($customer);
- }
- }
- protected function _syncProducts() {
- /* @var getProducts Polcode_Crm_Model_Proxy_Sugar */
- $products = $this->_proxy->getProducts();
- foreach ($products as $product) {
- $this->saveCrmProduct($product);
- }
- }
- public function saveCrmCustomer(Varien_Data $customer) {
- if (empty($customer->getEmail())) {
- throw new Exception('Email customer is required, set customer"s id: ' . $customer->id . ' email');
- } elseif ($this->checkCustomerExist($customer->getEmail())) {
- $this->log('Customer id: ' . $customer->id . ' already exist in system');
- } else {
- Mage::getModel('customer/customer')
- ->setWebsiteId(Mage::app()->getWebsite()->getId())
- ->setStoreId(Mage::app()->getStore()->getStoreId())
- ->addData($customer->getData())
- ->save();
- }
- }
- private function parseString($string) {
- return explode(' ', $string);
- }
- public function checkCustomerExist($email) {
- $customer = Mage::getModel('customer/customer');
- $collectionCount = $customer->getCollection()
- ->addFieldToFilter('email', $email)
- ->count();
- return $collectionCount;
- }
- public function saveCrmProduct(Varien_Data $product) {
- Mage::getModel('catalog/product')
- ->setAttributeSetId(4)
- ->setTypeId('simple')
- ->addData($product->getData())
- ->save();
- }
- public function checkProductExist($sku) {
- $customer = Mage::getModel('catalog/product');
- $collectionCount = $customer->getCollection()
- ->addFieldToFilter('sku', $sku)
- ->count();
- return $collectionCount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement