当前位置: 首页>>代码示例>>PHP>>正文


PHP Manufacturer::get方法代码示例

本文整理汇总了PHP中Manufacturer::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Manufacturer::get方法的具体用法?PHP Manufacturer::get怎么用?PHP Manufacturer::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Manufacturer的用法示例。


在下文中一共展示了Manufacturer::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveItem

 /**
  * (non-PHPdoc)
  * @see DetailsPageAbstract::saveItem()
  */
 public function saveItem($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         $product = !isset($param->CallbackParameter->id) ? new Product() : Product::get(trim($param->CallbackParameter->id));
         if (!$product instanceof Product) {
             throw new Exception('Invalid Product passed in!');
         }
         if (!($manufacturer = Manufacturer::get(trim($param->CallbackParameter->manufacturerId))) instanceof Manufacturer) {
             throw new Exception('Invalid Manufacturer/Brand!');
         }
         if (!($status = ProductStatus::get(trim($param->CallbackParameter->statusId))) instanceof ProductStatus) {
             throw new Exception('Invalid Status!');
         }
         $sku = trim($param->CallbackParameter->sku);
         if (!isset($param->CallbackParameter->id) && ($sku === '' || Product::getBySku($sku) instanceof Product)) {
             throw new Exception('Invalid SKU (' . $sku . ') passed in OR already exist.');
         }
         $name = trim($param->CallbackParameter->name);
         $shortDescription = trim($param->CallbackParameter->shortDescription);
         $sellOnWeb = trim($param->CallbackParameter->sellOnWeb) === '1';
         $weight = doubleval(trim($param->CallbackParameter->weight));
         $product->setName($name)->setSku($sku)->setShortDescription($shortDescription)->setStatus($status)->setManufacturer($manufacturer)->setSellOnWeb($sellOnWeb)->setAsNewFromDate(trim($param->CallbackParameter->asNewFromDate))->setAsNewToDate(trim($param->CallbackParameter->asNewToDate))->setAssetAccNo(trim($param->CallbackParameter->assetAccNo))->setRevenueAccNo(trim($param->CallbackParameter->revenueAccNo))->setCostAccNo(trim($param->CallbackParameter->costAccNo))->setWeight($weight);
         if (trim($product->getId()) === '') {
             $product->setIsFromB2B(false);
         }
         $product->save();
         $this->_updateFullDescription($product, $param)->_updateCategories($product, $param)->_uploadImages($product, $param)->_setSupplierCodes($product, $param)->_setBarcodes($product, $param)->_setPrices($product, $param)->_setLocation($product, $param);
         $product->save();
         $results['url'] = '/product/' . $product->getId() . '.html';
         $results['item'] = $product->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
开发者ID:larryu,项目名称:magento-b2b,代码行数:43,代码来源:DetailsController.php

示例2: _dataFeedImport

 /**
  * create/update product via datafeed.
  *
  * @param array $params
  *
  * @return array
  */
 private function _dataFeedImport($params)
 {
     try {
         Dao::beginTransaction();
         $this->_runner->log('dataFeedImport: ', __CLASS__ . '::' . __FUNCTION__);
         $sku = $this->_getPram($params, 'sku', null, true);
         $name = $this->_getPram($params, 'name', null, true);
         $shortDesc = $this->_getPram($params, 'short_description', $name);
         $fullDesc = $this->_getPram($params, 'description', '');
         $price = StringUtilsAbstract::getValueFromCurrency($this->_getPram($params, 'price', null, true));
         $supplierName = $this->_getPram($params, 'supplier', null, true);
         $supplierCode = $this->_getPram($params, 'supplier_code', null, true);
         $supplier = $this->_getEntityByName($supplierName, 'Supplier');
         if (!$supplier instanceof Supplier) {
             throw new Exception("invalid supplier:" . $supplierName);
         }
         $manufacturerId = $this->_getPram($params, 'manufacturer_id', null, true);
         $manufacturer = Manufacturer::get($manufacturerId);
         if (!$manufacturer instanceof Manufacturer) {
             throw new Exception("invalid Manufacturer:" . $manufacturerId);
         }
         $statusName = $this->_getPram($params, 'availability', null, true);
         $status = $this->_getEntityByName($statusName, 'ProductStatus');
         if (!$status instanceof ProductStatus) {
             throw new Exception("invalid ProductStatus:" . $statusName);
         }
         $assetAccNo = $this->_getPram($params, 'assetAccNo', null);
         $revenueAccNo = $this->_getPram($params, 'revenueAccNo', null);
         $costAccNo = $this->_getPram($params, 'costAccNo', null);
         $categoryIds = $this->_getPram($params, 'category_ids', array());
         $canSupplyQty = $this->_getPram($params, 'qty', 0);
         $weight = $this->_getPram($params, 'weight', 0);
         $images = $this->_getPram($params, 'images', array());
         $showOnWeb = $this->_getPram($params, 'showonweb', true);
         $attributesetId = $this->_getPram($params, 'attributesetId', null);
         $canUpdate = false;
         //if we have this product already, then skip
         if (!($product = Product::getBySku($sku)) instanceof Product) {
             $this->_runner->log('new SKU(' . $sku . ') for import, creating ...', '', APIService::TAB);
             $product = Product::create($sku, $name, '', null, null, false, $shortDesc, $fullDesc, $manufacturer, $assetAccNo, $revenueAccNo, $costAccNo, null, null, true, $weight, $attributesetId);
             $this->log_product("NEW", "=== new === sku={$sku}, name={$name}, shortDesc={$shortDesc}, fullDesc={$fullDesc}, category=" . implode(', ', $categoryIds), '', APIService::TAB);
             $canUpdate = true;
         } else {
             //$this->log_product("UPDATE", "=== update === sku=$sku, name=$name, shortDesc=$shortDesc, fullDesc=$fullDesc, category=" . implode(', ', $categoryIds),  '', APIService::TAB);
             //if there is no price matching rule for this product
             if (($rulesCount = intval(ProductPriceMatchRule::countByCriteria('active = 1 and productId = ?', array($product->getId())))) === 0) {
                 $this->_runner->log('Found SKU(' . $sku . '): ', '', APIService::TAB);
                 $fullAsset = Asset::getAsset($product->getFullDescAssetId());
                 $this->_runner->log('Finding asset for full description, assetId:' . ($fullAsset instanceof Asset ? $fullAsset->getAssetId() : ''), '', APIService::TAB . APIService::TAB);
                 $fullAssetContent = '';
                 if ($fullAsset instanceof Asset) {
                     $fullAssetContent = file_get_contents($fullAsset->getPath());
                     $this->_runner->log('Got full asset content before html_decode: <' . $fullAssetContent . '>', '', APIService::TAB . APIService::TAB);
                     $fullAssetContent = trim(str_replace('&nbsp;', '', $fullAssetContent));
                     $this->_runner->log('Got full asset content after html_code: <' . $fullAssetContent . '>', '', APIService::TAB . APIService::TAB);
                 }
                 if ($fullAssetContent === '') {
                     $this->_runner->log('GOT BLANK FULL DESD. Updating full description.', '', APIService::TAB . APIService::TAB . APIService::TAB);
                     if ($fullAsset instanceof Asset) {
                         Asset::removeAssets(array($fullAsset->getAssetId()));
                         $this->_runner->log('REMOVED old empty asset for full description', '', APIService::TAB . APIService::TAB . APIService::TAB);
                     }
                     $fullAsset = Asset::registerAsset('full_description_for_product.txt', $fullDesc, Asset::TYPE_PRODUCT_DEC);
                     $product->setFullDescAssetId($fullAsset->getAssetId())->save();
                     $this->_runner->log('Added a new full description with assetId: ' . $fullAsset->getAssetId(), '', APIService::TAB . APIService::TAB);
                     $canUpdate = true;
                     $this->log_product("UPDATE", "=== updating === sku={$sku} Found ", '', APIService::TAB);
                 } else {
                     $this->log_product("SKIP", "=== SKIP updating === sku={$sku} for full description not null", '', APIService::TAB);
                 }
             } else {
                 $this->_runner->log('SKIP updating. Found ProductPriceMatchRule count:' . $rulesCount, '', APIService::TAB);
                 $this->log_product("SKIP", "=== SKIP updating === sku={$sku} Found ProductPriceMatchRule count:{$rulesCount}", '', APIService::TAB);
             }
         }
         $json = $product->getJson();
         //only update categories and status when there is no pricematching rule or created new
         if ($canUpdate === true) {
             //short description, name, manufacturer
             $this->_runner->log('Updating the price to: ' . StringUtilsAbstract::getCurrency($price), '', APIService::TAB . APIService::TAB);
             $product->setShortDescription($shortDesc)->setName($name)->setManufacturer($manufacturer)->setWeight($weight)->setSellOnWeb($showOnWeb)->clearAllPrice()->addPrice(ProductPriceType::get(ProductPriceType::ID_RRP), $price);
             //show on web
             if (is_array($categoryIds) && count($categoryIds) > 0) {
                 $this->_runner->log('Updating the categories: ' . implode(', ', $categoryIds), '', APIService::TAB . APIService::TAB);
                 foreach ($categoryIds as $categoryId) {
                     if (!($category = ProductCategory::get($categoryId)) instanceof ProductCategory) {
                         continue;
                     }
                     if (count($ids = explode(ProductCategory::POSITION_SEPARATOR, trim($category->getPosition()))) > 0) {
                         foreach (ProductCategory::getAllByCriteria('id in (' . implode(',', $ids) . ')') as $cate) {
                             $product->addCategory($cate);
                             $this->_runner->log('Updated Category ID: ' . $cate->getId(), '', APIService::TAB . APIService::TAB . APIService::TAB);
                         }
//.........这里部分代码省略.........
开发者ID:larryu,项目名称:magento-b2b,代码行数:101,代码来源:APIProductService.php

示例3: ini_set

<?php

ini_set('memory_limit', '1024M');
require_once dirname(__FILE__) . '/../main/bootstrap.php';
Core::setUser(UserAccount::get(UserAccount::ID_SYSTEM_ACCOUNT));
echo "Begin disableProducts from magento MELB TIME: " . UDate::now(UDate::TIME_ZONE_MELB) . "\n";
// config
$manufacturerIds = [23, 75, 97];
$categoryIds = [166];
// validation
$manufacturers = array();
foreach ($manufacturerIds as $id) {
    if (($i = Manufacturer::get($id)) instanceof Manufacturer) {
        $manufacturers[] = $i;
        echo 'try to disable all product with manufactuer "' . $i->getName() . '"(' . $i->getId() . ')' . "\n";
    } else {
        throw new Exception('Invalid manufactuer id "' . $id . '" passed in');
    }
}
$manufacturerIds = array_map(create_function('$a', 'return $a->getId();'), $manufacturers);
foreach ($categoryIds as $id) {
    if (($i = ProductCategory::get($id)) instanceof ProductCategory) {
        $categories[] = $i;
        echo 'try to disable all product with category "' . $i->getName() . '"(' . $i->getId() . ')' . "\n";
    } else {
        throw new Exception('Invalid category id "' . $id . '" passed in');
    }
}
$categoryIds = array_map(create_function('$a', 'return $a->getId();'), $categories);
// run
$products = Product::getProducts('', '', array(), $manufacturerIds, $categoryIds);
开发者ID:larryu,项目名称:magento-b2b,代码行数:31,代码来源:DisableMageProducts07Aug15.php


注:本文中的Manufacturer::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。