Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for database file storage #75

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
${{entity}}Data = Mage::registry('current_{{entity}}')->getData();
$storeIds = ${{entity}}Data['store_id'];
for ($i = 0; $i < count($storeIds); ++$i) {
if ($storeIds[$i] == 0) {
$storeIds[$i] = 1;
}
}
$storeIds = array_unique($storeIds);
foreach ($storeIds as $storeId) {
$store = Mage::app()->getStore($storeId);
${{entity}} = Mage::registry('current_{{entity}}');
$linkToPreview = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
if ($prefix = Mage::getStoreConfig('{{namespace}}_{{module}}/{{entity}}/url_prefix')){
$linkToPreview .= $prefix.'/';
}
$linkToPreview .= ${{entity}}->getUrlKey();
if ($suffix = Mage::getStoreConfig('{{namespace}}_{{module}}/{{entity}}/url_suffix')){
$linkToPreview .= '.'.$suffix;
}
$linkToPreview .= '?mode=preview';
$fieldset->addField('preview-store-'.$storeId, 'link', array(
'label' => 'Preview for Store '.$store->getName(),
'href' => $linkToPreview,
'value' => 'Open preview',
'onclick' => 'window.open(\''.$linkToPreview.'\', \'_blank\'); return false;'
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
} elseif (Mage::registry('current_{{entity}}')) {
$formValues = array_merge($formValues, Mage::registry('current_{{entity}}')->getData());
}
$form->setValues($formValues);
$form->addValues($formValues);
return parent::_prepareForm();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$storeViewList = array();
$storeViewList['-1'] = Mage::helper('{{namespace}}_{{module}}')->__('Keep Existing');
foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $store) {
$storeViewList[$store->getId()] = $website->getName() . ' / ' . $group->getName() . ' / ' . $store->getName();
}
}
}
$this->getMassactionBlock()->addItem('copy_to_store_view', array(
'label' => Mage::helper('{{namespace}}_{{module}}')->__('Copy to store view'),
'url' => $this->getUrl('*/*/massCopyToStoreView', array('_current' => true)),
'additional' => array(
'store' => array(
'name' => 'storeview',
'type' => 'select',
'class' => 'required-entry',
'style' => 'max-width:100px',
'label' => Mage::helper('{{namespace}}_{{module}}')->__('Store View'),
'values' => $storeViewList
),
'suffix' => array(
'name' => 'suffix',
'type' => 'text',
'style' => 'width:50px',
'label' => Mage::helper('{{namespace}}_{{module}}')->__('Suffix for URL Key'),
)
)
));
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class {{Namespace}}_{{Module}}_Controller_Adminhtml_{{Module}} extends Mage_Admi
if (isset($data[$input]['delete'])) {
return '';
} else {
$uploader = new Varien_File_Uploader($input);
$uploader = new Mage_Core_Model_File_Uploader($input);
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$uploader->setAllowCreateFolders(true);
$result = $uploader->save($destinationFolder);
return $result['file'];
}
} catch (Exception $e) {
if ($e->getCode() != Varien_File_Uploader::TMP_NAME_EMPTY) {
if ($e->getCode() != Mage_Core_Model_Uploader::TMP_NAME_EMPTY) {
throw $e;
} else {
if (isset($data[$input]['value'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
$urlKey = substr($urlKey, 0, -strlen($settings['suffix']) - 1);
}
$model = Mage::getModel($settings->getModel());
$id = $model->checkUrlKey($urlKey, Mage::app()->getStore()->getId());
$isPreview = Mage::app()->getFrontController()->getRequest()->getParam('mode') == 'preview';
$id = $model->checkUrlKey($urlKey, Mage::app()->getStore()->getId(), !$isPreview);
if ($id) {
if ($settings->getCheckPath() && !$model->load($id)->getStatusPath()) {
if ($settings->getCheckPath() && !$model->load($id)->getStatusPath() && !$isPreview) {
continue;
}
$request->setModuleName('{{frontKey}}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ abstract class {{Namespace}}_{{Module}}_Helper_Image_Abstract extends Mage_Core_
$this->_resized = false;
$this->_adaptiveResize = 'center';

$imageFilePath = $this->getImageBaseDir().$this->_image;
if (!file_exists($imageFilePath)) {
Mage::helper('core/file_storage_database')->saveFileToFilesystem($imageFilePath);
}

try {
$this->_getImageProcessor()->open($this->getImageBaseDir().$this->_image);
$this->_getImageProcessor()->open($imageFilePath);
} catch (Exception $e) {
$this->_openError = $e->getMessage();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @return mixed
* {{qwertyuiop}}
*/
public function checkUrlKey($urlKey, $active = true)
public function checkUrlKey($urlKey, $storeId, $active = true)
{
return $this->_getResource()->checkUrlKey($urlKey, $active);
return $this->_getResource()->checkUrlKey($urlKey, $storeId, $active);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class {{Namespace}}_{{Module}}_Model_{{Entity}}_Attribute_Backend_File extends M
$path = Mage::helper('{{namespace}}_{{module}}/{{entity}}')->getFileBaseDir();

try {
$uploader = new Varien_File_Uploader($this->getAttribute()->getName());
$uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
//set allowed file extensions if you need
//$uploader->setAllowedExtensions(array('mp4', 'mov', 'f4v', 'flv'));
$uploader->setAllowRenameFiles(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class {{Namespace}}_{{Module}}_Model_{{Entity}}_Attribute_Backend_Image extends
$path = Mage::helper('{{namespace}}_{{module}}/{{entity}}_image')->getImageBaseDir();

try {
$uploader = new Varien_File_Uploader($this->getAttribute()->getName());
$uploader = new Mage_Core_Model_File_Uploader($this->getAttribute()->getName());
$uploader->setAllowRenameFiles(true);
$uploader->setFilesDispersion(true);
$result = $uploader->save($path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,59 @@
}
$this->_redirect('*/*/index');
}
/**
* mass copy to store view - action
*
* @access public
* @return void
* {{qwertyuiop}}
*/
public function massCopyToStoreViewAction() {
${{entity}}Ids = $this->getRequest()->getParam('{{entity}}');
$store = $this->getRequest()->getParam('storeview');
$suffix = $this->getRequest()->getParam('suffix');

if (!is_array(${{entity}}Ids)) {
$this->_getSession()->addError(
Mage::helper('{{namespace}}_{{module}}')->__('Please select {{entitiesLabel}}.')
);
} else {
try {
foreach (${{entity}}Ids as ${{entity}}Id) {
${{entity}} = Mage::getModel('{{namespace}}_{{module}}/{{entity}}')->load(${{entity}}Id);
$data = ${{entity}}->getData();
$selectedProductsFullInformation = ${{entity}}->getSelectedProducts();
$selectedProducts = array();
foreach ($selectedProductsFullInformation as $selectedProductsFullInformation) {
$selectedProduct = $selectedProductsFullInformation->getData();
$selectedProducts[$selectedProduct['entity_id']] = array(position => $selectedProduct['position']);
}
$selectedCategoriesFullInformation = ${{entity}}->getSelectedCategories();
$selectedCategories = array();
foreach ($selectedCategoriesFullInformation as $selectedCategoryFullInformation) {
$selectedCategory = $selectedCategoryFullInformation->getData();
$selectedCategories[] = $selectedCategory['entity_id'];
}
if ($store != -1) {
$data['store_id'] = array($store);
}
if (strlen($suffix) > 0) {
$data['url_key'] = $data['url_key'] . '-' . $suffix;
}
unset($data['entity_id'], $data['created_at'], $data['updated_at']);
$data['status'] = 0;
$model = Mage::getModel('{{namespace}}_{{module}}/{{entity}}');
$model->setData($data);
$model->setProductsData($selectedProducts);
$model->setCategoriesData($selectedCategories);
$model->save();
}
$this->_getSession()->addSuccess(
Mage::helper('{{namespace}}_{{module}}')->__('Total of %d {{entitiesLabel}} were successfully copied.', count(${{entity}}Ids))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage() . ' ' . Mage::helper('{{namespace}}_{{module}}')->__('There was an error copying {{entitiesLabel}}.'));
}
}
$this->_redirect('*/*/');
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
->load(${{entity}}Id);
if (!${{entity}}->getId()) {
return false;
} elseif (!${{entity}}->getStatus()) {
} elseif (!${{entity}}->getStatus() && $this->getRequest()->getParam('mode') != 'preview') {
return false;
}
return ${{entity}};
Expand All @@ -34,3 +34,6 @@
$this->_forward('no-route');
return;
}
if ($this->getRequest()->getParam('mode') == 'preview') {
$this->getResponse()->setHeader('HTTP/1.0', '404', true);
}
15 changes: 14 additions & 1 deletion app/code/community/Ultimate/ModuleCreator/etc/umc_source.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,12 @@
<depend>
<rss/>
</depend>
<sort_order>120</sort_order>
<sort_order>110</sort_order>
</rss>
<preview>
<name>115_preview</name>
<sort_order>115</sort_order>
</preview>
<stores>
<name>120_stores</name>
<depend>
Expand Down Expand Up @@ -1615,6 +1619,15 @@
<name>110_mass_action_top</name>
<sort_order>110</sort_order>
</mass_action_top>
<mass_action_copy_to_store_view>
<name>115_mass_action_copy_to_store_view</name>
<sort_order>115</sort_order>
<depend>
<is_flat/>
<not_is_tree/>
<store/>
</depend>
</mass_action_copy_to_store_view>
<mass_action_flags>
<name>120_mass_action_flags</name>
<scope>attribute</scope>
Expand Down