Example #1
0
 /**
  * Returns the result of filtering $value
  *
  * @param string $value
  * @return string
  */
 public function outputFilter($value)
 {
     $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Varien_Date::DATETIME_INTERNAL_FORMAT, 'locale' => $this->_locale));
     $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => $this->_dateFormat, 'locale' => $this->_locale));
     $value = $filterInput->filter($value);
     $value = $filterInternal->filter($value);
     return $value;
 }
Example #2
0
 /**
  * Convert date from localized to internal format
  *
  * @param string $date
  * @param string $locale
  * @return string
  */
 protected function _convertDate($date, $locale)
 {
     $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
     $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT));
     $date = $filterInput->filter($date);
     $date = $filterInternal->filter($date);
     return $date;
 }
 public function filterDateValue($value)
 {
     $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
     $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT));
     $value = $filterInput->filter($value);
     $value = $filterInternal->filter($value);
     return $value;
 }
Example #4
0
 /**
  * Returns the result of filtering $value
  *
  * @param string $value
  * @return string
  */
 public function outputFilter($value)
 {
     $filterInput = new \Zend_Filter_LocalizedToNormalized(['date_format' => DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->localeResolver->getLocale()]);
     $filterInternal = new \Zend_Filter_NormalizedToLocalized(['date_format' => $this->_dateFormat, 'locale' => $this->localeResolver->getLocale()]);
     $value = $filterInput->filter($value);
     $value = $filterInternal->filter($value);
     return $value;
 }
Example #5
0
 /**
  * Returns the result of filtering $value
  *
  * @param string $value
  * @return string
  */
 public function outputFilter($value)
 {
     $filterInput = new \Zend_Filter_LocalizedToNormalized(array('date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale));
     $filterInternal = new \Zend_Filter_NormalizedToLocalized(array('date_format' => $this->_dateFormat, 'locale' => $this->_locale));
     $value = $filterInput->filter($value);
     $value = $filterInternal->filter($value);
     return $value;
 }
 public function _get($fieldName, $load = true)
 {
     $value = parent::_get($fieldName, $load);
     if (strstr($fieldName, 'week_')) {
         $zendFilter = new Zend_Filter_NormalizedToLocalized();
         return $zendFilter->filter($value);
     }
     return $value;
 }
 protected function _filterDates($array, $dateFields)
 {
     if (empty($dateFields)) {
         return $array;
     }
     $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
     $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT));
     foreach ($dateFields as $dateField) {
         if (array_key_exists($dateField, $array) && !empty($dateField)) {
             $array[$dateField] = $filterInput->filter($array[$dateField]);
             $array[$dateField] = $filterInternal->filter($array[$dateField]);
         }
     }
     return $array;
 }
Example #8
0
 /**
  * Convert date from localized to internal format
  *
  * @param string $value
  * @return string
  */
 public function filter($value)
 {
     return $this->_normalToLocalFilter->filter($this->_localToNormalFilter->filter($value));
 }
