protected function _filterSql() { $date = new Zend_Date(); if (isset($this->filterdata['created_by']) && !empty($this->filterdata['created_by'])) { $this->_select->where("p.created_by = (?)", new Zend_Db_Expr("SELECT id FROM public.user WHERE upper(login) ilike '" . strtoupper($this->filterdata['created_by'] . "'"))); } if (isset($this->filterdata['name']) && !empty($this->filterdata['name'])) { $this->_select->where("p.name ilike ?", $this->filterdata['name']); } if (isset($this->filterdata['date_for']) && !empty($this->filterdata['date_for'])) { $this->filterdata['date_for'] = $date->setDate($this->filterdata['date_for'], 'YYYY-MM-dd')->toString(Zend_Date::ISO_8601); } if (isset($this->filterdata['date_to']) && !empty($this->filterdata['date_to'])) { $this->filterdata['date_to'] = $date->setDate($this->filterdata['date_to'], 'YYYY-MM-dd')->toString(Zend_Date::ISO_8601); } if (isset($this->filterdata['date_for']) && !empty($this->filterdata['date_for']) && isset($this->filterdata['date_to']) && !empty($this->filterdata['date_to'])) { $this->_select->where('created_at BETWEEN \'' . $this->filterdata['date_for'] . '\' AND \'' . $this->filterdata['date_to'] . '\''); } elseif (isset($this->filterdata['date_for']) && !empty($this->filterdata['date_for'])) { $this->_select->where('created_at > ?', $this->filterdata['date_for']); } elseif (isset($this->filterdata['date_to']) && !empty($this->filterdata['date_to'])) { $this->_select->where('created_at < ?', $this->filterdata['date_to']); } if (isset($this->filterdata['ws_service_set_id']) && !empty($this->filterdata['ws_service_set_id'])) { $this->_select->where("ws_service_set_id = ?", $this->filterdata['ws_service_set_id']); } if (isset($this->filterdata['ws_service_group_id']) && !empty($this->filterdata['ws_service_group_id'])) { $this->_select->where("ws_service_group_id = ?", $this->filterdata['ws_service_group_id']); } }
/** * Retrieve Bestseller product to show in frontend * @return mixed */ public function myBest() { $storeId = Mage::app()->getStore()->getId(); $HandleArray = Mage::app()->getLayout()->getUpdate()->getHandles(); $CategoryHandle = 'catalog_category_view'; $SourceConfig = Mage::getStoreConfig('sm_bestseller/sm_bestseller_source'); if ($SourceConfig && !empty($SourceConfig)) { $SourceType = $SourceConfig['timeperiod']; $date = new Zend_Date(); /** * Select time range to retrive bestseller */ if ($SourceType && $SourceType == 'specify') { $fromDate = $date->setDate($SourceConfig['fromdate'])->get('Y-MM-dd'); $toDate = $date->setDate($SourceConfig['todate'])->get('Y-MM-dd'); } else { /** * use switch to return begin of week, month, year... */ switch ($SourceType) { case 'subWeek': $toDate = $date->subDay($date->getDate()->get('e'))->getDate()->get('Y-MM-dd'); break; case 'subMonth': $toDate = $date->setDay(1)->getDate()->get('Y-MM-dd'); break; case 'subYear': $toDate = $date->subDay($date->getDate()->get('D'))->getDate()->get('Y-MM-dd'); break; default: $toDate = $date->getDate()->get('Y-MM-dd'); } // end switch $subType = $SourceType; $unit = $SourceConfig['unit'] ? $SourceConfig['unit'] : 1; $fromDate = $date->{$subType}($unit)->getDate()->get('Y-MM-dd'); } // end else /** * Limit maximum product retrieve */ $limit = $SourceConfig['limitproduct']; if ($limit > 0 && ctype_digit($limit)) { $this->setProductsCount($limit); } $products = Mage::getResourceModel('reports/product_collection')->addOrderedQty($fromDate, $toDate)->addAttributeToSelect('*')->addAttributeToSelect(array('name', 'price', 'small_image'))->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('ordered_qty', 'desc'); // most best sellers on top Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products); $products->setPageSize($limit)->setCurPage(1); if (in_array($CategoryHandle, $HandleArray)) { $CategoryId = Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); $CategoryModel = Mage::getModel('catalog/category')->load($CategoryId); $products->addCategoryFilter($CategoryModel); } return $products; } // end if sourceconfig }
public function downloadAction() { $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout->disableLayout(); $request = $this->getRequest(); $start = $this->_helper->IdConvert->hexToStr($request->getParam('date_for')); $end = $this->_helper->IdConvert->hexToStr($request->getParam('date_to')); $date = new Zend_Date(); if (empty($start) || empty($end) || (!$date->setDate($start, "YYYY-MM-dd")->isDate($start, "YYYY-MM-dd") || !$date->setDate($end, "YYYY-MM-dd")->isDate($end, "YYYY-MM-dd"))) { $this->_helper->messenger()->error("Nie podano zakresu dat"); return $this->_helper->redirector('index'); } $logic = new Logic_Raports_Render($start, $end, $this->_helper->currentip()); $logic->render(); }
/** * */ public function listAvisos($curso) { try { $auth = Zend_Auth::getInstance(); $parameters = array('usuario' => $auth->getIdentity()->codigo, 'curso' => $curso); // Cria hash de comunicacao $parameters['hash'] = App_Util_Cenbrap::getHash($parameters, array('usuario', 'curso')); // Faz requisição para API $response = App_Util_Cenbrap::request('MuralAvisos', $parameters); if (empty($response['status'])) { throw new Exception('Erro ao listar mural de avisos'); } $avisos = array(); $date = new Zend_Date(); foreach ($response['avisos'] as $aviso) { if (!empty($aviso['data'])) { $date->setDate($aviso['data'], 'dd/MM/yyyy'); $avisos[$date->toString('yyyy-MM-dd')][] = $aviso; } } ksort($avisos); $avisos = array_reverse($avisos); return $avisos; } catch (Exception $e) { $this->_message->addMessage($e->getMessage(), App_Message::WARNING); return array(); } }
/** * * @return int|bool */ public function save() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $dataForm = $this->_data; $dataForm['client'] = array_keys($this->_data['cost_client']); $mapperRule = new Fefop_Model_Mapper_Rule(); $mapperRule->validate($this->_message, $dataForm, Fefop_Model_Mapper_Expense::CONFIG_PFPCI_FP); // If there is no contract yet if (empty($this->_data['fk_id_fefop_contract'])) { $dataContract = array('module' => Fefop_Model_Mapper_Module::FP, 'district' => $this->_data['fk_id_adddistrict']); $mapperFefopContract = new Fefop_Model_Mapper_Contract(); $this->_data['fk_id_fefop_contract'] = $mapperFefopContract->save($dataContract); } $this->_data['amount'] = App_General_String::toFloat($this->_data['amount']); $date = new Zend_Date(); $this->_data['date_start'] = $date->setDate($this->_data['start_date'])->toString('yyyy-MM-dd'); $this->_data['date_finish'] = $date->setDate($this->_data['finish_date'])->toString('yyyy-MM-dd'); $dataForm = $this->_data; // Save the contract $dataForm['id_fp_contract'] = parent::_simpleSave(); // Set the class to the Planning Course $dbPlanningCourse = App_Model_DbTable_Factory::get('FPPlanningCourse'); $row = $dbPlanningCourse->fetchRow(array('id_planning_course = ?' => $dataForm['fk_id_planning_course'])); $row->fk_id_fefpstudentclass = $dataForm['fk_id_fefpstudentclass']; $row->save(); // Save budget category $this->_saveBudgetCategory($dataForm); // Save the contract beneficiaries $this->_saveBeneficiaries($dataForm); if (empty($this->_data['id_fp_contract'])) { $history = 'REJISTU KONTRAKTU: %s BA ANNUAL PLANNING: %s'; } else { $history = 'ATUALIZA KONTRAKTU: %s BA ANNUAL PLANNING: %s'; } $history = sprintf($history, $dataForm['id_fp_contract'], $this->_data['fk_id_annual_planning']); $this->_sysAudit($history); $dbAdapter->commit(); return $dataForm['id_fp_contract']; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
public function indexAction() { $raportsModel = new Raports(); $request = $this->getRequest(); $hash = $request->getParam('hash'); if (empty($hash)) { return; } $raport = $raportsModel->getRaportByHash($hash); if ($raport === null) { return; } $start = $raport->date_for; $end = $raport->date_to; $date = new Zend_Date(); if (empty($start) || empty($end) || (!$date->setDate($start, "YYYY-MM-dd")->isDate($start, "YYYY-MM-dd") || !$date->setDate($end, "YYYY-MM-dd")->isDate($end, "YYYY-MM-dd"))) { return; } $logic = new Logic_Raports_Render($start, $end, $this->_helper->currentip()); $logic->render(); }
public function isValid($data) { $isValid = parent::isValid($data); if (!empty($data['date_for']) && !empty($data['date_to'])) { $date = new Zend_Date(); $date2 = clone $date; $date->setDate($data['date_for'], 'YYYY-MM-dd')->getTimestamp(); $date2->setDate($data['date_to'], 'YYYY-MM-dd')->getTimestamp(); if ($date->isLater($date2)) { $isValid = false; $this->getElement('date_to')->addError("Data do nie może być wcześniejsza niż data od"); } } return $isValid; }
public function baseInit() { $this->datee(false, 'date_for', "Data od:", true); $this->date_for->addValidator('Callback', false, array('callback' => function ($value) { $date = new Zend_Date(); $date->setDate($value, 'YYYY-MM-dd'); return $date->isEarlier(new Zend_date()) || $date->isToday(); }, 'messages' => array(Zend_Validate_Callback::INVALID_VALUE => "Data od nie może być datą przyszłą"))); $this->datee(false, 'date_to', "Data do:", true); $this->date_to->addValidator('Callback', false, array('callback' => function ($value) { $date = new Zend_Date(); $date->setDate($value, 'YYYY-MM-dd'); return $date->isEarlier(new Zend_date()) || $date->isToday(); }, 'messages' => array(Zend_Validate_Callback::INVALID_VALUE => "Data do nie może być datą przyszłą"))); $this->submit(false, 'create_raport', 'Generuj raport'); }
public function getPredefinedStartDate() { $_editableOptions = $this->getProduct()->getPreconfiguredValues(); if (isset($_editableOptions['aw_sarp_subscription_start'])) { $date = $_editableOptions['aw_sarp_subscription_start']; $zDate = new Zend_Date(); $zDate->setDate($date); $today = new Zend_Date(); $period = Mage::getModel('sarp/period')->load($_editableOptions['aw_sarp_subscription_type']); if ($zDate->compare($today, Zend_Date::DATE_SHORT) < 0 || !$period->isAllowedDate($zDate, $this->getProduct())) { $zDate = $period->getNearestAvailableDay(); } $date = $zDate->toString(preg_replace(array('/M+/', '/d+/'), array('MM', 'dd'), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); return $date; } return null; }
protected function _afterSave(Mage_Core_Model_Abstract $object) { //insert field values if (count($object->getData('field')) > 0) { foreach ($object->getData('field') as $field_id => $value) { if (is_array($value)) { $value = implode("\n", $value); } $field = Mage::getModel('webforms/fields')->load($field_id); if (strstr($field->getType(), 'date') && strlen($value) > 0) { $date = new Zend_Date(); $date->setDate($value, $field->getDateFormat(), Mage::app()->getLocale()->getLocaleCode()); if ($field->getType() == 'datetime') { $date->setTime($value, $field->getDateFormat(), Mage::app()->getLocale()->getLocaleCode()); } $value = date($field->getDbDateFormat(), $date->getTimestamp()); } if ($field->getType() == 'select/contact' && is_numeric($value)) { $value = $field->getContactValueById($value); } if ($value == $field->getHint()) { $value = ''; } // create key $key = ""; if ($field->getType() == 'file' || $field->getType() == 'image') { $key = Mage::helper('webforms')->randomAlphaNum(6); if ($object->getData('key_' . $field_id)) { $key = $object->getData('key_' . $field_id); } } $object->setData('key_' . $field_id, $key); $select = $this->_getReadAdapter()->select()->from($this->getTable('webforms/results_values'))->where('result_id = ?', $object->getId())->where('field_id = ?', $field_id); $result_value = $this->_getReadAdapter()->fetchAll($select); if (!empty($result_value[0])) { $this->_getWriteAdapter()->update($this->getTable('webforms/results_values'), array("value" => $value, "key" => $key), "id = " . $result_value[0]['id']); } else { $this->_getWriteAdapter()->insert($this->getTable('webforms/results_values'), array("result_id" => $object->getId(), "field_id" => $field_id, "value" => $value, "key" => $key)); } } } Mage::dispatchEvent('webforms_result_save', array('result' => $object)); return parent::_afterSave($object); }
/** * Sets the internal value to ISO date format, based on either a database value in ISO date format, * or a form submssion in the user date format. Uses the individual date and time fields * to take care of the actual formatting and value conversion. * * Value setting happens *before* validation, so we have to set the value even if its not valid. * * Caution: Only converts user timezones when value is passed as array data (= form submission). * Weak indication, but unfortunately the framework doesn't support a distinction between * setting a value from the database, application logic, and user input. * * @param string|array $val String expects an ISO date format. Array notation with 'date' and 'time' * keys can contain localized strings. If the 'dmyfields' option is used for {@link DateField}, * the 'date' value may contain array notation was well (see {@link DateField->setValue()}). */ function setValue($val) { // If timezones are enabled, assume user data needs to be reverted to server timezone if ($this->getConfig('usertimezone')) { // Accept user input on timezone, but only when timezone support is enabled $userTz = is_array($val) && array_key_exists('timezone', $val) ? $val['timezone'] : null; if (!$userTz) { $userTz = $this->getConfig('usertimezone'); } // fall back to defined timezone } else { $userTz = null; } if (empty($val)) { $this->value = null; $this->dateField->setValue(null); $this->timeField->setValue(null); } else { // Case 1: String setting from database, in ISO date format if (is_string($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) { $this->value = $val; } elseif (is_array($val) && array_key_exists('date', $val) && array_key_exists('time', $val)) { $dataTz = date_default_timezone_get(); // If timezones are enabled, assume user data needs to be converted to server timezone if ($userTz) { date_default_timezone_set($userTz); } // Uses sub-fields to temporarily write values and delegate dealing with their normalization, // actual sub-field value setting happens later $this->dateField->setValue($val['date']); $this->timeField->setValue($val['time']); if ($this->dateField->dataValue() && $this->timeField->dataValue()) { $userValueObj = new Zend_Date(null, null, $this->locale); $userValueObj->setDate($this->dateField->dataValue(), $this->dateField->getConfig('datavalueformat')); $userValueObj->setTime($this->timeField->dataValue(), $this->timeField->getConfig('datavalueformat')); if ($userTz) { $userValueObj->setTimezone($dataTz); } $this->value = $userValueObj->get($this->getConfig('datavalueformat'), $this->locale); unset($userValueObj); } else { // Validation happens later, so set the raw string in case Zend_Date doesn't accept it $this->value = sprintf($this->getConfig('datetimeorder'), $val['date'], $val['time']); } if ($userTz) { date_default_timezone_set($dataTz); } } else { $this->dateField->setValue($val); if (is_string($val)) { $this->timeField->setValue($val); } $this->value = $val; } // view settings (dates might differ from $this->value based on user timezone settings) if (Zend_Date::isDate($this->value, $this->getConfig('datavalueformat'), $this->locale)) { $valueObj = new Zend_Date($this->value, $this->getConfig('datavalueformat'), $this->locale); if ($userTz) { $valueObj->setTimezone($userTz); } // Set view values in sub-fields if ($this->dateField->getConfig('dmyfields')) { $this->dateField->setValue($valueObj->toArray()); } else { $this->dateField->setValue($valueObj->get($this->dateField->getConfig('dateformat'), $this->locale)); } $this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat'), $this->locale)); } } }
/** * @ZF-7589 */ public function testSetDateWithArray() { $date = new Zend_Date(1234567890); $result = $date->setDate(array('year' => 2009, 'month' => 8, 'day' => 14)); $this->assertSame('2009-08-14T04:31:30+05:00', $result->get(Zend_Date::W3C)); }
protected function _afterSave() { if (!Mage::helper('customoptions')->isEnabled() || Mage::app()->getRequest()->getControllerName() != 'catalog_product' && Mage::app()->getRequest()->getControllerName() != 'adminhtml_catalog_product') { return parent::_afterSave(); } $optionId = $this->getData('option_id'); $defaultArray = $this->getData('default') ? $this->getData('default') : array(); $tablePrefix = (string) Mage::getConfig()->getTablePrefix(); $connection = Mage::getSingleton('core/resource')->getConnection('core_write'); $helper = Mage::helper('customoptions'); $storeId = $this->getProduct()->getStoreId(); if (is_array($this->getData('values'))) { $values = array(); foreach ($this->getData('values') as $key => $value) { if (isset($value['option_type_id'])) { if (isset($value['dependent_ids']) && $value['dependent_ids'] != '') { $dependentIds = array(); $dependentIdsTmp = explode(',', $value['dependent_ids']); foreach ($dependentIdsTmp as $d_id) { if ($this->decodeViewIGI($d_id) > 0) { $dependentIds[] = $this->decodeViewIGI($d_id); } } $value['dependent_ids'] = implode(',', $dependentIds); } $value['sku'] = trim($value['sku']); // prepare customoptions_qty $customoptionsQty = ''; if (isset($value['customoptions_qty']) && (!$helper->isSkuQtyLinkingEnabled() || $helper->getProductIdBySku($value['sku']) == 0)) { $customoptionsQty = strtolower(trim($value['customoptions_qty'])); if (substr($customoptionsQty, 0, 1) != 'x' && substr($customoptionsQty, 0, 1) != 'i' && substr($customoptionsQty, 0, 1) != 'l' && !is_numeric($customoptionsQty)) { $customoptionsQty = ''; } if (is_numeric($customoptionsQty)) { $customoptionsQty = intval($customoptionsQty); } if (substr($customoptionsQty, 0, 1) == 'i') { $customoptionsQty = $this->decodeViewIGI($customoptionsQty); } } $optionValue = array('option_id' => $optionId, 'sku' => $value['sku'], 'sort_order' => $value['sort_order'], 'customoptions_qty' => $customoptionsQty, 'default' => array_search($key, $defaultArray) !== false ? 1 : 0, 'in_group_id' => $value['in_group_id']); if (isset($value['dependent_ids'])) { $optionValue['dependent_ids'] = $value['dependent_ids']; } if (isset($value['weight'])) { $optionValue['weight'] = $value['weight']; } if (isset($value['cost'])) { $optionValue['cost'] = $value['cost']; } $optionTypePriceId = 0; if ($helper->isSkuNameLinkingEnabled() && (!isset($value['scope']['title']) || $value['scope']['title'] != 1) && (!isset($value['title']) || $value['title'] == '') && $value['sku']) { $value['title'] = $helper->getProductNameBySku($value['sku'], $storeId); } if (isset($value['option_type_id']) && $value['option_type_id'] > 0) { $optionTypeId = $value['option_type_id']; if ($value['is_delete'] == '1') { $connection->delete($tablePrefix . 'catalog_product_option_type_value', 'option_type_id = ' . $optionTypeId); $helper->deleteOptionFile(null, $optionId, $optionTypeId); } else { $connection->update($tablePrefix . 'catalog_product_option_type_value', $optionValue, 'option_type_id = ' . $optionTypeId); // update or insert price $select = $connection->select()->from($tablePrefix . 'catalog_product_option_type_price', array('option_type_price_id'))->where('option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); $optionTypePriceId = $isUpdate = $connection->fetchOne($select); if (isset($value['price']) && isset($value['price_type'])) { $priceValue = array('price' => $value['price'], 'price_type' => $value['price_type']); if ($isUpdate) { $connection->update($tablePrefix . 'catalog_product_option_type_price', $priceValue, 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); } else { $priceValue['option_type_id'] = $optionTypeId; $priceValue['store_id'] = $storeId; $connection->insert($tablePrefix . 'catalog_product_option_type_price', $priceValue); $optionTypePriceId = $connection->lastInsertId($tablePrefix . 'catalog_product_option_type_price'); } } elseif (isset($value['scope']['price']) && $value['scope']['price'] == 1 && $isUpdate && $storeId > 0) { $connection->delete($tablePrefix . 'catalog_product_option_type_price', 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); $optionTypePriceId = -1; } // update or insert title if ($storeId > 0) { $select = $connection->select()->from($tablePrefix . 'catalog_product_option_type_title', array('COUNT(*)'))->where('option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); $isUpdate = $connection->fetchOne($select); } else { $isUpdate = 1; } if (isset($value['title'])) { if ($isUpdate) { $connection->update($tablePrefix . 'catalog_product_option_type_title', array('title' => $value['title']), 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); } else { $connection->insert($tablePrefix . 'catalog_product_option_type_title', array('option_type_id' => $optionTypeId, 'store_id' => $storeId, 'title' => $value['title'])); } } elseif (isset($value['scope']['title']) && $value['scope']['title'] == 1 && $isUpdate && $storeId > 0) { $connection->delete($tablePrefix . 'catalog_product_option_type_title', 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); } // update or insert description if (isset($value['description']) || isset($value['scope']['description'])) { $select = $connection->select()->from($tablePrefix . 'custom_options_option_type_description', array('COUNT(*)'))->where('option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); $isUpdate = $connection->fetchOne($select); } if (isset($value['description']) && $value['description'] != '') { if ($isUpdate) { $connection->update($tablePrefix . 'custom_options_option_type_description', array('description' => $value['description']), 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); } else { $connection->insert($tablePrefix . 'custom_options_option_type_description', array('option_type_id' => $optionTypeId, 'store_id' => $storeId, 'description' => $value['description'])); } } elseif (isset($value['scope']['description']) && $value['scope']['description'] == 1 && $isUpdate && $storeId > 0 || isset($value['description']) && $value['description'] == '') { $connection->delete($tablePrefix . 'custom_options_option_type_description', 'option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); } } } else { if ($value['is_delete'] == '1') { continue; } $connection->insert($tablePrefix . 'catalog_product_option_type_value', $optionValue); $optionTypeId = $connection->lastInsertId($tablePrefix . 'catalog_product_option_type_value'); if (isset($value['price']) && isset($value['price_type'])) { // save not default //if ($storeId>0) $connection->insert($tablePrefix . 'catalog_product_option_type_price', array('option_type_id' =>$optionTypeId, 'store_id'=>$storeId, 'price' => $value['price'], 'price_type' => $value['price_type'])); // save default $connection->insert($tablePrefix . 'catalog_product_option_type_price', array('option_type_id' => $optionTypeId, 'store_id' => 0, 'price' => $value['price'], 'price_type' => $value['price_type'])); $optionTypePriceId = $connection->lastInsertId($tablePrefix . 'catalog_product_option_type_price'); } if (isset($value['title'])) { // save default $connection->insert($tablePrefix . 'catalog_product_option_type_title', array('option_type_id' => $optionTypeId, 'store_id' => 0, 'title' => $value['title'])); } if (isset($value['description']) && $value['description'] != '') { // save default $connection->insert($tablePrefix . 'custom_options_option_type_description', array('option_type_id' => $optionTypeId, 'store_id' => 0, 'description' => $value['description'])); } } if ($optionTypeId > 0 && $optionTypePriceId >= 0) { $id = $this->getData('id'); $this->_uploadImage('file_' . $id . '_' . $key, $optionId, $optionTypeId, $value); // check $optionTypePriceId if ($optionTypePriceId == 0) { $select = $connection->select()->from($tablePrefix . 'catalog_product_option_type_price', array('option_type_price_id'))->where('option_type_id = ' . $optionTypeId . ' AND `store_id` = ' . $storeId); $optionTypePriceId = $isUpdate = $connection->fetchOne($select); } if ($optionTypePriceId) { // save special prices if (isset($value['specials']) && is_array($value['specials'])) { $specials = array(); foreach ($value['specials'] as $special) { if ($special['is_delete'] == '1' || isset($specials[$special['customer_group_id']])) { if ($special['special_price_id'] > 0) { $connection->delete($tablePrefix . 'custom_options_option_type_special_price', 'option_type_special_price_id = ' . intval($special['special_price_id'])); } continue; } $specials[$special['customer_group_id']] = $special; } if (count($specials) > 0) { foreach ($specials as $special) { $zendDate = new Zend_Date(); $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); if ($special['date_from']) { $special['date_from'] = $zendDate->setDate($special['date_from'], $dateFormat)->toString(Varien_Date::DATE_INTERNAL_FORMAT); } else { $special['date_from'] = null; } if ($special['date_to']) { $special['date_to'] = $zendDate->setDate($special['date_to'], $dateFormat)->toString(Varien_Date::DATE_INTERNAL_FORMAT); } else { $special['date_to'] = null; } $specialData = array('option_type_price_id' => $optionTypePriceId, 'customer_group_id' => $special['customer_group_id'], 'price' => floatval($special['price']), 'price_type' => $special['price_type'], 'comment' => trim($special['comment']), 'date_from' => $special['date_from'], 'date_to' => $special['date_to']); if ($special['special_price_id'] > 0) { $connection->update($tablePrefix . 'custom_options_option_type_special_price', $specialData, 'option_type_special_price_id = ' . intval($special['special_price_id'])); } else { $connection->insert($tablePrefix . 'custom_options_option_type_special_price', $specialData); } } } } // save tier prices if (isset($value['tiers']) && is_array($value['tiers'])) { $tiers = array(); foreach ($value['tiers'] as $tier) { $uniqKey = $tier['qty'] . '+' . $tier['customer_group_id']; if ($tier['is_delete'] == '1' || isset($tiers[$uniqKey])) { if ($tier['tier_price_id'] > 0) { $connection->delete($tablePrefix . 'custom_options_option_type_tier_price', 'option_type_tier_price_id = ' . intval($tier['tier_price_id'])); } continue; } $tiers[$uniqKey] = $tier; } if (count($tiers) > 0) { foreach ($tiers as $tier) { $tierData = array('option_type_price_id' => $optionTypePriceId, 'customer_group_id' => $tier['customer_group_id'], 'qty' => intval($tier['qty']), 'price' => floatval($tier['price']), 'price_type' => $tier['price_type']); if ($tier['tier_price_id'] > 0) { $connection->update($tablePrefix . 'custom_options_option_type_tier_price', $tierData, 'option_type_tier_price_id = ' . intval($tier['tier_price_id'])); } else { $connection->insert($tablePrefix . 'custom_options_option_type_tier_price', $tierData); } } } } } } unset($value['option_type_id']); } $values[$key] = $value; } $this->setData('values', $values); } elseif ($this->getGroupByType($this->getType()) == self::OPTION_GROUP_SELECT) { Mage::throwException(Mage::helper('catalog')->__('Select type options required values rows.')); } if (version_compare($helper->getMagetoVersion(), '1.4.0', '>=')) { $this->cleanModelCache(); } Mage::dispatchEvent('model_save_after', array('object' => $this)); if (version_compare($helper->getMagetoVersion(), '1.4.0', '>=')) { Mage::dispatchEvent($this->_eventPrefix . '_save_after', $this->_getEventData()); } return $this; }
/** * Test for setDate */ public function testSetDate() { $locale = new Zend_Locale('de_AT'); $date = new Zend_Date(1234567890, null, $locale); $d2 = new Zend_Date(1234567899, null, $locale); $result = $date->setDate(Zend_Date::now()); $this->assertTrue($result instanceof Zend_Date); $result = $date->setDate('11.05.2008'); $this->assertSame($result->get(Zend_Date::W3C), '2008-04-11T00:31:30+02:00'); $this->assertSame($date->get(Zend_Date::W3C), '2008-04-11T00:31:30+02:00'); $date->setDate('2008-05-11', 'YYYY-MM-dd'); $this->assertSame($date->get(Zend_Date::W3C), '2008-04-11T00:31:30+02:00'); $date->setDate($d2); $this->assertSame($date->get(Zend_Date::W3C), '2009-02-14T00:31:30+01:00'); }
/** * test looseBehaviour */ public function testLoose() { $date = new Zend_Date(0, 'de'); try { $date->set(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set(10, 'de'); $this->assertEquals($date->getTimestamp(), 10); try { $date->add(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->add(10, 'de'); $this->assertEquals($date->getTimestamp(), 20); try { $date->sub(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->sub(10, 'de'); $this->assertEquals($date->getTimestamp(), 10); try { $date->compare(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->equals(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->isEarlier(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->isLater(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } }
/** * 取得某个预定义时间段 * * @static * @param integer $interval * @param string $forceUnit * @param integer $timestamp * @return array */ public static function getPredefinedRange($interval, $forceUnit = null, $timestamp = null) { if (empty($timestamp)) { $timestamp = time(); } $start = new Zend_Date($timestamp); $end = new Zend_Date($timestamp); switch ($interval) { case self::TODAY: $start->setHour(0)->setMinute(0)->setSecond(0); $unit = Zend_Date::HOUR; break; case self::YESTODAY: $start->subDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end = clone $start; $end->addDay(1); $unit = Zend_Date::HOUR; break; case self::TOMORROW: $start->addDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end = clone $start; $end->addDay(1); $unit = Zend_Date::HOUR; break; case self::THIS_MONTH: $start->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $unit = Zend_Date::DAY; break; case self::THIS_YEAR: $start->setMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end->addMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $unit = Zend_Date::DAY; break; case self::THIS_SEASON: $start->setMonth(3 * floor(($start->toValue('M') - 1) / 3) + 1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $unit = Zend_Date::DAY; case self::RECENT_24HOUR: $start->subHour(24); $unit = Zend_Date::HOUR; break; case self::RECENT_48HOUR: $start->subHour(48); $unit = Zend_Date::HOUR; break; case self::RECENT_1WEEK: $start->subWeek(1); $unit = Zend_Date::DAY; break; case self::RECENT_1MONTH: $start->subMonth(1); $unit = Zend_Date::DAY; break; case self::RECENT_24MONTH: $start->subMonth(24); $unit = Zend_Date::DAY; break; case self::LAST_1MONTH: $start->subMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end = clone $start; $end->addMonth(1); $unit = Zend_Date::DAY; break; case self::LAST_1YEAR: $start->subYear(1)->setMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end = clone $start; $end->addYear(1); $unit = Zend_Date::DAY; break; case self::ENTIRE_DAY: $start->setDate(self::ERA_DATE, self::ZF_DATE_FORMAT)->setTime(self::ERA_TIME, self::ZF_TIME_FORMAT); $end->addDay(1); $unit = Zend_Date::DAY; break; default: $unit = Zend_Date::SECOND; } if (!empty($forceUnit)) { $unit = $forceUnit; } $start = max(self::truncateDatetime($start, $unit), self::truncateDatetime(self::ERA_DATETIME, $unit)); $end = max(self::truncateDatetime($end, $unit), self::truncateDatetime(self::ERA_DATETIME, $unit)); return compact('start', 'end', 'unit'); }
protected function mapDirectiveSalePriceEffectiveDate($params = array()) { $map = $params['map']; $product = $this->getProduct(); /* @var $product Mage_Catalog_Model_Product */ $cell = ""; if (!$this->hasSpecialPrice()) { return $cell; } $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()); $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE); $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $fromDate->setTimezone($timezone); } $fromDate->setDate(substr($product->getSpecialFromDate(), 0, 10), 'yyyy-MM-dd'); $fromDate->setTime(substr($product->getSpecialFromDate(), 11, 8), 'HH:mm:ss'); $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if (!is_empty_date($product->getSpecialToDate())) { if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate(substr($product->getSpecialToDate(), 0, 10), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); } else { if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); $toDate->add(7, Zend_Date::DAY); } $cell = $fromDate->toString(Zend_Date::ISO_8601) . "/" . $toDate->toString(Zend_Date::ISO_8601); return $cell; }
public function getOptionValues() { $optionsCollection = $this->getProduct()->getOptions(); // if option enabled = no && hasOptions = 0 if (!$optionsCollection) { $optionsCollection = $this->getProduct()->getProductOptionsCollection(); } $zendDate = new Zend_Date(); $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); if (!$this->_values) { $values = array(); $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); $helper = Mage::helper('customoptions'); foreach ($optionsCollection as $option) { /* @var $option Mage_Catalog_Model_Product_Option */ $this->setItemCount($option->getOptionId()); $value = array(); $value['id'] = $option->getOptionId(); $value['template_title'] = $option->getGroupTitle() ? $helper->__('Options Template:') . ' ' . $option->getGroupTitle() : ''; $value['item_count'] = $this->getItemCount(); $value['option_id'] = $option->getOptionId(); $value['title'] = $this->htmlEscape($option->getTitle()); $value['type'] = $option->getType(); $value['is_require'] = $option->getIsRequire(true); $value['view_mode'] = $option->getViewMode(); $value['is_dependent'] = $option->getIsDependent(); $value['div_class'] = $option->getDivClass(); $value['sku_policy'] = $option->getSkuPolicy(); $value['customoptions_is_onetime'] = $option->getCustomoptionsIsOnetime(); $value['qnty_input'] = $option->getQntyInput() ? 'checked' : ''; $value['qnty_input_disabled'] = $option->getType() == 'multiple' || $option->getType() == 'hidden' ? 'disabled' : ''; $value['image_mode'] = $option->getImageMode(); $value['image_mode_disabled'] = $option->getGroupByType() != Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT ? 'disabled' : ''; $value['exclude_first_image'] = $option->getExcludeFirstImage() ? 'checked' : ''; $value['sort_order'] = $option->getSortOrder(); $value['image_button_label'] = $option->getImagePath() ? $helper->__('Change Image') : $helper->__('Add Image'); $value['description'] = $this->htmlEscape($option->getDescription()); if ($helper->isCustomerGroupsEnabled() && $option->getCustomerGroups() != null) { $value['customer_groups'] = $option->getCustomerGroups(); } if ($helper->isStoreViewsEnabled() && $option->getStoreViews() != null) { $value['store_views'] = $option->getStoreViews(); } $value['in_group_id'] = $option->getInGroupId(); $value['in_group_id_view'] = $this->getViewIGI($option->getInGroupId()); if ($this->getProduct()->getStoreId() != '0') { $value['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', is_null($option->getStoreTitle())); $value['scopeTitleDisabled'] = is_null($option->getStoreTitle()) ? 'disabled' : null; $value['checkboxScopeViewMode'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'view_mode', is_null($option->getStoreViewMode())); $value['scopeViewModeDisabled'] = is_null($option->getStoreViewMode()) ? 'disabled' : null; $value['checkboxScopeDescription'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'description', is_null($option->getStoreDescription())); $value['scopeDescriptionDisabled'] = is_null($option->getStoreDescription()) ? 'disabled' : null; } $connection = Mage::getSingleton('core/resource')->getConnection('core_write'); $tablePrefix = (string) Mage::getConfig()->getTablePrefix(); $select = $connection->select()->from($tablePrefix . 'custom_options_relation')->where('option_id = ' . $option->getOptionId()); $relation = $connection->fetchRow($select); if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) { $i = 0; $itemCount = 0; foreach ($option->getValues() as $_value) { /* @var $_value Mage_Catalog_Model_Product_Option_Value */ $dependentIds = array(); $dependentIdsTmp = explode(',', $_value->getDependentIds()); foreach ($dependentIdsTmp as $d_id) { $dependentIds[] = $this->getViewIGI($d_id); } $priceDisabled = $_value->getIsSkuPrice(); list($skuClass, $viewProductBySkuHtml) = $this->getViewSkuData($_value->getSku()); if (!$helper->isSkuQtyLinkingEnabled() || $helper->getProductIdBySku($_value->getSku()) == 0) { $customoptionsQty = $_value->getCustomoptionsQty(); } else { list($customoptionsQty, $backorders) = $helper->getCustomoptionsQty($_value->getCustomoptionsQty(), $_value->getSku(), 0, null, null, null, true); } $value['optionValues'][$i] = array('item_count' => max($itemCount, $_value->getOptionTypeId()), 'option_id' => $_value->getOptionId(), 'option_type_id' => $_value->getOptionTypeId(), 'title' => $this->htmlEscape($_value->getTitle()), 'price' => $this->getPriceValue($_value->getPrice(), $_value->getPriceType()), 'price_type' => $_value->getPriceType(), 'price_disabled' => $priceDisabled, 'description' => $this->htmlEscape($_value->getDescription()), 'cost' => $this->getPriceValue($_value->getCost(), 'fixed'), 'cost_disabled' => $_value->getIsSkuCost() ? 'disabled' : '', 'customoptions_qty' => $this->getViewQty($customoptionsQty), 'customoptions_qty_disabled' => $helper->isSkuQtyLinkingEnabled() && $helper->getProductIdBySku($_value->getSku()) ? 'disabled="disabled"' : '', 'sku' => $this->htmlEscape($_value->getSku()), 'sku_class' => $skuClass, 'view_product_by_sku_html' => $viewProductBySkuHtml, 'image_button_label' => $helper->__('Add Image'), 'sort_order' => $_value->getSortOrder(), 'checked' => $_value->getDefault() != 0 ? 'checked' : '', 'default_type' => $option->getType() == 'checkbox' || $option->getType() == 'multiple' || $option->getType() == 'multiswatch' || $option->getType() == 'hidden' ? 'checkbox' : 'radio', 'in_group_id' => $_value->getInGroupId(), 'in_group_id_view' => $this->getViewIGI($_value->getInGroupId()), 'dependent_ids' => implode(',', $dependentIds), 'weight' => $_value->getWeight(), 'weight_disabled' => $_value->getIsSkuWeight() ? 'disabled' : ''); // getImages $images = $_value->getImages(); if ($images) { foreach ($images as $image) { if ($image['source'] == 1) { // file $imgArr = $helper->getImgData($image['image_file'], $option->getId(), $_value->getOptionTypeId()); if ($imgArr) { $imgArr['option_type_image_id'] = $image['option_type_image_id']; $value['optionValues'][$i]['images'][] = $imgArr; } } elseif ($image['source'] == 2) { // color $colorArr = $image; $colorArr['id'] = $option->getId(); $colorArr['select_id'] = $_value->getOptionTypeId(); $value['optionValues'][$i]['images'][] = $colorArr; } } } else { $value['optionValues'][$i]['image_tr_style'] = 'display:none'; } //getOptionValueSpecialPrices $specialPrices = $_value->getSpecials(); if ($specialPrices) { foreach ($specialPrices as $specialKey => $specialPrice) { $specialPrices[$specialKey]['price'] = $this->getPriceValue($specialPrice['price'], $specialPrice['price_type']); if ($specialPrice['date_from']) { $specialPrices[$specialKey]['date_from'] = $zendDate->setDate($specialPrice['date_from'], Varien_Date::DATE_INTERNAL_FORMAT)->toString($dateFormat); } if ($specialPrice['date_to']) { $specialPrices[$specialKey]['date_to'] = $zendDate->setDate($specialPrice['date_to'], Varien_Date::DATE_INTERNAL_FORMAT)->toString($dateFormat); } } $value['optionValues'][$i]['specials'] = $specialPrices; } //getOptionValueTierPrices $tierPrices = $_value->getTiers(); if ($tierPrices) { foreach ($tierPrices as $tierKey => $tierPrice) { $tierPrices[$tierKey]['price'] = $this->getPriceValue($tierPrice['price'], $tierPrice['price_type']); } $value['optionValues'][$i]['tiers'] = $tierPrices; } if ($this->getProduct()->getStoreId() != '0') { $value['optionValues'][$i]['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($_value->getOptionId(), 'title', is_null($_value->getStoreTitle()), $_value->getOptionTypeId()); $value['optionValues'][$i]['scopeTitleDisabled'] = is_null($_value->getStoreTitle()) ? 'disabled' : null; $value['optionValues'][$i]['checkboxScopeDescription'] = $this->getCheckboxScopeHtml($_value->getOptionId(), 'description', is_null($_value->getStoreDescription()), $_value->getOptionTypeId()); $value['optionValues'][$i]['scopeDescriptionDisabled'] = is_null($_value->getStoreDescription()) ? 'disabled' : null; //if ($scope==Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) { if (!$priceDisabled) { $value['optionValues'][$i]['checkboxScopePrice'] = $this->getCheckboxScopeHtml($_value->getOptionId(), 'price', is_null($_value->getStorePrice()), $_value->getOptionTypeId()); } $value['optionValues'][$i]['scopePriceDisabled'] = is_null($_value->getStorePrice()) ? 'disabled' : null; //} } $i++; } } else { $priceDisabled = $option->getIsSkuPrice(); list($skuClass, $viewProductBySkuHtml) = $this->getViewSkuData($option->getSku()); $value['price'] = $this->getPriceValue($option->getPrice(), $option->getPriceType()); $value['price_type'] = $option->getPriceType(); $value['price_disabled'] = $priceDisabled; $value['sku'] = $this->htmlEscape($option->getSku()); $value['sku_class'] = $skuClass; $value['view_product_by_sku_html'] = $viewProductBySkuHtml; $value['max_characters'] = $option->getMaxCharacters(); $value['default_text'] = $this->htmlEscape($option->getDefaultText()); $value['file_extension'] = $option->getFileExtension(); $value['image_size_x'] = $option->getImageSizeX(); $value['image_size_y'] = $option->getImageSizeY(); $imgHtml = $helper->getImgHtml($helper->getImgData($option->getImagePath(), $option->getId())); if ($imgHtml) { $value['image'] = $imgHtml; } if ($this->getProduct()->getStoreId() != '0') { // && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE if (!$priceDisabled) { $value['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', is_null($option->getStorePrice())); } $value['scopePriceDisabled'] = is_null($option->getStorePrice()) ? 'disabled' : null; $value['checkboxScopeDefaultText'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'default_text', is_null($option->getStoreDefaultText())); $value['scopeDefaultTextDisabled'] = is_null($option->getStoreDefaultText()) ? 'disabled' : null; } } $values[] = new Varien_Object($value); } $this->_values = $values; } return $this->_values; }
public function insert(array $data) { $periodStaus = self::periodStatus($data['period_id'], true); if ('FULL' != $periodStaus['STATUS']) { if ('PARTIAL' == $periodStaus['STATUS']) { if ('ALL' === strtoupper($data['group_id'])) { throw new Zend_Exception('Period status is ' . $periodStaus['STATUS'] . '. ' . $data['group_id'] . ' groups can not be placed.', Zend_Log::WARN); } //TODO More strict check can also be implemented (It is still having some holes but hard to detect, I dont want to correct that because frontend covers that problem.). /* self::getLogger()->log('Future partial period!! Do something.', Zend_Log::DEBUG); $errVar = ''; foreach ($periodStaus['periodStatus'] as $key => $value) { $errVar .= "[$key] ::".var_export($value, true); } self::getLogger()->log('Future partial period. Attempt: '.var_export($data, true).' Actual: '.$errVar, Zend_Log::DEBUG); */ } //TODO Include Block and Rooms $data['block_id'] = 'ADM_B1'; $data['room_id'] = '1'; $periodsCovered = $data['period']; for ($i = 1; $i < $data['period_duration']; ++$i) { $nextPeriod = $data['period'] + $i; $periodsCovered .= ',' . $nextPeriod; } $data['periods_covered'] = $periodsCovered; $date = new Zend_Date(); $date->setDate($data['valid_from'], 'dd/MM/YYYY'); $data['valid_from'] = $date->toString('YYYY-MM-dd'); $data['valid_upto'] = Acad_Model_DbTable_AcademicSession::getSessionEndDate(); $currentPeriodStatus = self::currentPeriodStatus($data['period_id'], TRUE); self::getDefaultAdapter()->beginTransaction(); if ($currentPeriodStatus['STATUS'] != 'EMPTY') { self::updateCurrentValidity($currentPeriodStatus, $data['group_id'], $data['valid_from'], $data['periods_covered']); } unset($data['period']); unset($data['degree_id']); unset($data['semester_id']); unset($data['weekday_number']); self::getLogger()->log('Final data for insert', Zend_Log::INFO); self::getLogger()->log($data, Zend_Log::DEBUG); //Strange but NULL values are being accepted by MySQL(at least my server even in NOT NULL condition) //so im crossing checking null values foreach ($data as $column => $value) { if (!$value) { self::getDefaultAdapter()->rollBack(); throw new Zend_Exception($column . ' should have some value.', Zend_Log::ERR); } } $newID = parent::insert($data); self::getDefaultAdapter()->commit(); return $newID; } else { $errVar = ''; foreach ($periodStaus['periodStatus'] as $key => $value) { $errVar .= "[{$key}] ::" . var_export($value, true); } throw new Zend_Exception('Future period entry confliction. Attempt: ' . var_export($data, true) . ' Actual: ' . $errVar, Zend_Log::WARN); } }
/** * Returns the difference in days between to dates. * @param mixed $from The start date/time representation (one of the values accepted by toZendDate) * @param mixed $to The end date/time representation (one of the values accepted by toZendDate) * @param string $timezone The timezone to set. Special values are:<ul> * <li>'system' for the current system timezone</li> * <li>'user' (default) for the user's timezone</li> * <li>'app' for the app's timezone</li> * <li>Other values: one of the PHP supported time zones (see http://us1.php.net/manual/en/timezones.php )</li> * </ul> * @return int|null Returns the difference in days (less than zero if $dateFrom if greater than $dateTo). * Returns null if one of both the dates can't be parsed. */ public function getDeltaDays($from, $to, $timezone = 'user') { $zendFrom = $this->toZendDate($from, $timezone); $zendTo = $this->toZendDate($to, $timezone); if (is_null($zendFrom) || is_null($zendTo)) { return null; } $zendFromUTC = new Zend_Date(); $zendToUTC = new Zend_Date(); $zendFromUTC->setTimezone('GMT'); $zendToUTC->setTimezone('GMT'); $zendFromUTC->setDate($zendFrom->toString('Y-m-d'), 'Y-m-d'); $zendToUTC->setDate($zendTo->toString('Y-m-d'), 'Y-m-d'); $zendToUTC->sub($zendFromUTC); return round($zendToUTC->getTimestamp() / 86400); }
protected function _saveOrder($data) { $fieldNoEnc = array('customers_id', 'orders_id', 'date_purchased', 'last_modified', 'orders_date_finished', 'orders_products_id', 'osc_magento_id', 'products_id'); $importModel = $this->getImportModel(); $timezone = $importModel->getTimezone(); $customerIdPair = $this->getCustomerIdPair(); $importId = $importModel->getId(); $websiteId = $this->getWebsiteModel()->getId(); if ($data['customers_id'] > 0 && isset($this->_customerIdPair[$data['customers_id']])) { foreach ($data as $field => $value) { if (!in_array($field, $fieldNoEnc)) { $data[$field] = $this->convert($value); } } if ($data['date_purchased']) { $preparePurchased = explode(' ', $data['date_purchased']); $dateFormat = 'YYYY-MM-dd HH:mm:ss'; $datePurchased = new Zend_Date(); $datePurchased->setTimezone($timezone); $datePurchased->setDate($preparePurchased[0], 'YYYY-MM-dd'); $datePurchased->setTime($preparePurchased[1], 'HH:mm:ss'); $datePurchased->setTimezone('GMT'); $data['date_purchased'] = $datePurchased->toString($dateFormat); } if ($data['last_modified']) { $prepareModified = explode(' ', $data['last_modified']); $dateModified = new Zend_Date(); $dateModified->setTimezone($timezone); $dateModified->setDate($prepareModified[0], 'YYYY-MM-dd'); $dateModified->setTime($prepareModified[1], 'HH:mm:ss'); $dateModified->setTimezone('GMT'); $data['last_modified'] = $dateModified->toString($dateFormat); } if ($data['orders_date_finished']) { $prepareFinished = explode(' ', $data['orders_date_finished']); $dateFinished = new Zend_Date(); $dateFinished->setTimezone($timezone); $dateFinished->setDate($prepareFinished[0], 'YYYY-MM-dd'); $dateFinished->setTime($prepareFinished[1], 'HH:mm:ss'); $dateFinished->setTimezone('GMT'); $data['orders_date_finished'] = $dateFinished->toString($dateFormat); } $data['magento_customers_id'] = $this->_customerIdPair[$data['customers_id']]; // get Magento CustomerId $data['import_id'] = $importId; $data['website_id'] = $websiteId; $data['orders_status'] = $data['orders_status_name']; unset($data['orders_status_name']); $this->_getWriteAdapter()->insert($this->getTable('oscommerce_order'), $data); $oscMagentoId = $this->_getWriteAdapter()->lastInsertId(); $this->_saveRows++; // Get orders products $select = "SELECT `orders_products_id`, `orders_id`, `products_id` "; $select .= ", `products_model`, `products_name`, `products_price`, `final_price` "; $select .= ", `products_tax`, `products_quantity` "; $select .= " FROM `{$this->getOscTable('orders_products')}` WHERE `orders_id`={$data['orders_id']}"; if ($orderProducts = $this->_getForeignAdapter()->fetchAll($select)) { foreach ($orderProducts as $orderProduct) { unset($orderProduct['orders_id']); unset($orderProduct['orders_products_id']); $orderProduct['osc_magento_id'] = $oscMagentoId; foreach ($orderProduct as $field => $value) { if (!in_array($field, $fieldNoEnc)) { $orderProduct[$field] = $this->convert($value); } } $this->_getWriteAdapter()->insert($this->getTable('oscommerce_order_products'), $orderProduct); } } // Get orders totals $select = "SELECT `orders_total_id`, `orders_id`, `title`, `text`, `value`, `class`, `sort_order` "; $select .= " FROM `{$this->getOscTable('orders_total')}` WHERE `orders_id`={$data['orders_id']} ORDER BY `sort_order`"; if ($orderTotals = $this->_getForeignAdapter()->fetchAll($select)) { foreach ($orderTotals as $orderTotal) { unset($orderTotal['orders_id']); unset($orderTotal['orders_total_id']); $orderTotal['osc_magento_id'] = $oscMagentoId; $orderTotal['title'] = $this->convert($orderTotal['title']); $orderTotal['text'] = $this->convert($orderTotal['text']); $this->_getWriteAdapter()->insert($this->getTable('oscommerce_order_total'), $orderTotal); } } $defaultLanguage = $this->getOscDefaultLanguage(); $defaultLanguageId = $defaultLanguage['id']; // Get orders status history $select = "SELECT `osh`.`orders_status_history_id`, `osh`.`orders_id`, `osh`.`orders_status_id` "; $select .= ", `os`.`orders_status_name` `orders_status`, `osh`.`date_added`, `osh`.`customer_notified`, `osh`.`comments` "; $select .= " FROM `{$this->getOscTable('orders_status_history')}` osh "; $select .= " LEFT JOIN `{$this->getOscTable('orders_status')}` os ON `os`.`orders_status_id`=`osh`.`orders_status_id` "; $select .= " AND `os`.`language_id`={$defaultLanguageId}"; $select .= " WHERE `osh`.`orders_id`={$data['orders_id']}"; if ($orderHistories = $this->_getForeignAdapter()->fetchAll($select)) { foreach ($orderHistories as $orderHistory) { unset($orderHistory['orders_id']); unset($orderHistory['orders_status_history_id']); $orderHistory['osc_magento_id'] = $oscMagentoId; $prepareAdded = explode(' ', $orderHistory['date_added']); $dateFormat = 'YYYY-MM-dd HH:mm:ss'; $dateAdded = new Zend_Date(); $dateAdded->setTimezone($timezone); $dateAdded->setDate($prepareAdded[0], 'YYYY-MM-dd'); $dateAdded->setTime($prepareAdded[1], 'HH:mm:ss'); $dateAdded->setTimezone('GMT'); $orderHistory['date_added'] = $dateAdded->toString($dateFormat); $orderHistory['orders_status'] = $this->convert($orderHistory['orders_status']); $orderHistory['comments'] = $this->convert($orderHistory['comments']); $orderHistory['customer_notified'] = $this->convert($orderHistory['customer_notified']); $this->_getWriteAdapter()->insert($this->getTable('oscommerce_order_history'), $orderHistory); } } } else { $this->_addErrors(Mage::helper('oscommerce')->__('Order #%s failed to import because the customer ID #%s associated with this order could not be found.', $data['orders_id'], $data['customers_id'])); } }
/** * @param $product * @param $special_price * @param $rules * @return bool */ public function hasSpecialPrice($product, $special_price, $rules = true) { if ($rules && $this->hasPriceByCatalogRules($product)) { return true; } if ($special_price <= 0) { return false; } $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()); $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE); // From Date $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $fromDate->setTimezone($timezone); } $special_from_date = $product->getSpecialFromDate(); if (is_empty_date($special_from_date)) { $special_from_date = $cDate->toString('yyyy-MM-dd HH:mm:ss'); } $fromDate->setDate(substr($special_from_date, 0, 10), 'yyyy-MM-dd'); $fromDate->setTime(substr($special_from_date, 11, 8), 'HH:mm:ss'); // To Date $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $toDate->setTimezone($timezone); } $special_to_date = $product->getSpecialToDate(); if (is_empty_date($special_to_date)) { $special_to_date = $cDate->toString('yyyy-MM-dd HH:mm:ss'); } if (is_empty_date($special_to_date)) { $toDate->add(365, Zend_Date::DAY); } $toDate->setDate(substr($special_to_date, 0, 10), 'yyyy-MM-dd'); $toDate->setTime(substr($special_to_date, 11, 8), 'HH:mm:ss'); if (($fromDate->compare($cDate) == -1 || $fromDate->compare($cDate) == 0) && ($toDate->compare($cDate) == 1 || $toDate->compare($cDate) == 0)) { return true; } return false; }
public function baseInit() { $dict = new Base_Dictionary(); $date = new Zend_Date(); $user = Zend_Auth::getInstance()->getIdentity(); $client = Logic_Client::getInstance(); $wsServiceSet = $client->getGroupListAsDict(Wsclient::GROUP_SERVICE_SET); $config = Zend_Registry::get('config'); $this->addElement('text', 'name', array('required' => true, 'label' => 'Nazwa wysyłki')); $this->datee(false, "send_start", "Początek wysyłki"); $this->send_start->setValue($date->getDate()->toString('YYYY-MM-dd'))->addValidator('Callback', false, array('callback' => function ($value) { $date = new Zend_Date(); $date2 = clone $date; return $date->getTimestamp() <= $date2->setDate($value, 'YYYY-MM-dd')->getTimestamp(); })); $this->timee(false, "time_send_start", "Okno czasowe od"); $this->time_send_start->setValue('8:00'); $this->timee(false, "time_send_end", "Okno czasowe do"); $this->time_send_end->setValue('20:00'); $this->time_send_end->addValidator('Callback', false, array('callback' => function ($value) { return strtotime($value) > strtotime($this->time_send_start->getValue()); })); $this->datetimee(false, 'expiry_date', "Ważność wiadomości", false, array('value' => '')); $this->expiry_date->addValidator('Callback', false, array('callback' => function ($value) { $date = new Zend_Date(); $date2 = clone $date; $date2->setDate($value, 'YYYY-MM-dd HH:mm'); $date->setDate($this->send_start->getValue(), 'YYYY-MM-dd HH:mm'); return $date->getTimestamp() <= $date2->getTimestamp() && $date->addHour(72)->getTimestamp() >= $date2->getTimestamp(); })); $this->expiry_date->getValidator('Callback')->setMessages(array(Zend_Validate_Callback::INVALID_VALUE => "Data ważności wiadmości może wynosić maksymalnie 72 godziny")); $this->addElement('checkbox', 'repeat_message', array('label' => 'Powtarzaj tą wiadomość', 'attribs' => array('onchange' => 'checkPackageOptions();'))); $this->repeat_message->addValidator('Callback', false, array('callback' => function ($value) { if ($value) { $this->repeat_interval->setRequired(true); $this->repeat_count->setRequired(true); $this->repeat_end->setRequired(true); } return true; })); $this->addElement('radio', 'repeat_interval', array('MultiOptions' => $dict->setSource('package_repeat')->getDictionary(), 'attribs' => array('disable' => 'disable'), 'attribs' => array('onchange' => 'checkPackageOptions();'))); $this->repeat_interval->addValidator('Callback', false, array('callback' => function ($value) { if ($value == 5) { $this->repeat_days->setRequired(true); } elseif ($value == 4) { $this->repeat_day_interval->setRequired(true); } return true; })); $this->addElement('multiselect', 'repeat_days', array('MultiOptions' => $dict->setSource('day_of_week')->getDictionary(), 'attribs' => array('disable' => 'disable'))); $this->addElement('text', 'repeat_day_interval', array('label' => 'Powtarzań wiadomość co (liczba dni)', 'attribs' => array('disable' => 'disable'))); $this->addElement('text', 'repeat_count', array('label' => 'Ilość powtórzeń wiadomości', 'attribs' => array('disable' => 'disable'))); $this->datetimee(false, "repeat_end", "Powtarzań do", false, array('value' => '', 'attribs' => array('disabled' => 'disabled'))); $this->repeat_end->addValidator('Callback', false, array('callback' => function ($value) { $date = new Zend_Date(); $date2 = clone $date; $date->setDate($value, 'YYYY-MM-dd HH:mm'); $date2->setDate($this->send_start->getValue(), 'YYYY-MM-dd HH:mm'); return $date->getTimestamp() <= $date2->setDate($value, 'YYYY-MM-dd HH:mm')->getTimestamp(); })); $this->addElement('select', 'ws_service_set_id', array('label' => 'Wysyłka', 'required' => true, 'MultiOptions' => $this->addClearStart($wsServiceSet), 'attribs' => array('onchange' => 'getServiceSetOptions();'))); $this->addElement('select', 'file_type', array('required' => true, 'label' => 'Typ wysyłki:', 'multioptions' => $this->addClearStart($dict->setSource('service_import_file_type')->getDictionary()))); $this->addElement('file', 'addressbook_import_csv', array('label' => 'CSV z listą kontaktów do zaimportowania', 'decorators' => $this->_fileDecorator, 'validators' => array(array('Extension', false, 'csv'), array('Size', false, $config['uploads']['maxfilesize'])))); $this->addElement('select', 'delimeter', array('label' => "Separator pola", 'MultiOptions' => $this->addClearStart($dict->setSource('csv_delimeter')->getDictionary()))); $this->addElement('select', 'phone_heders', array('label' => "Kolumna z kontaktami")); $this->addElement('select', 'ws_addressbook_id', array('label' => 'Adresy', 'MultiOptions' => $this->addClearStart($dict->setSource(new Addressbook(), array('created_by =' . (int) $user->id, 'ghost=false'), 'id', 'id', array('addressbook_name'))->getDictionary()))); $this->addDisplayGroup(array($this->addressbook_import_csv, $this->delimeter, $this->phone_heders), 'tags_import'); $this->addElement('select', 'message_heders', array('label' => "Kolumna z wiadomością")); $this->submit(false, 'save_send', 'Wyślij'); $this->submit(); $this->cancel(); }
public function getOptionValues() { $data = array(); $optionsArr = ''; $data = $this->getTemplateData(); if (isset($data['hash_options'])) { $optionsArr = $data['hash_options']; } $zendDate = new Zend_Date(); $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $helper = Mage::helper('customoptions'); $helper->getCustomerGroups(); // init customer_groups for sort prices $groupId = (int) $this->getRequest()->getParam('group_id'); if ($optionsArr) { $optionsArr = unserialize($optionsArr); } $store = Mage::app()->getStore($this->getStoreId()); $storeOptionsArr = array(); $groupStore = Mage::getSingleton('customoptions/group_store')->loadByGroupAndStore($groupId, $this->getStoreId()); if ($groupStore->getHashOptions()) { $storeOptionsArr = unserialize($groupStore->getHashOptions()); } //print_r($storeOptionsArr); exit; $optionModel = Mage::getSingleton('catalog/product_option'); if (!$this->_values && $optionsArr) { $values = array(); $sortOrder = array(); $scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); $optionItemCount = count($optionsArr); foreach ($optionsArr as $optionId => $option) { $option = new Varien_Object($option); $value = array(); if ($option->getIsDelete() != '1') { $value['id'] = $option->getOptionId(); $value['item_count'] = $optionItemCount; $value['option_id'] = $option->getOptionId(); $value['title'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['title']) ? $storeOptionsArr[$optionId]['title'] : $option->getTitle()); // old view_mode = hidden => to new type = 'hidden'; if ($optionModel->getGroupByType($option->getType()) == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT && $option->getViewMode() == 2) { $option->setType('hidden'); $option->setViewMode(1); } $value['type'] = $option->getType(); $value['is_require'] = $option->getIsRequire(); $value['view_mode'] = isset($storeOptionsArr[$optionId]['view_mode']) ? $storeOptionsArr[$optionId]['view_mode'] : $option->getViewMode(); $value['is_dependent'] = $option->getIsDependent(); $value['div_class'] = $option->getDivClass(); $value['sku_policy'] = $option->getSkuPolicy(); $value['customoptions_is_onetime'] = $option->getCustomoptionsIsOnetime(); $value['qnty_input'] = $option->getQntyInput() ? 'checked' : ''; $value['qnty_input_disabled'] = $option->getType() == 'multiple' || $option->getType() == 'hidden' ? 'disabled' : ''; $value['image_mode'] = $option->getImageMode(); $value['image_mode_disabled'] = $optionModel->getGroupByType($option->getType()) != Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT ? 'disabled' : ''; $value['exclude_first_image'] = $option->getExcludeFirstImage() ? 'checked' : ''; $value['description'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['description']) ? $storeOptionsArr[$optionId]['description'] : $option->getDescription()); if ($helper->isCustomerGroupsEnabled() && $option->getCustomerGroups() != null) { $value['customer_groups'] = implode(',', $option->getCustomerGroups()); } if ($helper->isStoreViewsEnabled() && $option->getStoreViews() != null) { $value['store_views'] = implode(',', $option->getStoreViews()); } $value['in_group_id'] = $option->getInGroupId(); $value['in_group_id_view'] = $option->getInGroupId(); $value['sort_order'] = $this->_getSortOrder($option); if ($this->getStoreId() != '0') { $value['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', !isset($storeOptionsArr[$optionId]['title'])); $value['scopeTitleDisabled'] = !isset($storeOptionsArr[$optionId]['title']) ? 'disabled' : null; $value['checkboxScopeViewMode'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'view_mode', !isset($storeOptionsArr[$optionId]['view_mode'])); $value['scopeViewModeDisabled'] = !isset($storeOptionsArr[$optionId]['view_mode']) ? 'disabled' : null; $value['checkboxScopeDescription'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'description', !isset($storeOptionsArr[$optionId]['description'])); $value['scopeDescriptionDisabled'] = !isset($storeOptionsArr[$optionId]['description']) ? 'disabled' : null; } if ($optionModel->getGroupByType($option->getType()) == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) { $countValues = count($option->getValues()); if ($countValues > 0) { foreach ($option->getValues() as $key => $_value) { $_value = new Varien_Object($_value); $_value->setOptionTypeId($key); if ($_value->getIsDelete() != '1') { $defaultArray = $option->getDefault() !== null ? $option->getDefault() : array(); if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price'])) { $_value->setPrice(floatval($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price'])); } if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price_type'])) { $_value->setPriceType($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price_type']); } // for support old format: if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['special_price'])) { $_value->setSpecialPrice(floatval($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['special_price'])); } if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['special_comment'])) { $_value->setSpecialComment($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['special_comment']); } if ($_value->getSpecialPrice()) { $_value->setSpecials(array(array('customer_group_id' => 32000, 'price' => $_value->getSpecialPrice(), 'price_type' => 'fixed', 'comment' => $_value->getSpecialComment(), 'date_from' => '', 'date_to' => ''))); } $helper->applyLinkedBySkuDataToOption($_value, $_value->getSku(), $store, 0); $helper->calculateOptionSpecialPrice($_value, null, $helper->isSpecialPriceEnabled()); $priceDisabled = $_value->getIsSkuPrice(); list($skuClass, $viewProductBySkuHtml) = $this->getViewSkuData($_value->getSku()); if (!$helper->isSkuQtyLinkingEnabled() || $helper->getProductIdBySku($_value->getSku()) == 0) { $customoptionsQty = $_value->getCustomoptionsQty(); } else { list($customoptionsQty, $backorders) = $helper->getCustomoptionsQty($_value->getCustomoptionsQty(), $_value->getSku(), 0, null, null, null, true); } $value['optionValues'][$key] = array('item_count' => $countValues, 'option_id' => $option->getOptionId(), 'option_type_id' => $_value->getOptionTypeId(), 'title' => $this->htmlEscape(isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title'] : $_value->getTitle()), 'price' => $this->getPriceValue($_value->getPrice(), $_value->getPriceType()), 'price_type' => $_value->getPriceType(), 'price_disabled' => $priceDisabled, 'description' => $this->htmlEscape(isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['description']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['description'] : $_value->getDescription()), 'cost' => $this->getPriceValue($_value->getCost(), 'fixed'), 'cost_disabled' => $_value->getIsSkuCost() ? 'disabled' : '', 'customoptions_qty' => $customoptionsQty, 'customoptions_qty_disabled' => $helper->isSkuQtyLinkingEnabled() && $helper->getProductIdBySku($_value->getSku()) ? 'disabled="disabled"' : '', 'sku' => $this->htmlEscape($_value->getSku()), 'sku_class' => $skuClass, 'view_product_by_sku_html' => $viewProductBySkuHtml, 'image_button_label' => $helper->__('Add Image'), 'sort_order' => $this->_getSortOrder($_value), 'checked' => array_search($_value->getOptionTypeId(), $defaultArray) !== false ? 'checked' : '', 'default_type' => $option->getType() == 'checkbox' || $option->getType() == 'multiple' || $option->getType() == 'multiswatch' || $option->getType() == 'hidden' ? 'checkbox' : 'radio', 'in_group_id' => $_value->getInGroupId(), 'in_group_id_view' => $_value->getInGroupId(), 'dependent_ids' => $_value->getDependentIds(), 'weight' => number_format(floatval($_value->getWeight()), 4, null, ''), 'weight_disabled' => $_value->getIsSkuWeight() ? 'disabled' : ''); // getImages $images = $_value->getImages(); if ($images) { $imagePath = $groupId . DS . $option->getId() . DS . $_value->getOptionTypeId() . DS; foreach ($images as $fileName) { if (substr($fileName, 0, 1) == '#') { // color $colorArr = array('id' => $option->getId(), 'select_id' => $_value->getOptionTypeId(), 'image_file' => $fileName, 'option_type_image_id' => $fileName, 'source' => 2); $value['optionValues'][$key]['images'][] = $colorArr; } else { // file $imgArr = $helper->getImgData($imagePath . $fileName, $option->getId(), $_value->getOptionTypeId()); if ($imgArr) { $imgArr['option_type_image_id'] = $imgArr['file_name']; $value['optionValues'][$key]['images'][] = $imgArr; } } } } elseif ($_value->getImagePath()) { // old format $imgArr = $helper->getImgData($_value->getImagePath(), $option->getId(), $_value->getOptionTypeId()); if ($imgArr) { $imgArr['option_type_image_id'] = $imgArr['file_name']; $value['optionValues'][$key]['images'][] = $imgArr; } } else { $value['optionValues'][$key]['image_tr_style'] = 'display:none'; } //getOptionValueSpecialPrices $specialPrices = isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['specials']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['specials'] : $_value->getSpecials(); if ($specialPrices) { foreach ($specialPrices as $specialKey => $specialPrice) { $specialPrices[$specialKey]['price'] = $this->getPriceValue($specialPrice['price'], $specialPrice['price_type']); if (isset($specialPrice['date_from']) && $specialPrice['date_from']) { $specialPrices[$specialKey]['date_from'] = $zendDate->setDate($specialPrice['date_from'], Varien_Date::DATE_INTERNAL_FORMAT)->toString($dateFormat); } else { $specialPrices[$specialKey]['date_from'] = ''; } if (isset($specialPrice['date_to']) && $specialPrice['date_to']) { $specialPrices[$specialKey]['date_to'] = $zendDate->setDate($specialPrice['date_to'], Varien_Date::DATE_INTERNAL_FORMAT)->toString($dateFormat); } else { $specialPrices[$specialKey]['date_to'] = ''; } } usort($specialPrices, array($helper, '_sortPrices')); $value['optionValues'][$key]['specials'] = $specialPrices; } //getOptionValueTierPrices $tierPrices = isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['tiers']) ? $storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['tiers'] : $_value->getTiers(); if ($tierPrices) { foreach ($tierPrices as $tierKey => $tierPrice) { $tierPrices[$tierKey]['price'] = $this->getPriceValue($tierPrice['price'], $tierPrice['price_type']); } usort($tierPrices, array($helper, '_sortPrices')); $value['optionValues'][$key]['tiers'] = $tierPrices; } if ($this->getStoreId() != '0') { $value['optionValues'][$key]['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']), $_value->getOptionTypeId()); $value['optionValues'][$key]['scopeTitleDisabled'] = !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['title']) ? 'disabled' : null; $value['optionValues'][$key]['checkboxScopeDescription'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'description', !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['description']), $_value->getOptionTypeId()); $value['optionValues'][$key]['scopeDescriptionDisabled'] = !isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['description']) ? 'disabled' : null; //if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) { if (isset($storeOptionsArr[$optionId]['values'][$_value->getOptionTypeId()]['price'])) { $scopePrice = true; } else { $scopePrice = false; } if (!$priceDisabled) { $value['optionValues'][$key]['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', !$scopePrice, $_value->getOptionTypeId()); } $value['optionValues'][$key]['scopePriceDisabled'] = !$scopePrice ? 'disabled' : null; //} } } } $value['optionValues'] = array_values($value['optionValues']); } } else { if (isset($storeOptionsArr[$optionId]['price'])) { $option->setPrice(floatval($storeOptionsArr[$optionId]['price'])); } if (isset($storeOptionsArr[$optionId]['price_type'])) { $option->setPriceType($storeOptionsArr[$optionId]['price_type']); } $helper->applyLinkedBySkuDataToOption($option, $option->getSku(), $store, 0); $helper->calculateOptionSpecialPrice($option, null, false); $priceDisabled = $option->getIsSkuPrice(); list($skuClass, $viewProductBySkuHtml) = $this->getViewSkuData($option->getSku()); $value['price'] = $this->getPriceValue($option->getPrice(), $option->getPriceType()); $value['price_type'] = $option->getPriceType(); $value['price_disabled'] = $priceDisabled; $value['sku'] = $this->htmlEscape($option->getSku()); $value['sku_class'] = $skuClass; $value['view_product_by_sku_html'] = $viewProductBySkuHtml; $value['max_characters'] = $option->getMaxCharacters(); $value['default_text'] = $this->htmlEscape(isset($storeOptionsArr[$optionId]['default_text']) ? $storeOptionsArr[$optionId]['default_text'] : $option->getDefaultText()); $value['file_extension'] = $option->getFileExtension(); $value['image_size_x'] = $option->getImageSizeX(); $value['image_size_y'] = $option->getImageSizeY(); $value['image_button_label'] = $helper->__('Add Image'); $imgHtml = $helper->getImgHtml($helper->getImgData($option->getImagePath(), $option->getId())); if ($imgHtml) { $value['image'] = $imgHtml; $value['image_button_label'] = $helper->__('Change Image'); } if ($this->getStoreId() != '0') { //&& $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE if (!$priceDisabled) { $value['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', !isset($storeOptionsArr[$optionId]['price'])); } $value['scopePriceDisabled'] = !isset($storeOptionsArr[$optionId]['price']) ? 'disabled' : null; $value['checkboxScopeDefaultText'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'default_text', !isset($storeOptionsArr[$optionId]['default_text'])); $value['scopeDefaultTextDisabled'] = !isset($storeOptionsArr[$optionId]['default_text']) ? 'disabled' : null; } } $values[] = new Varien_Object($value); } } $this->_values = $values; } return $this->_values ? $this->_values : array(); }
public function toTimestamp($date, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT) { $dateFormat = Mage::app()->getLocale()->getDateFormat($format); $dateObj = new Zend_Date(); if ($date) { try { $dateObj->setDate($date, $dateFormat); } catch (Exception $ex) { try { $dateObj->setDate($date); } catch (Exception $ex) { if ($timestamp = @strtotime($date)) { $dateObj->setTimestamp($timestamp); } } } $dateObj->setTime(0); } return $dateObj->getTimestamp(); }
public function saveAction() { @ini_set('max_execution_time', 1800); @ini_set('memory_limit', 534003200); $helper = Mage::helper('customoptions'); $productOptionModel = Mage::getModel('catalog/product_option'); $zendDate = new Zend_Date(); $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $data = $this->getRequest()->getPost(); $id = (int) $this->getRequest()->getParam('group_id'); $storeId = (int) $this->getRequest()->getParam('store', 0); $redirectParams = array('group_id' => $id); if ($storeId > 0) { $redirectParams['store'] = $storeId; } $error = false; if ($data) { $data = $helper->getFilter($data); try { // prepare Assign by -> $data['in_products'] if (isset($data['products_area_type']) && $data['products_area_type'] > 1 && isset($data['products_area'])) { if ($data['in_products']) { $productIds = explode(',', $data['in_products']); } else { $productIds = array(); } switch ($data['products_area_type']) { case 2: // by product ids $productArea = explode(',', $data['products_area']); foreach ($productArea as $productId) { $productId = intval($productId); if ($productId && !in_array($productId, $productIds)) { $product = Mage::getSingleton('catalog/product')->load($productId); if ($product && $product->getId() > 0) { $productIds[] = $productId; } } } $data['in_products'] = implode(',', $productIds); break; case 3: // by SKUs $productArea = explode(',', $data['products_area']); foreach ($productArea as $sku) { $sku = trim($sku); $productId = $helper->getProductIdBySku($sku); if ($productId && !in_array($productId, $productIds)) { $productIds[] = $productId; } } $data['in_products'] = implode(',', $productIds); break; } } $productOptions = array(); if (!isset($data['product']['options']) || $this->_isEmptyOptions($data['product']['options'])) { Mage::getSingleton('adminhtml/session')->addError($this->__('There are no Options')); $error = true; } else { // first prepare options: id=-1 -> id=$key $productOptions = $data['product']['options']; foreach ($productOptions as $i => $option) { if (isset($option['values'])) { if (count($option['values']) > 0) { foreach ($option['values'] as $key => $value) { if ($value['option_type_id'] == '-1') { $option['values'][$key]['option_type_id'] = (string) $key; } if (!isset($value['scope']['price'])) { if (!isset($value['price'])) { $option['values'][$key]['price'] = '0.00'; } if (!isset($value['price_type'])) { $option['values'][$key]['price_type'] = 'fixed'; } } if (isset($value['specials'])) { if (count($value['specials']) > 0) { // uniq by group $specials = array(); foreach ($value['specials'] as $sKey => $sValue) { if ($sValue['is_delete'] == '1') { continue; } if ($sValue['special_price_id'] == '-1') { $sValue['special_price_id'] = (string) $sKey; } $sValue['comment'] = trim($sValue['comment']); if (isset($sValue['date_from']) && $sValue['date_from']) { $sValue['date_from'] = $zendDate->setDate($sValue['date_from'], $dateFormat)->toString(Varien_Date::DATE_INTERNAL_FORMAT); } else { $sValue['date_from'] = ''; } if (isset($sValue['date_to']) && $sValue['date_to']) { $sValue['date_to'] = $zendDate->setDate($sValue['date_to'], $dateFormat)->toString(Varien_Date::DATE_INTERNAL_FORMAT); } else { $sValue['date_to'] = ''; } if (!isset($specials[$sValue['customer_group_id']])) { $specials[$sValue['customer_group_id']] = $sValue; } } $option['values'][$key]['specials'] = array(); foreach ($specials as $sValue) { $option['values'][$key]['specials'][$sValue['special_price_id']] = $sValue; } } else { unset($option['values'][$key]['specials']); } } if (isset($value['tiers'])) { if (count($value['tiers']) > 0) { // uniq by group and qty $tiers = array(); foreach ($value['tiers'] as $tkey => $tValue) { if ($tValue['is_delete'] == '1') { continue; } $tValue['qty'] = intval($tValue['qty']); if ($tValue['qty'] == 0) { continue; } if ($tValue['tier_price_id'] == '-1') { $tValue['tier_price_id'] = (string) $tkey; } if (!isset($tiers[$tValue['customer_group_id'] . '+' . $tValue['qty']])) { $tiers[$tValue['customer_group_id'] . '+' . $tValue['qty']] = $tValue; } } $option['values'][$key]['tiers'] = array(); foreach ($tiers as $tValue) { $option['values'][$key]['tiers'][$tValue['tier_price_id']] = $tValue; } } else { unset($option['values'][$key]['tiers']); } } if ($helper->isSkuNameLinkingEnabled() && (!isset($value['title']) || $value['title'] == '') && $value['sku']) { $option['values'][$key]['title'] = $helper->getProductNameBySku($value['sku'], $storeId); } } } else { unset($option['values']); } } else { if (!isset($option['scope']['price'])) { if (!isset($option['price'])) { $option['price'] = '0.00'; } if (!isset($option['price_type'])) { $option['price_type'] = 'fixed'; } } if ($helper->isSkuNameLinkingEnabled() && (!isset($option['title']) || $option['title'] == '') && $productOptionModel->getGroupByType($option['type']) != Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT && $option['sku']) { $option['title'] = $helper->getProductNameBySku($option['sku'], $storeId); } } $option['option_id'] = $i; // qnty_input if (!isset($option['qnty_input']) || $productOptionModel->getGroupByType($option['type']) != Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT || $option['type'] == 'multiple' || $option['type'] == 'hidden') { $option['qnty_input'] = 0; } // exclude_first_image if (!isset($option['exclude_first_image']) || $productOptionModel->getGroupByType($option['type']) != Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) { $option['exclude_first_image'] = 0; } $productOptions[$i] = $option; } $data['general']['hash_options'] = serialize(array()); } if ($error) { if (isset($data['in_products']) && is_array($data['in_products']) && count($data['in_products']) > 0) { $data['in_products'] = implode(',', $data['in_products']); } throw new Exception(); } $optionsPrev = array(); $prevGroupIsActive = 1; if ($id) { $group = Mage::getSingleton('customoptions/group')->load($id); $prevGroupIsActive = $group->getIsActive(); if ($group->getHashOptions() != '') { $optionsPrev = unserialize($group->getHashOptions()); } } else { $group = Mage::getSingleton('customoptions/group'); } // insert if (!$id) { $group->setData($data['general']); $group->save(); $id = $group->getId(); } $productIds = array(); if (isset($data['in_products']) && $data['in_products']) { $productIds = explode(',', $data['in_products']); } //remove files if (isset($data['image_delete'])) { foreach ($data['image_delete'] as $optionId) { if ($optionId) { $helper->deleteOptionFile($group->getId(), $optionId); } } } //upload files foreach ($productOptions as $key => $option) { if ($option['option_id'] == 0) { $option['option_id'] = 1; } switch ($option['type']) { case 'field': case 'area': $this->_uploadImage('file_' . $option['option_id'], $id, $option['option_id']); if (isset($option['id'])) { if ($helper->isCustomOptionsFile($id, $option['id'])) { $option['image_path'] = $id . DS . $option['id'] . DS; } else { $option['image_path'] = ''; } } $productOptions[$key] = $option; break; case 'drop_down': case 'radio': case 'checkbox': case 'multiple': case 'swatch': case 'multiswatch': case 'hidden': if (isset($option['values']) && is_array($option['values']) && !empty($option['values'])) { foreach ($option['values'] as $k => $value) { $counter = $value['option_type_id'] == '-1' ? $k : $value['option_type_id']; $value['images'] = $this->_uploadImage('file_' . $option['option_id'] . '_' . $counter, $id, $option['option_id'], $counter, $value); $productOptions[$key]['values'][$k] = $value; } } break; case 'file': case 'date': case 'date_time': case 'time': // no image if (isset($option['option_id'])) { $helper->deleteOptionFile($id, $option['option_id']); } break; } } $prevStoreOptionsData = array(); if ($storeId > 0) { // if no default store $defaultOptions = $optionsPrev; // add to store defoult values + add new options to defoult or mark is_delete flag foreach ($productOptions as $key => $option) { if (isset($optionsPrev[$key])) { if (isset($option['scope'])) { foreach ($option['scope'] as $field => $value) { if ($value && isset($optionsPrev[$key][$field])) { $productOptions[$key][$field] = $optionsPrev[$key][$field]; } } unset($productOptions[$key]['scope']); } $defaultOptions[$key]['is_delete'] = $option['is_delete']; if (isset($option['values'])) { foreach ($option['values'] as $valueId => $optionValue) { if (isset($optionsPrev[$key]['values'][$valueId])) { if (isset($optionValue['scope'])) { foreach ($optionValue['scope'] as $field => $value) { if ($value && isset($optionsPrev[$key]['values'][$valueId][$field])) { $productOptions[$key]['values'][$valueId][$field] = $optionsPrev[$key]['values'][$valueId][$field]; } } unset($productOptions[$key]['values'][$valueId]['scope']); } $defaultOptions[$key]['values'][$valueId]['is_delete'] = $optionValue['is_delete']; } else { // found new option value $defaultOptions[$key]['values'][$valueId] = $optionValue; } } } } else { // found new option $defaultOptions[$key] = $option; } } // difference default and store - quadruple nesting //$storeOptions = $this->comparisonArrays4($productOptions, $defaultOptions); // difference default and store $storeOptions = Mage::getSingleton('catalog/product_option')->comparisonArrays($productOptions, $defaultOptions); // add option_id/option_type_id/type to $storeOptions foreach ($storeOptions as $optionId => $option) { $storeOptions[$optionId]['option_id'] = $optionId; $storeOptions[$optionId]['type'] = $productOptions[$optionId]['type']; if (isset($option['price']) && !isset($option['price_type'])) { $storeOptions[$optionId]['price_type'] = $productOptions[$optionId]['price_type']; } if (!isset($option['price']) && isset($option['price_type'])) { $storeOptions[$optionId]['price'] = $productOptions[$optionId]['price']; } if (isset($option['values'])) { foreach ($option['values'] as $valueId => $optionValue) { $storeOptions[$optionId]['values'][$valueId]['option_type_id'] = $valueId; if (isset($optionValue['price']) || isset($optionValue['price_type']) || isset($optionValue['tiers']) || isset($optionValue['specials'])) { $storeOptions[$optionId]['values'][$valueId]['price'] = $productOptions[$optionId]['values'][$valueId]['price']; $storeOptions[$optionId]['values'][$valueId]['price_type'] = $productOptions[$optionId]['values'][$valueId]['price_type']; if (isset($productOptions[$optionId]['values'][$valueId]['specials'])) { $storeOptions[$optionId]['values'][$valueId]['specials'] = $productOptions[$optionId]['values'][$valueId]['specials']; } if (isset($productOptions[$optionId]['values'][$valueId]['tiers'])) { $storeOptions[$optionId]['values'][$valueId]['tiers'] = $productOptions[$optionId]['values'][$valueId]['tiers']; } } } } } // save store options $groupStore = Mage::getSingleton('customoptions/group_store')->loadByGroupAndStore($id, $storeId); $prevStoreOptionsData = $groupStore->getData(); $groupStore->setGroupId($id)->setStoreId($storeId)->setHashOptions(serialize($this->_prepareOptions($storeOptions, $id)))->save(); // print_r($optionsPrev); // print_r($defaultOptions); // print_r($storeOptions); // exit; } else { // default store $defaultOptions = $productOptions; // foreach all no default store and mark is_delete flag or no option $groupStoreCollection = Mage::getResourceModel('customoptions/group_store_collection')->addFieldToFilter('group_id', $id); if (count($groupStoreCollection) > 0) { foreach ($groupStoreCollection as $groupStore) { $groupStoreOptions = $groupStore->getHashOptions(); if ($groupStoreOptions) { $groupStoreOptions = unserialize($groupStoreOptions); } $changeFlag = false; foreach ($groupStoreOptions as $optionId => $option) { if (!isset($defaultOptions[$optionId]) || isset($defaultOptions[$optionId]['is_delete']) && $defaultOptions[$optionId]['is_delete']) { unset($groupStoreOptions[$optionId]); $changeFlag = true; } else { if (isset($option['values']) && count($option['values']) > 0) { foreach ($option['values'] as $valueId => $value) { if (!isset($defaultOptions[$optionId]['values'][$valueId]) || isset($defaultOptions[$optionId]['values'][$valueId]['is_delete']) && $defaultOptions[$optionId]['values'][$valueId]['is_delete']) { unset($groupStoreOptions[$optionId]['values'][$valueId]); if (count($groupStoreOptions[$optionId]['values']) == 0) { unset($groupStoreOptions[$optionId]['values']); } $changeFlag = true; } else { if (isset($value['specials']) && count($value['specials']) > 0) { if (!isset($defaultOptions[$optionId]['values'][$valueId]['specials'])) { unset($groupStoreOptions[$optionId]['values'][$valueId]['specials']); $changeFlag = true; } else { foreach ($value['specials'] as $specialId => $sValue) { if (!isset($defaultOptions[$optionId]['values'][$valueId]['specials'][$specialId])) { unset($groupStoreOptions[$optionId]['values'][$valueId]['specials'][$specialId]); $changeFlag = true; } } } } if (isset($value['tiers']) && count($value['tiers']) > 0) { if (!isset($defaultOptions[$optionId]['values'][$valueId]['tiers'])) { unset($groupStoreOptions[$optionId]['values'][$valueId]['tiers']); $changeFlag = true; } else { foreach ($value['tiers'] as $tierId => $tValue) { if (!isset($defaultOptions[$optionId]['values'][$valueId]['tiers'][$tierId])) { unset($groupStoreOptions[$optionId]['values'][$valueId]['tiers'][$tierId]); $changeFlag = true; } } } } } } } } } if ($changeFlag) { if (count($groupStoreOptions) > 0) { $groupStore->setHashOptions(serialize($groupStoreOptions))->save(); } else { $groupStore->delete(); } } } } } //print_r($defaultOptions); exit; // save default options if (!isset($data['general']['absolute_price'])) { $data['general']['absolute_price'] = 0; } if (!isset($data['general']['absolute_weight'])) { $data['general']['absolute_weight'] = 0; } if (!isset($data['general']['sku_policy'])) { $data['general']['sku_policy'] = 0; } if (!isset($data['general']['update_inventory'])) { $data['general']['update_inventory'] = 0; } if (!isset($data['general']['only_update'])) { $data['general']['only_update'] = 0; } $data['general']['hash_options'] = serialize($this->_prepareOptions($defaultOptions, $id)); $approximateOptionCount = ceil((strlen($data['general']['hash_options']) + 1) / 500); // 500 byte = ~1 option $group->setData($data['general']); $group->setId($id); $group->save(); Mage::getSingleton('adminhtml/session')->setCustomoptionsData(null); if ($this->getRequest()->getParam('back')) { $redirectParams['group_id'] = $group->getId(); $redirectData = array('*/*/edit', $redirectParams); } else { $redirectData = array('*/*/', array()); } // apply options to products if ($productOptions && isset($productIds) && is_array($productIds)) { if (count($productIds) > 0) { if (count($productIds) * $approximateOptionCount < 250) { // apply default and store $productOptionModel->saveProductOptions($defaultOptions, $optionsPrev, $productIds, $group, $prevGroupIsActive, 'apo', $prevStoreOptionsData); // make reindex $productIndexerPrice = Mage::getResourceModel('catalog/product_indexer_price'); if (method_exists($productIndexerPrice, 'reindexProductIds')) { $productIndexerPrice->reindexProductIds($productIds); } else { Mage::getModel('catalog/product_indexer_price')->reindexAll(); } } else { // start multi-step apply $limit = ceil(250 / $approximateOptionCount); Mage::getSingleton('adminhtml/session')->setCustomoptionsApplyData(array($defaultOptions, $optionsPrev, $productIds, $group, $prevGroupIsActive, $prevStoreOptionsData, $redirectData, $limit)); return $this->_redirect('*/*/apply'); } } else { if ($productOptionModel->removeProductOptionsAndRelationByGroup($group->getId())) { Mage::getModel('catalog/product_indexer_price')->reindexAll(); // make reindex } } } Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Options were successfully saved')); return $this->_redirect($redirectData[0], $redirectData[1]); } catch (Exception $e) { if ($e->getMessage()) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); } Mage::getSingleton('adminhtml/session')->setData('customoptions_data', $data); $this->_redirect('*/*/edit', $redirectParams); return; } } Mage::getSingleton('adminhtml/session')->addError($this->__('Unable to find Options to save')); $this->_redirect('*/*/'); }
/** * * @return int|bool */ public function saveClient() { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $dbAdapter->beginTransaction(); try { $dbStudentClassPerData = App_Model_DbTable_Factory::get('FEFEPStudentClass_has_PerData'); $date = new Zend_Date(); foreach ($this->_data['status'] as $client => $status) { $dataUpdate = array('status' => $status); $where = array('fk_id_perdata = ?' => $client, 'fk_id_fefpstudentclass = ?' => $this->_data['fk_id_fefpstudentclass']); if (!empty($this->_data['date_drop'][$client])) { $dataUpdate['date_drop_out'] = $date->setDate($this->_data['date_drop'][$client], 'dd/MM/yyyy')->toString('yyyy-MM-dd'); } else { $dataUpdate['date_drop_out'] = null; } $dbStudentClassPerData->update($dataUpdate, $where); } // Save the auditing $history = 'ATUALIZA ALUNO SIRA: BA KLASE %s'; $history = sprintf($history, $this->_data['fk_id_fefpstudentclass']); $this->_sysAudit($history, StudentClass_Form_RegisterClient::ID); $dbAdapter->commit(); return $this->_data['fk_id_fefpstudentclass']; } catch (Exception $e) { $dbAdapter->rollBack(); $this->_message->addMessage($this->_config->messages->error, App_Message::ERROR); return false; } }
/** * * @param type $event * @return type */ protected function _treatEvent($event) { $date = new Zend_Date(); $title = (empty($event->external_code) ? '' : $event->external_code . ' - ') . $event->scholarity; $title .= ' - Partisipants: ' . $event->students_course; $row = array('id' => $event->id_planning_course, 'title' => $title, 'start' => (int) $date->setDate($event->date_start, 'yyyy-MM-dd')->get(Zend_Date::TIMESTAMP), 'end' => (int) $date->setDate($event->date_finish, 'yyyy-MM-dd')->get(Zend_Date::TIMESTAMP), 'scholarity' => $event->id_perscholarity); return $row; }
protected function mapDirectiveSalePriceEffectiveDate($params = array()) { /** @var $product Mage_Catalog_Model_Product */ $product = $this->getProduct(); $assocMapArr = $this->getAssocMaps(); $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()); $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE); $cell = ""; if (!$this->hasSpecialPrice($product, $this->getSpecialPrice($product))) { return $cell; } $has_default_qty = $this->_hasDefaultQty($assocMapArr); $display_min = $this->getConfigVar('grouped_price_display_mode', 'columns'); if ($has_default_qty) { if ($display_min == RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_SUM_DEFAULT_QTY) { $product_from_date = $product_to_date = null; $from_time = -1; $to_time = PHP_INT_MAX; foreach ($assocMapArr as $assocMap) { $associatedProduct = $assocMap->getProduct(); if ($associatedProduct->getQty() > 0) { if ($assocMap->hasSpecialPrice($associatedProduct, $assocMap->getSpecialPrice($associatedProduct))) { if ($assocMap->hasPriceByCatalogRules($associatedProduct)) { // Current date to cdate + ttl $fromDate = clone $cDate; $fromDate->setTime('00:00:00', 'HH:mm:ss'); $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY); $compare_from_date = $fromDate->toString('yyyy-MM-dd 00:00:00'); $compare_to_date = $toDate->toString('yyyy-MM-dd 23:59:59'); } else { $compare_from_date = $associatedProduct->getSpecialFromDate(); $compare_to_date = $associatedProduct->getSpecialToDate(); } if ($from_time < $this->dateToTime($compare_from_date)) { $product_from_date = $compare_from_date; $from_time = $this->dateToTime($product_from_date); } if (!is_empty_date($compare_to_date) && $to_time > $this->dateToTime($compare_to_date)) { $product_to_date = $compare_to_date; $to_time = $this->dateToTime($product_to_date); } } } } } else { // RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_START_AT $minAssocMap = $this->findMinimalPriceProduct($assocMapArr); if ($minAssocMap === false) { return $cell; } $associatedProduct = $minAssocMap->getProduct(); if ($minAssocMap->hasPriceByCatalogRules($associatedProduct)) { // Current date to cdate + ttl $fromDate = clone $cDate; $fromDate->setTime('00:00:00', 'HH:mm:ss'); $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY); $compare_from_date = $fromDate->toString('yyyy-MM-dd 00:00:00'); $compare_to_date = $toDate->toString('yyyy-MM-dd 23:59:59'); } else { $compare_from_date = $associatedProduct->getSpecialFromDate(); $compare_to_date = $associatedProduct->getSpecialToDate(); } $product_from_date = $compare_from_date; $product_to_date = $compare_to_date; } } else { // RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_START_AT $minAssocMap = $this->findMinimalPriceProduct($assocMapArr); if ($minAssocMap === false) { return $cell; } $associatedProduct = $minAssocMap->getProduct(); $product_from_date = $associatedProduct->getSpecialFromDate(); $product_to_date = $associatedProduct->getSpecialToDate(); } $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $fromDate->setTimezone($timezone); } if ($product_from_date) { $fromDate->setDate(substr($product_from_date, 0, 10), 'yyyy-MM-dd'); $fromDate->setTime(substr($product_from_date, 11, 8), 'HH:mm:ss'); } $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if (!is_empty_date($product_to_date)) { if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate(substr($product_to_date, 0, 10), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); } else { if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY); } $cell = $fromDate->toString(Zend_Date::ISO_8601) . "/" . $toDate->toString(Zend_Date::ISO_8601); return $cell; }
/** * Returns ready-to-use calendar field HTML * @return string */ public function getCalendarHtml() { $_editableOptions = $this->getProduct()->getPreconfiguredValues(); if (!isset($_editableOptions['aw_sarp_subscription_start'])) { $zDate = new Zend_Date($this->getProductBlock()->formatDate($this->getDefaultPeriod()->getNearestAvailableDay(), Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), null, Mage::app()->getLocale()->getLocaleCode()); $date = $zDate->toString(preg_replace(array('/M+/', '/d+/'), array('MM', 'dd'), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); } else { $date = $_editableOptions['aw_sarp_subscription_start']; $zDate = new Zend_Date(); $zDate->setDate($date); $today = new Zend_Date(); $period = Mage::getModel('sarp/period')->load($_editableOptions['aw_sarp_subscription_type']); if ($zDate->compare($today, Zend_Date::DATE_SHORT) < 0 || !$period->isAllowedDate($zDate, $this->getProduct())) { $zDate = $period->getNearestAvailableDay(); } $date = $zDate->toString(preg_replace(array('/M+/', '/d+/'), array('MM', 'dd'), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); } $calendar = $this->getProductBlock()->getLayout()->createBlock('sarp/html_date')->setId(self::DATE_FIELD_NAME)->setName(self::DATE_FIELD_NAME)->setPeriod($this->getDefaultPeriod())->setClass('product-custom-option datetime-picker input-text')->setImage(Mage::getDesign()->getSkinUrl('aw_sarp/images/grid-cal.gif'))->setValue($date)->setFormat(Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); return $calendar->getHtml(); }