Пример #1
0
 public function syncProductAndProductCategory()
 {
     $cronStartDateTime = UDate::now();
     $criteria = array("(sku != '' OR (mageId != '' AND mageId != 0))");
     $param = array();
     if (($lastUpdateDateTime = trim(SystemSettings::getSettings(SystemSettings::TYPE_PRODUCT_LAST_UPDATED))) !== '') {
         $criteria[] = "updated >= ?";
         $param[] = $lastUpdateDateTime;
     }
     $counter = Product::countByCriteria(implode(" and ", $criteria), $param);
     if ($counter > 0) {
         $this->_mySoapClient = $this->_connect();
         $this->syncAllProductCategory();
         $productArray = Product::findByCriteria(implode(" and ", $criteria), $param);
         foreach ($productArray as $product) {
             $linkedCategories = array();
             $product_categoryArray = Product_Category::getCategories($product);
             if (is_array($product_categoryArray) && count($product_categoryArray) > 0) {
                 $linkedCategories = array_map(create_function('$a', 'return $a->getCategory()->getMageId();'), $product_categoryArray);
             }
             /// if no category is found, set the default to 1 ///
             if (count($linkedCategories) <= 0) {
                 $linkedCategories = array(1);
             }
             $productData = $this->_generateProductData($product, $linkedCategories);
             if (($productMageId = trim($product->getMageId())) === '' || $productMageId === '0') {
                 $attributeSets = $this->_mySoapClient->catalogProductAttributeSetList($session);
                 $attributeSet = current($attributeSets);
                 $productType = 'simple';
                 $newMageId = $this->_mySoapClient->catalogProductCreate($this->_session, $productType, $attributeSet->set_id, trim($product->getSku()), $productData);
                 if (is_numeric($newMageId)) {
                     $product->setMageId($newMageId)->save();
                 } else {
                     $this->_handle_failed_product($product, $cronStartDateTime);
                 }
             } else {
                 // update product on magento
                 $updated = $this->_mySoapClient->catalogProductUpdate($this->_session, $productMageId, $productData);
                 if ($updated === false) {
                     $this->_handle_failed_product($product, $cronStartDateTime, "update");
                 }
             }
         }
     }
     SystemSettings::addSettings(SystemSettings::TYPE_PRODUCT_LAST_UPDATED, $cronStartDateTime);
     //Debug::inspect($products); die();
 }
Пример #2
0
 public function getSitemapNode()
 {
     $result = $params = array();
     $Product = new Product();
     $Categories = Product_Category::getCategories();
     foreach ($Categories as $Category) {
         $result[] = URL::get($Category);
         $params = array();
         $params[] = 'CategoryId = ' . $Category->Id;
         foreach ($Product->findList($params, 'Position asc') as $Item) {
             $result[] = URL::get($Item);
         }
     }
     return $result;
 }
Пример #3
0
 /**
  * (non-PHPdoc)
  * @see BaseEntityAbstract::getJson()
  */
 public function getJson($extra = array(), $reset = false)
 {
     try {
         $array = $extra;
         if (!$this->isJsonLoaded($reset)) {
             $array['prices'] = array_map(create_function('$a', 'return $a->getJson();'), $this->getPrices());
             $array['manufacturer'] = $this->getManufacturer() instanceof Manufacturer ? $this->getManufacturer()->getJson() : null;
             $array['supplierCodes'] = array_map(create_function('$a', 'return $a->getJson();'), SupplierCode::getAllByCriteria('productId = ?', array($this->getId())));
             $array['productCodes'] = array_map(create_function('$a', 'return $a->getJson();'), ProductCode::getAllByCriteria('productId = ?', array($this->getId())));
             $array['images'] = array_map(create_function('$a', 'return $a->getJson();'), $this->getImages());
             $array['categories'] = array_map(create_function('$a', '$json = $a->getJson(); return $json["category"];'), Product_Category::getCategories($this));
             $array['fullDescriptionAsset'] = ($asset = Asset::getAsset($this->getFullDescAssetId())) instanceof Asset ? $asset->getJson() : null;
             $array['locations'] = array_map(create_function('$a', 'return $a->getJson();'), PreferredLocation::getPreferredLocations($this));
             $array['unitCost'] = $this->getUnitCost();
             $array['priceMatchRule'] = ($i = ProductPriceMatchRule::getByProduct($this)) instanceof ProductPriceMatchRule ? $i->getJson() : null;
             $array['attributeSet'] = ($i = $this->getAttributeSet()) instanceof ProductAttributeSet ? $i->getJson() : null;
             $array['status'] = ($i = $this->getStatus()) instanceof ProductStatus ? $i->getJson() : null;
         }
     } catch (Exception $ex) {
         throw new Exception(' ********** getJson exception :' . $ex->getMessage());
     }
     return parent::getJson($array, $reset);
 }