Example #9
0
 public function saveAction()
 {
     if (!$this->_validateProducts()) {
         return;
     }
     /* Collect Data */
     $inventoryData = $this->getRequest()->getParam('inventory', array());
     $attributesData = $this->getRequest()->getParam('attributes', array());
     $websiteRemoveData = $this->getRequest()->getParam('remove_website_ids', array());
     $websiteAddData = $this->getRequest()->getParam('add_website_ids', array());
     /* Prepare inventory data item options (use config settings) */
     foreach (Mage::helper('Mage_CatalogInventory_Helper_Data')->getConfigItemOptions() as $option) {
         if (isset($inventoryData[$option]) && !isset($inventoryData['use_config_' . $option])) {
             $inventoryData['use_config_' . $option] = 0;
         }
     }
     try {
         if ($attributesData) {
             $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
             $storeId = $this->_getHelper()->getSelectedStoreId();
             foreach ($attributesData as $attributeCode => $value) {
                 $attribute = Mage::getSingleton('Mage_Eav_Model_Config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
                 if (!$attribute->getAttributeId()) {
                     unset($attributesData[$attributeCode]);
                     continue;
                 }
                 if ($attribute->getBackendType() == 'datetime') {
                     if (!empty($value)) {
                         $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => $dateFormat));
                         $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT));
                         $value = $filterInternal->filter($filterInput->filter($value));
                     } else {
                         $value = null;
                     }
                     $attributesData[$attributeCode] = $value;
                 } else {
                     if ($attribute->getFrontendInput() == 'multiselect') {
                         if (is_array($value)) {
                             $value = implode(',', $value);
                         }
                         $attributesData[$attributeCode] = $value;
                     }
                 }
             }
             Mage::getSingleton('Mage_Catalog_Model_Product_Action')->updateAttributes($this->_getHelper()->getProductIds(), $attributesData, $storeId);
         }
         if ($inventoryData) {
             $stockItem = Mage::getModel('Mage_CatalogInventory_Model_Stock_Item');
             $stockItem->setProcessIndexEvents(false);
             $stockItemSaved = false;
             foreach ($this->_getHelper()->getProductIds() as $productId) {
                 $stockItem->setData(array());
                 $stockItem->loadByProduct($productId)->setProductId($productId);
                 $stockDataChanged = false;
                 foreach ($inventoryData as $k => $v) {
                     $stockItem->setDataUsingMethod($k, $v);
                     if ($stockItem->dataHasChangedFor($k)) {
                         $stockDataChanged = true;
                     }
                 }
                 if ($stockDataChanged) {
                     $stockItem->save();
                     $stockItemSaved = true;
                 }
             }
             if ($stockItemSaved) {
                 Mage::getSingleton('Mage_Index_Model_Indexer')->indexEvents(Mage_CatalogInventory_Model_Stock_Item::ENTITY, Mage_Index_Model_Event::TYPE_SAVE);
             }
         }
         if ($websiteAddData || $websiteRemoveData) {
             /* @var $actionModel Mage_Catalog_Model_Product_Action */
             $actionModel = Mage::getSingleton('Mage_Catalog_Model_Product_Action');
             $productIds = $this->_getHelper()->getProductIds();
             if ($websiteRemoveData) {
                 $actionModel->updateWebsites($productIds, $websiteRemoveData, 'remove');
             }
             if ($websiteAddData) {
                 $actionModel->updateWebsites($productIds, $websiteAddData, 'add');
             }
             Mage::dispatchEvent('catalog_product_to_website_change', array('products' => $productIds));
             $this->_getSession()->addNotice($this->__('Please refresh "Catalog URL Rewrites" and "Product Attributes" in System -> <a href="%s">Index Management</a>', $this->getUrl('adminhtml/process/list')));
         }
         $this->_getSession()->addSuccess($this->__('Total of %d record(s) were updated', count($this->_getHelper()->getProductIds())));
     } catch (Mage_Core_Exception $e) {
         $this->_getSession()->addError($e->getMessage());
     } catch (Exception $e) {
         $this->_getSession()->addException($e, $this->__('An error occurred while updating the product(s) attributes.'));
     }
     $this->_redirect('*/catalog_product/', array('store' => $this->_getHelper()->getSelectedStoreId()));
 }
 /**
  * Ensures that the filter follows expected behavior
  *
  * @return void
  */
 public function testLocalizationToFloat()
 {
     $filter = new Zend_Filter_NormalizedToLocalized(array('locale' => 'de', 'precision' => 2));
     $valuesExpected = array(1 => '1234.5678', 2 => 1234.5678, 3 => '1.234', 4 => 1.234, 5 => '1234', 6 => 1234);
     $valuesReceived = array(1 => '1.234,57', 2 => '1.234,57', 3 => '1,23', 4 => '1,23', 5 => '1.234,00', 6 => '1.234,00');
     foreach ($valuesExpected as $key => $value) {
         $this->assertEquals($valuesReceived[$key], $filter->filter($value), 'failed filter of ' . var_export($value, 1));
     }
 }
