/** * 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); } }
/** * 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; }
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; }
/** * 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; }