Esempio n. 1
0
 public function updateSetting($sender, $param)
 {
     $result = $errors = array();
     try {
         $result = $products = array();
         $systemSetting = SystemSettings::getByType(SystemSettings::TYPE_SYSTEM_BUILD_PRODUCTS_ID);
         foreach ($param->CallbackParameter as $type => $ids) {
             $result[$type] = array();
             $products[$type] = array();
             foreach ($ids as $index => $id) {
                 $id = intval(trim($id));
                 if (($product = Product::get($id)) instanceof Product) {
                     $result[$type][] = $id;
                     $products[$type][] = $product->getJson();
                 }
             }
         }
         Dao::beginTransaction();
         $systemSetting->setValue(json_encode($result))->save();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         // 			Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($products, $errors);
 }
Esempio n. 2
0
 /**
  * SEtting the value for the system settings
  *
  * @param string $key
  * @param string $value
  * @param string $preFix
  * @param bool   $debug
  */
 private static function _setSettings($key, $value, $preFix = '', $debug = false)
 {
     $paramName = SystemSettings::TYPE_MAGENTO_SYNC;
     self::_log('-- Trying to set SystemSettings for: "' . $paramName . '" with new value: ' . $value, __CLASS__ . '::' . __FUNCTION__, $preFix);
     $settings = self::_getSettings($preFix . self::TAB, $debug);
     if (!is_array($settings)) {
         $settings = array();
     }
     self::_log('Before setting: ' . preg_replace('/\\s+/', ' ', print_r($settings, true)), '', $preFix . self::TAB);
     $settings[$key] = $value;
     self::_log('After setting: ' . preg_replace('/\\s+/', ' ', print_r($settings, true)), '', $preFix . self::TAB);
     if (!($settingObj = SystemSettings::getByType($paramName)) instanceof SystemSettings) {
         $settingObj = new SystemSettings();
         $settingObj->setType($paramName)->setDescription($paramName);
     }
     $jsonString = json_encode($settings);
     self::_log('Saving new Settings: ' . $jsonString, '', $preFix . self::TAB);
     $settingObj->setValue($jsonString)->save();
     self::_log('DONE', '', $preFix . self::TAB);
     self::_log('');
     self::$_cache[__CLASS__ . ':settings:' . $paramName] = $settings;
 }
Esempio n. 3
0
 /**
  * import all products
  *
  * @return CatelogConnector
  */
 public function importProducts()
 {
     if (!($systemSetting = SystemSettings::getByType(SystemSettings::TYPE_LAST_NEW_PRODUCT_PULL)) instanceof SystemSettings) {
         throw new Exception('cannot get LAST_NEW_PRODUCT_PULL in system setting');
     }
     $fromDate = $systemSetting->getValue();
     $products = $this->getProductList($fromDate);
     if (count($products) === 0) {
         echo 'nothing from magento. exitting' . "\n";
         return $this;
     }
     try {
         $transStarted = false;
         try {
             Dao::beginTransaction();
         } catch (Exception $e) {
             $transStarted = true;
         }
         foreach ($products as $pro) {
             $mageId = trim($pro->product_id);
             $sku = trim($pro->sku);
             $pro = $this->getProductInfo($sku, $this->getInfoAttributes());
             $created_at = trim($pro->created_at);
             $updated_at = trim($pro->updated_at);
             $product_id = trim($pro->product_id);
             if (is_null($pro) || !isset($pro->additional_attributes)) {
                 continue;
             }
             // handle extra long sku from magento, exceeding mysql sku length limit
             DaoMap::loadMap('Product');
             $skuSizeLimit = DaoMap::$map['product']['sku']['size'];
             if (strlen($sku) > $skuSizeLimit) {
                 echo 'Product ' . $sku . '(id=' . $product->getId() . ', magento Product Creation Time=' . trim($pro->created_at) . ') magento sku length exceed system sku length limit of' . $skuSizeLimit . ', skipped' . "\n";
                 continue;
             }
             $additionAttrs = $this->_getAttributeFromAdditionAttr($pro->additional_attributes);
             $name = trim($additionAttrs['name']);
             $short_description = trim($additionAttrs['short_description']);
             $description = trim($additionAttrs['description']);
             $weight = trim($additionAttrs['weight']);
             $statusId = trim($additionAttrs['status']);
             $price = trim($additionAttrs['price']);
             $specialPrice = isset($additionAttrs['special_price']) ? trim($additionAttrs['special_price']) : '';
             $specialPrice_From = isset($additionAttrs['special_from_date']) ? trim($additionAttrs['special_from_date']) : null;
             $specialPrice_To = isset($additionAttrs['special_to_date']) ? trim($additionAttrs['special_to_date']) : null;
             if (!($product = Product::getBySku($sku)) instanceof Product) {
                 $product = Product::create($sku, $name);
                 Log::logging(0, get_class($this), 'Found New Product from Magento with sku="' . trim($sku) . '" and name="' . $name . '", created_at="' . $created_at, self::LOG_TYPE, '', __FUNCTION__);
                 echo 'Found New Product from Magento with sku="' . trim($sku) . '" and name="' . $name . '", created_at="' . $created_at . ', updated_at' . $updated_at . "\n";
             } elseif (Product::getBySku($sku) instanceof Product) {
                 $product = Product::getBySku($sku);
                 echo 'Found Existing Product from Magento with sku="' . trim($sku) . '" and name="' . $name . '", created_at="' . $created_at . ', updated_at' . $updated_at . '"' . "\n";
                 echo "\t" . 'Name: "' . $name . '"' . "\n";
                 echo "\t" . 'MageId: "' . $mageId . '"' . "\n";
                 echo "\t" . 'Short Description: "' . $short_description . '"' . "\n";
                 echo "\t" . 'Full Description: "' . $description . '"' . "\n";
                 echo "\t" . 'Status: "' . ProductStatus::get($statusId) . '"' . "\n";
                 echo "\t" . 'Manufacturer: id=' . $this->getManufacturerName(trim($additionAttrs['manufacturer']))->getId() . ', name="' . $this->getManufacturerName(trim($additionAttrs['manufacturer']))->getName() . '"' . "\n";
                 echo "\t" . 'Price: "' . $price . '"' . "\n";
                 echo "\t" . 'Weight: "' . $weight . '"' . "\n";
             }
             $asset = ($assetId = trim($product->getFullDescAssetId())) === '' || !($asset = Asset::getAsset($assetId)) instanceof Asset ? Asset::registerAsset('full_desc_' . $sku, $description, Asset::TYPE_PRODUCT_DEC) : $asset;
             $product->setName($name)->setMageId($mageId)->setShortDescription($short_description)->setFullDescAssetId(trim($asset->getAssetId()))->setIsFromB2B(true)->setStatus(ProductStatus::get($statusId))->setSellOnWeb(true)->setManufacturer($this->getManufacturerName(trim($additionAttrs['manufacturer'])))->save()->clearAllPrice()->addPrice(ProductPriceType::get(ProductPriceType::ID_RRP), $price)->addInfo(ProductInfoType::ID_WEIGHT, $weight);
             if ($specialPrice !== '') {
                 $product->addPrice(ProductPriceType::get(ProductPriceType::ID_CASUAL_SPECIAL), $specialPrice, $specialPrice_From, $specialPrice_To);
             }
             if (isset($additionAttrs['supplier']) && ($supplierName = trim($additionAttrs['supplier'])) !== '') {
                 $product->addSupplier(Supplier::create($supplierName, $supplierName, true));
             }
             if (isset($pro->categories) && count($pro->categories) > 0) {
                 $product->clearAllCategory();
                 foreach ($pro->category_ids as $cateMageId) {
                     if (!($category = ProductCategory::getByMageId($cateMageId)) instanceof ProductCategory) {
                         continue;
                     }
                     $product->addCategory($category);
                 }
             }
         }
         $systemSetting->setValue($updated_at)->save();
         if ($transStarted === false) {
             Dao::commitTransaction();
         }
     } catch (Exception $ex) {
         if ($transStarted === false) {
             Dao::rollbackTransaction();
         }
         throw $ex;
     }
     return $this;
 }