Example #11
0
 /**
  * Convert dates with time in array from localized to internal format
  *
  * @param   array $array
  * @param $isDb
  * @internal param array $dateFields
  * @return  array
  */
 public static function filterDateTimeOnly($array, $isDb)
 {
     $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
     if (!$isDb) {
         $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATETIME_INTERNAL_FORMAT));
     } else {
         $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => 'yyyy-MM-dd HH:mm:ss'));
     }
     foreach ($array as $dateField => $val) {
         $array[$dateField] = $filterInput->filter($array[$dateField]);
         $array[$dateField] = $filterInternal->filter($array[$dateField]);
     }
     return $array;
 }
 public function getDay7()
 {
     $zv = new Zend_Filter_NormalizedToLocalized();
     return $zv->filter($this->_get('day_7'));
 }
 /**
  * Get localized Extra Percentage 
  */
 public function getExtraPercentage()
 {
     $zf = new Zend_Filter_NormalizedToLocalized();
     $price = $this->_get('extra_percentage');
     return $zf->filter($price);
 }
Example #14
0
 /**
  * Update product attributes
  *
  * @return void
  */
 public function execute()
 {
     if (!$this->_validateProducts()) {
         return;
     }
     /* Collect Data */
     $inventoryData = $this->getRequest()->getParam('inventory', array());
     $attributesData = $this->getRequest()->getParam('attributes', array());
     $websiteRemoveData = $this->getRequest()->getParam('remove_website_ids', array());
     $websiteAddData = $this->getRequest()->getParam('add_website_ids', array());
     /* Prepare inventory data item options (use config settings) */
     $options = $this->_objectManager->get('Magento\\CatalogInventory\\Helper\\Data')->getConfigItemOptions();
     foreach ($options as $option) {
         if (isset($inventoryData[$option]) && !isset($inventoryData['use_config_' . $option])) {
             $inventoryData['use_config_' . $option] = 0;
         }
     }
     try {
         if ($attributesData) {
             $dateFormat = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
             $storeId = $this->attributeHelper->getSelectedStoreId();
             foreach ($attributesData as $attributeCode => $value) {
                 $attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
                 if (!$attribute->getAttributeId()) {
                     unset($attributesData[$attributeCode]);
                     continue;
                 }
                 if ($attribute->getBackendType() == 'datetime') {
                     if (!empty($value)) {
                         $filterInput = new \Zend_Filter_LocalizedToNormalized(array('date_format' => $dateFormat));
                         $filterInternal = new \Zend_Filter_NormalizedToLocalized(array('date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT));
                         $value = $filterInternal->filter($filterInput->filter($value));
                     } else {
                         $value = null;
                     }
                     $attributesData[$attributeCode] = $value;
                 } elseif ($attribute->getFrontendInput() == 'multiselect') {
                     // Check if 'Change' checkbox has been checked by admin for this attribute
                     $isChanged = (bool) $this->getRequest()->getPost($attributeCode . '_checkbox');
                     if (!$isChanged) {
                         unset($attributesData[$attributeCode]);
                         continue;
                     }
                     if (is_array($value)) {
                         $value = implode(',', $value);
                     }
                     $attributesData[$attributeCode] = $value;
                 }
             }
             $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action')->updateAttributes($this->attributeHelper->getProductIds(), $attributesData, $storeId);
         }
         if ($inventoryData) {
             /** @var \Magento\CatalogInventory\Service\V1\StockItemService $stockItemService */
             $stockItemService = $this->_objectManager->create('Magento\\CatalogInventory\\Service\\V1\\StockItemService');
             foreach ($this->_helper->getProductIds() as $productId) {
                 $stockItemDo = $stockItemService->getStockItem($productId);
                 if (!$stockItemDo->getProductId()) {
                     $inventoryData[] = $productId;
                 }
                 $stockItemService->saveStockItem($this->stockItemBuilder->mergeDataObjectWithArray($stockItemDo, $inventoryData));
             }
             $this->_stockIndexerProcessor->reindexList($this->_helper->getProductIds());
         }
         if ($websiteAddData || $websiteRemoveData) {
             /* @var $actionModel \Magento\Catalog\Model\Product\Action */
             $actionModel = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action');
             $productIds = $this->attributeHelper->getProductIds();
             if ($websiteRemoveData) {
                 $actionModel->updateWebsites($productIds, $websiteRemoveData, 'remove');
             }
             if ($websiteAddData) {
                 $actionModel->updateWebsites($productIds, $websiteAddData, 'add');
             }
             $this->_eventManager->dispatch('catalog_product_to_website_change', array('products' => $productIds));
             $this->messageManager->addNotice(__('Please refresh "Catalog URL Rewrites" and "Product Attributes" in System -> ' . '<a href="%1">Index Management</a>.', $this->getUrl('adminhtml/process/list')));
         }
         $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', count($this->attributeHelper->getProductIds())));
         $this->_productFlatIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
         if ($this->_catalogProduct->isDataForPriceIndexerWasChanged($attributesData) || !empty($websiteRemoveData) || !empty($websiteAddData)) {
             $this->_productPriceIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
         }
     } catch (\Magento\Framework\Model\Exception $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
     }
     $this->_redirect('catalog/product/', array('store' => $this->attributeHelper->getSelectedStoreId()));
 }
Example #15
0
 /**
  * Convert date in from <$formatIn> to internal format
  *
  * @param   string $value
  * @param   string $formatIn    -  FORMAT_TYPE_FULL, FORMAT_TYPE_LONG, FORMAT_TYPE_MEDIUM, FORMAT_TYPE_SHORT
  * @return  string
  */
 public function _filterDate($value, $formatIn = false)
 {
     if ($formatIn === false) {
         return $value;
     } else {
         $formatIn = Mage::app()->getLocale()->getDateFormat($formatIn);
     }
     $filterInput = new Zend_Filter_LocalizedToNormalized(array('date_format' => $formatIn, 'locale' => Mage::app()->getLocale()->getLocaleCode()));
     $filterInternal = new Zend_Filter_NormalizedToLocalized(array('date_format' => Varien_Date::DATE_INTERNAL_FORMAT));
     $value = $filterInput->filter($value);
     $value = $filterInternal->filter($value);
     return $value;
 }
Example #16
0
 /**
  * Update product attributes
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function execute()
 {
     if (!$this->_validateProducts()) {
         return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
     }
     /* Collect Data */
     $inventoryData = $this->getRequest()->getParam('inventory', []);
     $attributesData = $this->getRequest()->getParam('attributes', []);
     $websiteRemoveData = $this->getRequest()->getParam('remove_website_ids', []);
     $websiteAddData = $this->getRequest()->getParam('add_website_ids', []);
     /* Prepare inventory data item options (use config settings) */
     $options = $this->_objectManager->get('Magento\\CatalogInventory\\Api\\StockConfigurationInterface')->getConfigItemOptions();
     foreach ($options as $option) {
         if (isset($inventoryData[$option]) && !isset($inventoryData['use_config_' . $option])) {
             $inventoryData['use_config_' . $option] = 0;
         }
     }
     try {
         $storeId = $this->attributeHelper->getSelectedStoreId();
         if ($attributesData) {
             $dateFormat = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getDateFormat(\IntlDateFormatter::SHORT);
             foreach ($attributesData as $attributeCode => $value) {
                 $attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
                 if (!$attribute->getAttributeId()) {
                     unset($attributesData[$attributeCode]);
                     continue;
                 }
                 if ($attribute->getBackendType() == 'datetime') {
                     if (!empty($value)) {
                         $filterInput = new \Zend_Filter_LocalizedToNormalized(['date_format' => $dateFormat]);
                         $filterInternal = new \Zend_Filter_NormalizedToLocalized(['date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT]);
                         $value = $filterInternal->filter($filterInput->filter($value));
                     } else {
                         $value = null;
                     }
                     $attributesData[$attributeCode] = $value;
                 } elseif ($attribute->getFrontendInput() == 'multiselect') {
                     // Check if 'Change' checkbox has been checked by admin for this attribute
                     $isChanged = (bool) $this->getRequest()->getPost($attributeCode . '_checkbox');
                     if (!$isChanged) {
                         unset($attributesData[$attributeCode]);
                         continue;
                     }
                     if (is_array($value)) {
                         $value = implode(',', $value);
                     }
                     $attributesData[$attributeCode] = $value;
                 }
             }
             $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action')->updateAttributes($this->attributeHelper->getProductIds(), $attributesData, $storeId);
         }
         if ($inventoryData) {
             // TODO why use ObjectManager?
             /** @var \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry */
             $stockRegistry = $this->_objectManager->create('Magento\\CatalogInventory\\Api\\StockRegistryInterface');
             /** @var \Magento\CatalogInventory\Api\StockItemRepositoryInterface $stockItemRepository */
             $stockItemRepository = $this->_objectManager->create('Magento\\CatalogInventory\\Api\\StockItemRepositoryInterface');
             foreach ($this->attributeHelper->getProductIds() as $productId) {
                 $stockItemDo = $stockRegistry->getStockItem($productId, $this->attributeHelper->getStoreWebsiteId($storeId));
                 if (!$stockItemDo->getProductId()) {
                     $inventoryData[] = $productId;
                 }
                 $stockItemId = $stockItemDo->getId();
                 $this->dataObjectHelper->populateWithArray($stockItemDo, $inventoryData, '\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterface');
                 $stockItemDo->setItemId($stockItemId);
                 $stockItemRepository->save($stockItemDo);
             }
             $this->_stockIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
         }
         if ($websiteAddData || $websiteRemoveData) {
             /* @var $actionModel \Magento\Catalog\Model\Product\Action */
             $actionModel = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action');
             $productIds = $this->attributeHelper->getProductIds();
             if ($websiteRemoveData) {
                 $actionModel->updateWebsites($productIds, $websiteRemoveData, 'remove');
             }
             if ($websiteAddData) {
                 $actionModel->updateWebsites($productIds, $websiteAddData, 'add');
             }
             $this->_eventManager->dispatch('catalog_product_to_website_change', ['products' => $productIds]);
         }
         $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', count($this->attributeHelper->getProductIds())));
         $this->_productFlatIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
         if ($this->_catalogProduct->isDataForPriceIndexerWasChanged($attributesData) || !empty($websiteRemoveData) || !empty($websiteAddData)) {
             $this->_productPriceIndexerProcessor->reindexList($this->attributeHelper->getProductIds());
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
     }
     return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['store' => $this->attributeHelper->getSelectedStoreId()]);
 }
 public function getPrice()
 {
     $zf = new Zend_Filter_NormalizedToLocalized();
     $price = $this->_get('price');
     return $zf->filter($price);
 }
Example #18
0
 /**
  * Format value according to attribute display options
  *
  * @param mixed $value The value to format
  *
  * @return string
  */
 private function formatValue($value)
 {
     $attribute = $this->getAttributeModel();
     if ((int) $attribute->getDisplayPrecision() > 0) {
         $locale = $this->localeResolver->getLocale();
         $options = ['locale' => $locale, 'precision' => (int) $attribute->getDisplayPrecision()];
         $valueFormatter = new \Zend_Filter_NormalizedToLocalized($options);
         $value = $valueFormatter->filter($value);
     }
     if ((string) $attribute->getDisplayPattern() != "") {
         $value = sprintf((string) $attribute->getDisplayPattern(), $value);
     }
     return $value;
 }
 /**
  * Get price (localized)
  * @return integer $price
  */
 public function getPrice()
 {
     $zendFilter = new Zend_Filter_NormalizedToLocalized();
     $price = $zendFilter->filter($this->_get('price'));
     return $price;
 }