/**
  * @param Mage_Eav_Model_Entity_Type $object
  * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
  * @param mixed $value
  * @return $this
  * @throws Mage_Core_Exception
  */
 protected function _saveAttribute($object, $attribute, $value)
 {
     $table = $attribute->getBackend()->getTable();
     if (!isset($this->_attributeValuesToSave[$table])) {
         $this->_attributeValuesToSave[$table] = array();
     }
     $entityIdField = $attribute->getBackend()->getEntityIdField();
     $data = array('entity_type_id' => $object->getEntityTypeId(), $entityIdField => $object->getId(), 'attribute_id' => $attribute->getId(), 'value' => $this->_prepareValueForSave($value, $attribute));
     $this->_attributeValuesToSave[$table][] = $data;
     $this->_saveEntityData($object);
     return $this;
 }
Beispiel #2
0
 /**
  * Retreive new incrementId
  *
  * @param int $storeId
  * @return string
  */
 public function fetchNewIncrementId($storeId = null)
 {
     $entityTypeCode = $this->getEntityTypeCode();
     switch ($entityTypeCode) {
         case 'vendor_order':
             // To get correct column name (vendor_total_orders)
             $entityTypeCode = 'order';
         case 'invoice':
         case 'creditmemo':
         case 'shipment':
             $vendor = Mage::helper('smvendors')->getVendorLogin();
             if (!$vendor) {
                 // Split order when creating from front-end.
                 $vendor = $this->getData('vendor_object');
             }
             if ($vendor) {
                 $lastId = $vendor->getData("vendor_total_{$entityTypeCode}s");
                 $incrementId = $vendor->getVendorPrefix() . '-' . str_pad($lastId + 1, 9, 0, STR_PAD_LEFT);
                 $vendor->setData("vendor_total_{$entityTypeCode}s", $lastId + 1);
                 $vendor->save();
                 return $incrementId;
             } else {
                 return parent::fetchNewIncrementId($storeId);
             }
         default:
             return parent::fetchNewIncrementId($storeId);
     }
 }
Beispiel #3
0
 /**
  * Retreive new incrementId
  *
  * @param int $storeId
  * @return string
  */
 public function fetchNewIncrementId($storeId = null)
 {
     $incrementId = parent::fetchNewIncrementId($storeId);
     // save in store table default numbers
     if (!$incrementId) {
         return false;
     }
     if (!Mage::getStoreConfig('amnumber/general/enabled', $storeId)) {
         return $incrementId;
     }
     $type = $this->getEntityTypeCode();
     if (!in_array($type, array('order', 'shipment', 'invoice', 'creditmemo'))) {
         return $incrementId;
     }
     // same mumber as order
     if (Mage::getStoreConfig('amnumber/' . $type . '/same', $storeId)) {
         return $incrementId;
     }
     $timeOffset = trim(Mage::getStoreConfig('amnumber/general/offset', $storeId));
     if (!preg_match('/^[+\\-]\\d+$/', $timeOffset)) {
         $timeOffset = 0;
     }
     $now = 3600 * $timeOffset + time();
     $cfg = Mage::getStoreConfig('amnumber/' . $type, $storeId);
     //get last counter value and update it
     $start = max(intVal($cfg['start']), 0);
     $oldDate = $this->_getNotCachedConfig('date', $storeId);
     $last = $this->_getNotCachedConfig('counter', $storeId);
     if ($last->getValue() > 0) {
         // not first time
         if ($cfg['reset']) {
             //we track date change
             // date has changed
             if (!$oldDate->getValue() || date($cfg['reset'], $now) != date($cfg['reset'], strtotime($oldDate->getValue()))) {
                 $last->setValue($start);
             }
         }
     }
     //         else {
     //             $last->setValue($start);
     //         }
     $oldDate->setValue(date('Y-m-d', $now));
     $oldDate->save();
     $counter = max(intVal($last->getValue()), $start) + max(intVal($cfg['increment']), 1);
     $last->setValue($counter);
     $last->save();
     if (intVal($cfg['pad'])) {
         $counter = str_pad($counter, intVal($cfg['pad']), '0', STR_PAD_LEFT);
     }
     $vars = array('store_id' => $storeId, 'store' => $storeId, 'yy' => date('y', $now), 'yyyy' => date('Y', $now), 'mm' => date('m', $now), 'm' => date('n', $now), 'dd' => date('d', $now), 'd' => date('j', $now), 'hh' => date('H', $now), 'rand' => rand(1000, 9999), 'counter' => $counter);
     $incrementId = $cfg['format'];
     foreach ($vars as $k => $v) {
         $incrementId = str_replace('{' . $k . '}', $v, $incrementId);
     }
     return $incrementId;
 }
Beispiel #4
0
 protected function _afterSave()
 {
     parent::_afterSave();
     if ($this->getCreateAttributeSet() === true) {
         $this->setCreateAttributeSet(false);
         $this->isObjectNew(false);
         $this->save();
     }
     return $this;
 }