Пример #4
0
 /**
  * Getting the default value for the row
  *
  * @param Product $product
  *
  * @return multitype:string number ProductStatus
  */
 private static function _getDefaultData(Product $product)
 {
     $xmap = Product_Category::getCategories($product);
     return array('store' => 'admin', 'websites' => 'base', 'attribute_set' => '', 'type' => 'simple', 'category_ids' => implode(',', array_map(create_function('$a', '$a->getCategory()->getMageId();'), $xmap)), 'sku' => $product->getSku(), 'has_options' => '0', 'name' => $product->getName(), 'meta_title' => '', 'meta_description' => '', 'image' => '', 'small_image' => '', 'thumbnail' => '', 'url_key' => '', 'url_path' => '', 'custom_design' => '', 'page_layout' => 'No layout updates', 'options_container' => 'Block after Info Column', 'image_label' => '', 'small_image_label' => '', 'thumbnail_label' => '', 'country_of_manufacture' => '', 'msrp_enabled' => 'Use config', 'msrp_display_actual_price_type' => 'Use config', 'gift_message_available' => '', 'supplier' => '', 'man_code' => '', 'price' => '', 'special_price' => '', 'weight' => '', 'msrp' => '', 'manufacturer' => $product->getManufacturer() instanceof Manufacturer ? $product->getManufacturer()->getName() : '', 'status' => intval($product->getActive()) === 1 ? 'Enabled' : 'Disabled', 'is_recurring' => 'No', 'visibility' => 'Catalog, Search', 'tax_class_id' => 'Taxable Goods', 'all_ln_stock' => $product->getStatus() instanceof ProductStatus ? $product->getStatus()->getName() : '', 'pc_sln_ssd' => '', 'hd_sln_interface' => '', 'description' => '', 'short_description' => trim($product->getShortDescription()), 'meta_keyword' => '', 'custom_layout_update' => '', 'videobox' => '', 'customtab' => '', 'customtabtitle' => 'Features', 'shortparams' => '', 'special_from_date' => '', 'special_to_date' => '', 'news_from_date' => trim($product->getAsNewFromDate()), 'news_to_date' => trim($product->getAsNewToDate()), 'custom_design_from' => '', 'custom_design_to' => '', 'qty' => intval($product->getStockOnHand()), 'min_qty' => 0, 'use_config_min_qty' => 1, 'is_qty_decimal' => 0, 'backorders' => 0, 'use_config_backorders' => 1, 'min_sale_qty' => 1, 'use_config_min_sale_qty' => 1, 'max_sale_qty' => 0, 'use_config_max_sale_qty' => 1, 'is_in_stock' => 1, 'low_stock_date' => '', 'notify_stock_qty' => 0, 'use_config_notify_stock_qty' => 1, 'manage_stock' => 0, 'use_config_manage_stock' => 1, 'stock_status_changed_auto' => 0, 'use_config_qty_increments' => 1, 'qty_increments' => 0, 'use_config_enable_qty_inc' => 1, 'enable_qty_increments' => 0, 'is_decimal_divided' => 0, 'stock_status_changed_automatically' => 0, 'use_config_enable_qty_increments' => 1, 'product_name' => trim($product->getName()), 'store_id' => 0, 'product_type_id' => 'simple', 'product_status_changed' => '', 'product_changed_websites' => '', 'reward_point_product' => '', 'mw_reward_point_sell_product' => '');
 }