本文整理汇总了PHP中ProductCategory::getByMageId方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductCategory::getByMageId方法的具体用法?PHP ProductCategory::getByMageId怎么用?PHP ProductCategory::getByMageId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductCategory
的用法示例。
在下文中一共展示了ProductCategory::getByMageId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateProduct
function updateProduct($pro, $fileName, $line)
{
$clientScript = CatelogConnector::getConnector(B2BConnector::CONNECTOR_TYPE_CATELOG, getWSDL(), 'B2BUser', 'B2BUser');
try {
$transStarted = false;
try {
Dao::beginTransaction();
} catch (Exception $e) {
$transStarted = true;
}
$sku = trim($pro['sku']);
$product = Product::getBySku($pro['sku']);
$mageId = trim($pro['product_id']);
$name = trim($pro['name']);
$short_description = trim($pro['short_description']);
$description = trim($pro['description']);
$weight = trim($pro['weight']);
$statusId = trim($pro['status']);
$price = trim($pro['price']);
$specialPrice = trim($pro['special_price']);
$specialPrice_From = trim($pro['special_from_date']) === '' ? trim($pro['special_from_date']) : null;
$specialPrice_To = trim($pro['special_to_date']) === '' ? trim($pro['special_to_date']) : null;
$supplierName = trim($pro['supplier']);
$attributeSet = ProductAttributeSet::get(trim($pro['attributeSetId']));
if (!$product instanceof Product) {
$product = Product::create($sku, $name);
}
$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)->setAttributeSet($attributeSet)->setShortDescription($short_description)->setFullDescAssetId(trim($asset->getAssetId()))->setIsFromB2B(true)->setStatus(ProductStatus::get($statusId))->setSellOnWeb(true)->setManufacturer($clientScript->getManufacturerName(trim($pro['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 ($supplierName !== '') {
$product->addSupplier(Supplier::create($supplierName, $supplierName, true));
}
if (isset($pro['categories']) && count($pro['categories']) > 0) {
$product->clearAllCategory();
foreach ($pro['categories'] as $cateMageId) {
if (!($category = ProductCategory::getByMageId($cateMageId)) instanceof ProductCategory) {
continue;
}
$product->addCategory($category);
}
}
if ($transStarted === false) {
Dao::commitTransaction();
}
//TODO remove the file
removeLineFromFile($fileName, $line);
echo $product->getId() . " => done! \n";
} catch (Exception $ex) {
if ($transStarted === false) {
Dao::rollbackTransaction();
}
throw $ex;
}
}
示例2: importProducts
/**
* 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;
}