Beispiel #5
0
 public function fetchNewIncrementId($storeId = null)
 {
     $incrementId = parent::fetchNewIncrementId($storeId);
     $typeCode = $this->getEntityTypeCode();
     $allowedTypes = array('order', 'shipment', 'invoice', 'creditmemo');
     if (!$incrementId) {
         return false;
     }
     if (!Mage::getStoreConfig('ordernumber/general/enabled', $storeId) || !in_array($typeCode, $allowedTypes)) {
         return $incrementId;
     }
     if (Mage::getStoreConfig('ordernumber/' . $typeCode . '/same', $storeId)) {
         return $incrementId;
     }
     $config = Mage::getStoreConfig('ordernumber/' . $typeCode, $storeId);
     $startValue = max(intVal($config['start']), 0);
     $currentValue = $this->getConfigNotStored('counter', $storeId);
     if ($currentValue->getValue() > 0) {
         //            if($config['counter'])
         if ($config['reset_counter']) {
             $currentValue->setValue($startValue);
             //                $configStack = Mage::getModel('core/config');
             $configStack = Mage::getModel('core/config');
             //                $configStack->saveConfig('ordernumber/order/counter', 0);
             $configStack->saveConfig('ordernumber/order/reset_counter', 0);
             $configStack->cleanCache();
         } else {
             if ($config['reset']) {
                 $oldDate = $this->getConfigNotStored('date', $storeId);
                 if (!$oldDate->getValue() || date($config['reset']) != date($config['reset'], strtotime($oldDate->getValue()))) {
                     $currentValue->setValue($startValue);
                 }
                 $oldDate->setValue(date('Y-m-d'));
                 $oldDate->save();
             }
         }
     } else {
         $currentValue->setValue($startValue);
     }
     $counter = max(intVal($currentValue->getValue()), 0) + max(intVal($config['increment']), 1);
     $currentValue->setValue($counter);
     $currentValue->save();
     if (intVal($config['padding'])) {
         $counter = str_pad($counter, intVal($config['padding']), '0', STR_PAD_LEFT);
     }
     $patterns = array('store_id' => $storeId, 'yy' => date('y'), 'yyyy' => date('Y'), 'mm' => date('m'), 'm' => date('n'), 'dd' => date('d'), 'd' => date('j'), 'counter' => $counter);
     $incrementId = $config['format'];
     foreach ($patterns as $pattern => $val) {
         $incrementId = str_replace('{' . $pattern . '}', $val, $incrementId);
     }
     return $incrementId;
 }
Beispiel #6
0
 /**
  * Retreive new incrementId
  *
  * @param int $storeId
  * @return string
  */
 public function fetchNewIncrementId($storeId = null)
 {
     $this->_storeId = $storeId;
     // @TODO: make this configurable
     $this->setIncrementPerStore(true);
     if (!$this->getIncrementModel()) {
         return false;
     }
     if (!in_array($this->_entityTypeCode = $this->getEntityTypeCode(), $this->_processedEntityTypeCodes)) {
         return parent::fetchNewIncrementId($this->_storeId);
     }
     if (!$this->getIncrementPerStore() || $this->_storeId === null) {
         $this->_storeId = 0;
     }
     $this->_computeAndPersistNewIncrementId();
     return $this->_incrementId;
 }
Beispiel #7
0
 /**
  * Validate attribute set
  *
  * @param array $data
  * @param Mage_Eav_Model_Entity_Type $productEntity
  * @return bool
  */
 protected function _validateAttributeSet($data, $productEntity)
 {
     if ($this->_isUpdate()) {
         return true;
     }
     if (!isset($data['attribute_set_id']) || empty($data['attribute_set_id'])) {
         $this->_critical('Missing "attribute_set_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
     }
     /** @var $attributeSet Mage_Eav_Model_Entity_Attribute_Set */
     $attributeSet = Mage::getModel('eav/entity_attribute_set')->load($data['attribute_set_id']);
     if (!$attributeSet->getId() || $productEntity->getEntityTypeId() != $attributeSet->getEntityTypeId()) {
         $this->_critical('Invalid attribute set.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
     }
 }
 /**
  * Retrieves entity id field, based on entity configuration
  *
  * @param Mage_Eav_Model_Entity_Type|Mage_Eav_Model_Entity_Attribute $entityTypeModel
  * @return string
  */
 protected function _getEntityIdField($entityTypeModel)
 {
     if ($entityTypeModel->getEntityIdField()) {
         return $entityTypeModel->getEntityIdField();
     }
     return Mage_Eav_Model_Entity::DEFAULT_ENTITY_ID_FIELD;
 }
Beispiel #9
0
 /**
  * Generates records for catalog_product_entity_tier_price table
  *
  * @param array $row
  * @param Mage_Eav_Model_Entity_Type $entityTypeModel
  * @return array
  */
 protected function _getTierPriceRecords($row, $entityTypeModel)
 {
     if (isset($row['tier_price']) && is_array($row['tier_price'])) {
         $tableName = $entityTypeModel->getValueTablePrefix() . '_tier_price';
         $columns = $this->_getWriteAdapter()->describeTable($tableName);
         $records = array();
         foreach ($row['tier_price'] as $tierPrice) {
             $tierPrice[$this->_getEntityIdField($entityTypeModel)] = $row[$this->_getEntityIdField($entityTypeModel)];
             $records[] = $this->_getTableRecord($tierPrice, $columns);
         }
         if ($records) {
             return array($tableName => $records);
         }
     }
     return array();
 }