/** * 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); }
/** * (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); }