Skip to content

Commit

Permalink
Merge branch 'develop' for 1.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz-Silpion committed Apr 11, 2016
2 parents 7123f28 + 6a066e0 commit e2b93f3
Show file tree
Hide file tree
Showing 24 changed files with 1,819 additions and 389 deletions.
361 changes: 21 additions & 340 deletions LICENSE

Large diffs are not rendered by default.

54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# magento-LCB_Attachments
# LCB_Attachments
Magento attachments plugin with attachment type and multistore support


## Version

###1.2.0

## Changelog

### 1.1.0

* Added modman
* Fixed minor bugs, added new features

### 1.1.1

* Added download logic for attachments and images

### 1.1.2

* Added optional type of content display for categories

### 1.1.3

* Added support for attachments thumbnails/icons and Imagick support for pdf covers

### 1.1.4

* Fixed image logic, option for both attachments and images download

### 1.1.5

* Minor amends for downloads, pdf cover and Imagick exception support

### 1.1.6

* Added movies support and attachment image resize feature

### 1.1.7

* Added support for youtube downloads (based on Stephan Schmitz yt_downloader) and CSRF protection

### 1.1.8

* Added support for direct movie url render and download

### 1.1.9

* Added store filter for attachments category methods

### 1.2.0

* Store filter fixes for product tab. Version bump for 1.2.0 release
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function _prepareForm()
$fieldset->addField('file', 'file', array(
'label' => Mage::helper('lcb_attachments')->__('File'),
'name' => 'file',
'note' => '(*.pdf, *.txt, *.jpg, *.png, *.gif)',
'note' => '(*.pdf, *.txt, *.jpg, *.png, *.gif, *.mp4, *.avi)',
));

$fieldset->addField('category', 'select', array(
Expand All @@ -55,7 +55,6 @@ protected function _prepareForm()
'name' => 'stores[]',
'value' => Mage::app()->getStore(true)->getId()
));
$model->setStoreId(Mage::app()->getStore(true)->getId());
}

if (Mage::getSingleton("adminhtml/session")->getAttachmentData()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ protected function _prepareForm()
$this->setForm($form);
$fieldset = $form->addFieldset("attachments_form", array("legend" => Mage::helper("lcb_attachments")->__("Item information")));


$fieldset->addField("name", "text", array(
"label" => Mage::helper("lcb_attachments")->__("Name"),
"class" => 'required-entry',
"name" => "name",
));

$fieldset->addField('display', 'select', array(
"label" => Mage::helper("lcb_attachments")->__("Display"),
"values" => Mage::getModel('lcb_attachments/category')->getDisplayOptionArray(),
"name" => 'display',
));

if (Mage::getSingleton("adminhtml/session")->getCategoryData()) {
$form->setValues(Mage::getSingleton("adminhtml/session")->getCategoryData());
Expand Down
148 changes: 148 additions & 0 deletions app/code/community/LCB/Attachments/Block/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

/**
* Attachments
*
* @category LCB
* @package LCB_Attachments
* @author Silpion Tomasz Gregorczyk <[email protected]>
*/
class LCB_Attachments_Block_Index extends Mage_Core_Block_Template {

/**
* Get media images from products
*
* @return Varien_Data_Collection
*/
public function getProductImages()
{
$collection = new Varien_Data_Collection();

$categoryId = $this->getRequest()->getParam('category');
$subcategoryId = $this->getRequest()->getParam('subcategory');
$productId = $this->getRequest()->getParam('product');
$photoIds = $this->getRequest()->getParam('photos');

$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('small_image')
->addAttributeToSelect('thumbnail')
->addAttributeToSelect('image');
$products->addAttributeToFilter('small_image', array('neq' => "no_selection"));
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

if (!empty($categoryId) && empty($subcategoryId)) {
$category = Mage::getModel('catalog/category')->load($this->getRequest()->getParam('category'));
$products->addCategoryFilter($category);
}

if (!empty($subcategoryId)) {
$category = Mage::getModel('catalog/category')->load($this->getRequest()->getParam('subcategory'));
$products->addCategoryFilter($category);
}

if (!empty($productId)) {
$products->addAttributeToFilter('entity_id', array('in' => array($this->getRequest()->getParam('product'))));
}

if (empty($photoIds)) {
$products->getSelect()->order('RAND()');
$products->getSelect()->limit(16);
}

foreach ($products as $_product) {
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGalleryImages() as $image) {

if (!empty($photoIds)) {
if (!in_array($image->getId(), $photoIds)) {
continue;
}
}

if (!$image->getLabel()) {
$image->setLabel($product->getName());
}

$mime = pathinfo($image->getPath(), PATHINFO_EXTENSION);
$image->setMime($mime);

$filesize = filesize($image->getPath()) * .0009765625; // bytes to KB
$image->setSize(round($filesize));

$collection->addItem($image);
}
}

return $collection;
}

/**
* Get categories to populate first select
*
* @return Mage_Catalog_Model_Resource_Category_Collection $categories
*/
public function getCategories()
{
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('level', 2)
->addAttributeToFilter('is_active', 1);
return $categories;
}

/**
* Get subcategories to populate second select
*
* @return mixed array|Mage_Catalog_Model_Resource_Category_Collection $categories
*/
public function getSubcategories()
{
if (!$this->getRequest()->getParam('category')) {
return array();
}

$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('level', 3)
->addAttributeToFilter('parent_id', $this->getRequest()->getParam('category'))
->addAttributeToFilter('is_active', 1);
return $categories;
}

/**
* Get subcategories to populate second select
*
* @return mixed array|Mage_Catalog_Model_Resource_Product_Collection $products
*/
public function getProducts()
{
if (!$this->getRequest()->getParam('subcategory')) {
return array();
}

$products = Mage::getModel('catalog/category')->load($this->getRequest()->getParam('subcategory'))
->getProductCollection()
->addAttributeToSelect('*');
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
$products->getSelect()->limit(240);
return $products;
}

/**
* Get attachments within specific category id
*
* @param int $categoryId
* @return LCB_Attachments_Model_Resource_Attachment_Collection $attachments
*/
public function getAttachments($categoryId, $store = false)
{
$attachments = Mage::getModel('lcb_attachments/category')->load($categoryId)->getAttachments();
if ($store) {
$attachments->addStoreFilter($store);
}
return $attachments;
}

}
14 changes: 12 additions & 2 deletions app/code/community/LCB/Attachments/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ public function getProductTab()
{
$product = Mage::registry('current_product');
if ($product && $product->getId()) {
$attachment = Mage::getModel('lcb_attachments/product')->load($product->getId(), 'product_id');
if ($attachment->getId()) {
$data = Mage::getModel('lcb_attachments/product')->load($product->getId(), 'product_id');
if ($data->getId()) {
return 'lcb/attachments/catalog/product/tab.phtml';
}
}

return false;
}

/**
* Get all attachments categories
*
* @return LCB_Attachments_Model_Resource_Category_Collection
*/
public function getCategories()
{
return Mage::getModel('lcb_attachments/category')->getCollection();
}

}
Loading

0 comments on commit e2b93f3

Please sign in to comment.