/** * The index handler. * * @access public * @return string The HTML code. */ public function index() { $Product = new Product(); $Category = new Product_Category(); foreach ($Category->findList(array(), 'Position asc', 0, 1) as $Category) { } $params = array(); $c = Request::get('c', $Category->Id); $params[] = 'CategoryId = ' . $c; $_GET['c'] = $c; $this->getView()->set('Products', $Product->findList($params, 'Position asc')); return $this->getView()->render(); }
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(); }
/** * (non-PHPdoc) * @see BaseEntityAbstract::getJson() */ public function getJson($extra = array(), $reset = false) { $class = __CLASS__; $array = $extra; if (!$this->isJsonLoaded($reset)) { $array['parent'] = $this->getParent() instanceof $class ? array('id' => $this->getParent()->getId()) : null; $array['root'] = array('id' => $this->getRoot()->getId()); $array['namePath'] = $this->getNamePath(); $array['noOfChildren'] = self::countByCriteria('parentId = ? and active = 1', array($this->getId())); $array['noOfProducts'] = Product_Category::countByCriteria('categoryId = ? and active = 1', array($this->getId())); $array['productAttributeSet'] = $this->getProductAttributeSet() instanceof ProductAttributeSet ? $this->getProductAttributeSet()->getJson() : null; } return parent::getJson($array, $reset); }
/** * The function returns current product Category. * * @access public * @return object The Category. */ public function getCategory() { $Category = new Product_Category(); return $Category->findItem(array('Id = ' . $this->CategoryId)); }
/** * The row with default value * * @param UDate $lastUpdatedInDB * @param Product $product * @param string $preFix * @param bool $debug * * @return multitype:string number */ private static function _getRowWithDefaultValues(UDate $lastUpdatedInDB, Product $product = null, $preFix = '', $debug = false) { $attributeSetDefault = 'Default'; $attributeSetName = $attributeSetDefault; $enabled = true; $sku = $statusId = $productName = $rrpPrice = $weight = $shortDescription = $fullDecription = $supplierName = $supplierCode = $manufacturerName = $asNewFrom = $asNewTo = $specialPrice = $specialPriceFromDate = $specialPriceToDate = ''; $categoryIds = array(2); //default category if ($product instanceof Product) { $sku = trim($product->getSku()); $productName = trim($product->getName()); $shortDescription = trim($product->getShortDescription()); $asNewFrom = $product->getAsNewFromDate() instanceof UDate ? $product->getAsNewFromDate()->format('Y-m-d H:i:sP') : ''; $asNewTo = $product->getAsNewToDate() instanceof UDate ? $product->getAsNewToDate()->format('Y-m-d H:i:sP') : ''; $weight = trim($product->getWeight()); if ($product->getAttributeSet() instanceof ProductAttributeSet) { $attributeSetName = $product->getAttributeSet()->getName(); self::_log('-- attributeSetName ', __CLASS__ . '::' . __FUNCTION__ . " attributeSetName={$attributeSetName}", $preFix); } //RRP if (($rrp = $product->getRRP()) instanceof ProductPrice) { $rrpPrice = StringUtilsAbstract::getValueFromCurrency($rrp->getPrice()); } //special price if (($specialPriceObj = $product->getNearestSpecialPrice()) instanceof ProductPrice) { $specialPrice = StringUtilsAbstract::getValueFromCurrency($specialPriceObj->getPrice()); $specialPriceFromDate = $specialPriceObj->getStart()->format('Y-m-d H:i:sP'); $specialPriceToDate = $specialPriceObj->getEnd()->format('Y-m-d H:i:sP'); if ($specialPrice == 0) { $specialPrice = ''; $specialPriceFromDate = '1990-10-10'; $specialPriceToDate = '2009-10-10'; } } else { // delete the special price //$specialPrice = StringUtilsAbstract::getValueFromCurrency('99999999'); //$specialPrice = '9999999'; $specialPrice = ''; $specialPriceFromDate = '1990-10-10'; $specialPriceToDate = '2009-10-10'; } // if it is the daily promotion time then overwrite the special price with the daily special price $isDailyPromotionTime = intval(SystemSettings::getSettings(SystemSettings::TYP_ISDAILYPROMOTIONTIME)); if ($isDailyPromotionTime === 1) { // get daily promotion price if (($specialPriceObj = $product->getDailySpecialPrice()) instanceof ProductPrice) { $dailySpecialPrice = StringUtilsAbstract::getValueFromCurrency($specialPriceObj->getPrice()); if ($dailySpecialPrice != 0) { $specialPrice = $dailySpecialPrice; $specialPriceFromDate = $specialPriceObj->getStart()->format('Y-m-d H:i:sP'); $specialPriceToDate = $specialPriceObj->getEnd()->format('Y-m-d H:i:sP'); } } } // if it is the daily promotion time then overwrite the special price with the daily special price $isWeekendPromotionTime = intval(SystemSettings::getSettings(SystemSettings::TYP_ISWEEKENDPROMOTIONTIME)); if ($isWeekendPromotionTime === 1) { // get weekend promotion price if (($specialPriceObj = $product->getWeekendSpecialPrice()) instanceof ProductPrice) { $weekendSpecialPrice = StringUtilsAbstract::getValueFromCurrency($specialPriceObj->getPrice()); if ($weekendSpecialPrice != 0) { $specialPrice = $weekendSpecialPrice; $specialPriceFromDate = $specialPriceObj->getStart()->format('Y-m-d H:i:sP'); $specialPriceToDate = $specialPriceObj->getEnd()->format('Y-m-d H:i:sP'); } } } //full description if (($asset = Asset::getAsset($product->getFullDescAssetId())) instanceof Asset) { //$fullDecription = '"' . $asset->read() . '"'; $fullDecription = $asset->read(); } //supplier if (count($supplierCodes = SupplierCode::getAllByCriteria('productId = ?', array($product->getId()), true, 1, 1)) > 0) { $supplierName = ($supplier = $supplierCodes[0]->getSupplier()) instanceof Supplier ? $supplier->getName() : ''; $supplierCode = trim($supplierCodes[0]->getCode()); } //Manufacturer if ($product->getManufacturer() instanceof Manufacturer) { $manufacturerName = trim($product->getManufacturer()->getName()); } //disable or enabled if (intval($product->getActive()) === 0 || intval($product->getSellOnWeb()) === 0) { $enabled = false; } else { if ($product->getStatus() instanceof ProductStatus && intval($product->getStatus()->getId()) === ProductStatus::ID_DISABLED) { $enabled = false; } } //categories if (count($categories = Product_Category::getAllByCriteria('productId = ?', array($product->getId()))) > 0) { foreach ($categories as $category) { if (!$category->getCategory() instanceof ProductCategory || ($mageCateId = trim($category->getCategory()->getMageId())) === '') { continue; } if (trim($attributeSetName) === $attributeSetDefault && ($productAttributeSet = $category->getCategory()->getProductAttributeSet()) instanceof ProductAttributeSet) { $attributeSetName = trim($productAttributeSet->getName()); } $categoryIds[] = $mageCateId; } } //ProductStatus if ($product->getStatus() instanceof ProductStatus) { $statusId = $product->getStatus()->getName(); } } $categoryIds = array_unique($categoryIds); return array("store" => 'default', "websites" => 'base', "attribute_set" => $attributeSetName, "type" => 'simple', "category_ids" => implode(',', $categoryIds), "sku" => $sku, "name" => $productName, "price" => $rrpPrice, "special_from_date" => $specialPriceFromDate, "special_to_date" => $specialPriceToDate, "special_price" => $specialPrice, "news_from_date" => $asNewFrom, "news_to_date" => $asNewTo, "status" => intval($enabled) === 1 ? 1 : 2, "visibility" => 4, "tax_class_id" => 2, "description" => $fullDecription, "short_description" => $shortDescription, "supplier" => $supplierName, "man_code" => '', "sup_code" => $supplierCode, "meta_title" => '', "meta_description" => '', "manufacturer" => $manufacturerName, "url_key" => '', "url_path" => '', "custom_design" => '', "page_layout" => '', "country_of_manufacture" => '', "msrp_enabled" => '', "msrp_display_actual_price_type" => '', "meta_keyword" => '', "custom_layout_update" => '', "custom_design_from" => '', "custom_design_to" => '', "weight" => $weight, "msrp" => 'Use config', "gift_wrapping_price" => '', "qty" => 99, "min_qty" => 99, "use_config_min_qty" => 99, "is_qty_decimal" => '', "backorders" => '', "use_config_backorders" => '', "min_sale_qty" => '', "use_config_min_sale_qty" => '', "max_sale_qty" => '', "use_config_max_sale_qty" => '', "all_ln_stock" => $statusId, "is_in_stock" => 1, "low_stock_date" => '', "notify_stock_qty" => '', "use_config_notify_stock_qty" => '', "manage_stock" => '', "use_config_manage_stock" => '', "stock_status_changed_auto" => '', "use_config_qty_increments" => '', "qty_increments" => '', "use_config_enable_qty_inc" => '', "enable_qty_increments" => '', "is_decimal_divided" => '', "stock_status_changed_automatically" => '', "use_config_enable_qty_increments" => '', "image" => '', "small_image" => '', "thumbnail" => '', "media_gallery" => '', "is_recurring" => '', "media_gallery_reset" => 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; }
/** * The index handler. * * @access public * @return string The HTML code. */ public function index() { $Category = new Product_Category(); $this->getView()->set('Categories', $Category->findList(array(), 'Position asc')); return $this->getView()->render(); }
private function _updateCategories(Product &$product, $param) { //update categories if (isset($param->CallbackParameter->categoryIds) && count($categoryIds = $param->CallbackParameter->categoryIds) > 0) { Product_Category::deleteByCriteria('productId = ?', array(trim($product->getId()))); foreach ($categoryIds as $categoryId) { if (!($category = ProductCategory::get($categoryId))) { continue; } Product_Category::create($product, $category); } } return $this; }
/** * (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); }
/** * The function returns Product Category for current Layout. * * @access public * @return object The Product Category. */ public function getCategory() { $Category = new Product_Category(); return $Category->findItem(array('Layout = ' . get_class($this))); }
/** * 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' => ''); }