Example #1
0
 public function save(RM_Barcode_Object $obBarcode, &$error)
 {
     try {
         $obBarcode->save();
         return TRUE;
     } catch (RM_Validator_Exception $e) {
         foreach ($e->getResult()->getErrors() as $err) {
             break;
         }
         if ($err['code'] == 'not_empty' || $err['code'] == 'not_null') {
             $error = 'barcode.fill_required_fields';
         } else {
             if (in_array($err['code'], qw2('no_such_segment no_such_class no_such_family no_such_brick no_such_attributes no_attributes2brick no_such_values no_values2attribute'))) {
                 $error = 'gpc.' . $err['code'];
             } else {
                 $error = 'barcode.cannot_edit_object';
             }
         }
         return FALSE;
     }
     /*		catch (Exception $e)
     		{
     			$error = 'barcode.cannot_edit_object';
     			return FALSE;
     		}*/
 }
Example #2
0
 public function addFlavoursToBarcode(RM_Barcode_Object $obBarcode, $flavour_names, $flavour_type, &$error)
 {
     $result = FALSE;
     if ($flavour_names) {
         if (!in_array($flavour_type, M('Gpc')->flavour_types())) {
             $error = 'gpc.wrong_flavour_type';
         } else {
             foreach ($obBarcode->getFlavours() as $obFlavour) {
                 $obFlavour->removeBarcode($obBarcode, $flavour_type);
             }
             foreach ($flavour_names as $flavour_name) {
                 if (!trim($flavour_name)) {
                     continue;
                 }
                 if (isNull($obFlavour = M('Gpc')->loadFlavourByName(trim($flavour_name)))) {
                     $error = 'gpc.no_such_flavours';
                 } else {
                     $obFlavour->addBarcode($obBarcode, $flavour_type);
                     $result = TRUE;
                 }
             }
         }
     }
     return $result;
 }
Example #3
0
 /**
  *	Returns brand name or parses and returns brand name from barcode description
  *
  *	@param		RM_Barcode_Object		obBarcode
  *	@return		string
  **/
 protected function _getBrandName(RM_Barcode_Object $obBarcode)
 {
     if (isNull($obBarcode->getBrand())) {
         return $this->parseBrand($obBarcode);
     }
     return $obBarcode->getBrand()->name;
 }
Example #4
0
 public function getNewBarcodeInFamily(RM_Barcode_Object $obBarcode, $new_attribute_1 = NULL)
 {
     if (isNull($obFamily = $obBarcode->getFamily())) {
         $obFamily = $this->createFamily(array('barcode_value' => $obBarcode->value));
         $obFamily->save();
         $this->family()->updateBarcodeValueByFamily($obBarcode, $obFamily);
     }
     return $this->family()->createBarcodeAndAddToFamily($obFamily, $new_attribute_1, $obBarcode->value);
 }
Example #5
0
 /**
  *	Creates (dosn't save) catalog price object
  *
  *	@param 		array					data
  *	@param 		RM_Barcode_Object		obBarcode
  *	@return		RM_Store_Object
  **/
 public function createPrice($data, RM_Barcode_Object $obBarcode)
 {
     $data['barcode_id'] = $obBarcode->id();
     $data['catalog_price'] = str_replace(',', '.', $data['catalog_price']);
     return $this->_mapper->storage('catalogprice')->createObject($data);
 }
Example #6
0
 /**
  * Checks and cleans Flavour2Barcode relation using Flavour2Brick
  *
  * @param 		RM_Barcode_Object			obBarcode
  * @return		bool
  **/
 public function cleanBarcodeFlavours(RM_Barcode_Object $obBarcode)
 {
     if (isNull($obBrick = $obBarcode->getBrick())) {
         return 0;
     }
     $query = M('Db')->createQuery($this->_tables['flavour'] . ' AS f')->what('f.*')->what('f2ba.type')->join('f', 'LEFT JOIN ' . $this->_tables['flavour2barcode'] . ' f2ba ON f2ba.' . $this->_fields['flavour2barcode']['flavour_id'] . ' = f.' . $this->_fields['flavour']['id'] . ' AND f2ba.' . $this->_fields['flavour2barcode']['barcode_id'] . ' = ?', $obBarcode->id())->join('f2ba', 'LEFT JOIN ' . $this->_tables['flavour2brick'] . ' f2br ON f2br.' . $this->_fields['flavour2brick']['flavour_id'] . ' = f.' . $this->_fields['flavour']['id'] . ' AND f2br.' . $this->_fields['flavour2brick']['brick_id'] . ' = ?' . ' AND f2br.' . $this->_fields['flavour2brick']['type'] . ' = f2ba.' . $this->_fields['flavour2barcode']['type'], $obBrick->id())->where('f2ba.' . $this->_fields['flavour2brick']['flavour_id'] . ' IS NOT NULL')->where('f2br.' . $this->_fields['flavour2brick']['brick_id'] . ' IS NULL');
     $request = $this->_storages['flavour']->request($query, array('id' => 'f.' . $this->_fields['flavour']['id']), M('Store')->factoryData($this->_storages['flavour']->factory(), array($this->_fields['flavour2barcode']['type'])));
     $result = 0;
     foreach ($request as $obFlavour) {
         $obFlavour->removeBarcode($obBarcode, $obFlavour->type);
         $result = 1;
     }
     return $result;
 }
Example #7
0
 public function updateBarcodeValueByFamily(RM_Barcode_Object &$obBarcode, RM_Barcode_Family &$obFamily, $restriction = array())
 {
     $obBarcode->barcode_family_id = $obFamily->id();
     $obFamily->save();
     $obBarcode->save();
 }