コード例 #1
0
 /**
  * Update product code
  *
  * @param Product $product
  * @param unknown $myobCode
  * @param ProductCodeType $productCodeType
  * @param string $assetAccNo
  * @param string $revenueAccNo
  * @param string $costAccNo
  *
  * @return Product
  */
 private function updateProductCode(Product $product, $myobCode, ProductCodeType $productCodeType, $assetAccNo = '', $revenueAccNo = '', $costAccNo = '')
 {
     try {
         Dao::beginTransaction();
         // only take the myobCode (myob item#) after the first dash
         $position = strpos($myobCode, '-');
         if ($position) {
             $myobCodeAfter = substr($myobCode, $position + 1);
             // get everything after first dash
             $myobCodeAfter = str_replace(' ', '', $myobCodeAfter);
             // remove all whitespace
         } else {
             $myobCodeAfter = $myobCode;
         }
         $result = array();
         $result['product'] = $product->getJson();
         $result['code'] = $myobCodeAfter;
         $result['MYOBcode'] = $myobCode;
         $result['assetAccNo'] = $assetAccNo;
         $result['revenueAccNo'] = $revenueAccNo;
         $result['costAccNo'] = $costAccNo;
         // if such code type for such product exist, update it to the new one
         if (!empty($myobCode)) {
             if (count($productCodes = ProductCode::getAllByCriteria('pro_code.typeId = ? and pro_code.productId = ?', array($productCodeType->getId(), $product->getId()), true, 1, 1)) > 0) {
                 $productCodes[0]->setCode($myobCodeAfter)->save();
                 $result['codeNew'] = false;
             } else {
                 $newCode = ProductCode::create($product, $productCodeType, trim($myobCodeAfter));
                 $result['codeNew'] = true;
             }
         }
         // do the same for MYOB code (NOTE: have to have MYOB code in code type !!!)
         if (!empty($myobCode)) {
             if (count($productCodes = ProductCode::getAllByCriteria('pro_code.typeId = ? and pro_code.productId = ?', array(ProductCodeType::ID_MYOB, $product->getId()), true, 1, 1)) > 0) {
                 $productCodes[0]->setCode($myobCode)->save();
                 $result['MYOBcodeNew'] = false;
             } else {
                 ProductCode::create($product, ProductCodeType::get(ProductCodeType::ID_MYOB), trim($myobCode));
                 $result['MYOBcodeNew'] = true;
             }
         }
         if (!empty($assetAccNo)) {
             $product->setAssetAccNo($assetAccNo)->save();
         }
         if (!empty($revenueAccNo)) {
             $product->setRevenueAccNo($revenueAccNo)->save();
         }
         if (!empty($costAccNo)) {
             $product->setCostAccNo($costAccNo)->save();
         }
         Dao::commitTransaction();
         return $product;
     } catch (Exception $e) {
         Dao::rollbackTransaction();
         echo $e;
         exit;
     }
 }
コード例 #2
0
ファイル: ProductCode.php プロジェクト: larryu/magento-b2b
 /**
  * Getting the productcodes
  *
  * @param Product         $product
  * @param ProductCodeType $type
  * @param string          $activeOnly
  * @param string          $pageNo
  * @param array           $pageSize
  * @param array           $orderBy
  *
  * @return Ambigous <multitype:, multitype:BaseEntityAbstract >
  */
 public static function getCodes(Product $product, ProductCodeType $type, $activeOnly = true, $pageNo = null, $pageSize = DaoQuery::DEFAUTL_PAGE_SIZE, $orderBy = array(), &$stats = array())
 {
     return self::getAllByCriteria('productId = ? and typeId = ?', array($product->getId(), $type->getId()), $activeOnly, $pageNo, $pageSize, $orderBy, $stats);
 }