Version Notes
This extension will automatically add/remove products with special price into a Sale or Offer category according to the date specified.
Supports:
MultiStore
Product import.
Features:
Mail Notification
Cron Job
Download this release
Release Info
Developer | Manu Jose |
Extension | Automatic_Sale_Category |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Manu/Saleproducts/Block/Saleproducts.php +13 -0
- app/code/community/Manu/Saleproducts/Helper/Data.php +13 -0
- app/code/community/Manu/Saleproducts/Model/Category.php +31 -0
- app/code/community/Manu/Saleproducts/Model/Observer.php +139 -0
- app/code/community/Manu/Saleproducts/controllers/Catalog/ProductController.php +271 -0
- app/code/community/Manu/Saleproducts/etc/config.xml +93 -0
- app/code/community/Manu/Saleproducts/etc/system.xml +63 -0
- app/etc/modules/Manu_Saleproducts.xml +17 -0
- package.xml +31 -0
app/code/community/Manu/Saleproducts/Block/Saleproducts.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Product list
|
5 |
+
*
|
6 |
+
* @category Manu
|
7 |
+
* @package Manu_Saleproducts
|
8 |
+
* @author Manu Jose K
|
9 |
+
*/
|
10 |
+
class Manu_Saleproducts_Block_Saleproducts extends Mage_Catalog_Block_Product_List {
|
11 |
+
|
12 |
+
}
|
13 |
+
|
app/code/community/Manu/Saleproducts/Helper/Data.php
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Product list
|
4 |
+
*
|
5 |
+
* @category Manu
|
6 |
+
* @package Manu_Saleproducts
|
7 |
+
* @author Manu Jose K
|
8 |
+
*/
|
9 |
+
|
10 |
+
class Manu_Saleproducts_Helper_Data extends Mage_Core_Helper_Abstract
|
11 |
+
{
|
12 |
+
|
13 |
+
}
|
app/code/community/Manu/Saleproducts/Model/Category.php
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Product list
|
4 |
+
*
|
5 |
+
* @category Manu
|
6 |
+
* @package Manu_Saleproducts
|
7 |
+
* @author Manu Jose K
|
8 |
+
*/
|
9 |
+
class Manu_Saleproducts_Model_Category {
|
10 |
+
|
11 |
+
public function getCategories()
|
12 |
+
{
|
13 |
+
$categoryOption = array();
|
14 |
+
$categories = Mage::getModel('catalog/category')->getCollection()
|
15 |
+
->addAttributeToSelect('name')
|
16 |
+
->addAttributeToFilter('level', array('eq' => '2'))
|
17 |
+
->load();
|
18 |
+
foreach ($categories as $cat):
|
19 |
+
$temp = array('value' => $cat->getName(), 'label' => $cat->getName().' ( Root Category : '.$cat->getParentCategory()->getName().' ) ' );
|
20 |
+
array_push($categoryOption, $temp);
|
21 |
+
endforeach;
|
22 |
+
return $categoryOption;
|
23 |
+
}
|
24 |
+
|
25 |
+
public function toOptionArray()
|
26 |
+
{
|
27 |
+
return ($this->getCategories());
|
28 |
+
}
|
29 |
+
|
30 |
+
}
|
31 |
+
?>
|
app/code/community/Manu/Saleproducts/Model/Observer.php
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Product list
|
4 |
+
*
|
5 |
+
* @category Manu
|
6 |
+
* @package Manu_Saleproducts
|
7 |
+
* @author Manu Jose K
|
8 |
+
*/
|
9 |
+
|
10 |
+
class Manu_Saleproducts_Model_Observer {
|
11 |
+
/*
|
12 |
+
* Cron job for every day.
|
13 |
+
* Functionality:Remove all products from Sale category when special price date ends.
|
14 |
+
* Notification:send mail to the store owner with list of removed products.
|
15 |
+
*
|
16 |
+
*/
|
17 |
+
|
18 |
+
public function removeOfferProducts()
|
19 |
+
{
|
20 |
+
|
21 |
+
$mailContent = array();
|
22 |
+
$sales;
|
23 |
+
$i = 0;
|
24 |
+
$categories = Mage::getModel('catalog/category')->getCollection()
|
25 |
+
->addAttributeToFilter('name', Mage::getStoreConfig('sale_category/general/offer_category'))
|
26 |
+
->addAttributeToSelect('id')
|
27 |
+
->load();
|
28 |
+
foreach ($categories as $product)
|
29 |
+
{ //loop for getting products
|
30 |
+
$sales[$i] = $product->getId();
|
31 |
+
$i++;
|
32 |
+
}
|
33 |
+
$categoryCollection = Mage::getModel('catalog/category')->getCollection()
|
34 |
+
->addAttributeToSelect('id')
|
35 |
+
->load();
|
36 |
+
foreach ($categoryCollection as $cat):
|
37 |
+
|
38 |
+
$currentCategoryId = $cat->getId();
|
39 |
+
if (in_array($currentCategoryId, $sales))
|
40 |
+
{
|
41 |
+
$todayDate = date('m/d/y');
|
42 |
+
$yesterday = mktime(0, 0, 0, date('m'), date('d') - 1, date('y'));
|
43 |
+
$yesterdayDate = date('m/d/y', $yesterday);
|
44 |
+
$catagoryModel = Mage::getModel('catalog/category')->load($currentCategoryId);
|
45 |
+
$productCollection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('name')->addCategoryFilter($catagoryModel);
|
46 |
+
$productCollection->addAttributeToFilter('special_to_date', array('date' => true, 'to' => $yesterdayDate));
|
47 |
+
$currentStoreID = Mage::app()->getStore()->getId();
|
48 |
+
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
|
49 |
+
foreach ($productCollection as $currentProduct)
|
50 |
+
{
|
51 |
+
array_push($mailContent, $currentProduct->getName());
|
52 |
+
$categoryIds = $currentProduct->getCategoryIds();
|
53 |
+
$categoryIds = str_replace($currentCategoryId, "", $categoryIds);
|
54 |
+
$currentProduct->setCategoryIds($categoryIds);
|
55 |
+
$currentProduct->save();
|
56 |
+
}
|
57 |
+
Mage::app()->setCurrentStore($currentStoreID);
|
58 |
+
}
|
59 |
+
|
60 |
+
endforeach;
|
61 |
+
if (Mage::getStoreConfig('sale_category/general/offer_mail'))
|
62 |
+
{
|
63 |
+
$newContent = "Following products are removed from Sale/Offer Category due to the end of special price date.\r\n
|
64 |
+
This mail was generated by a cron job.<br/> You can turn of this mail notification in system->config->catalog->Sale / Offer";
|
65 |
+
$headers = "MIME-Version: 1.0" . "\r\n";
|
66 |
+
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
|
67 |
+
$headers .= 'From: <' . Mage::getStoreConfig('general/store_information/name') . '@magento.com>';
|
68 |
+
$mailContent = array_unique($mailContent);
|
69 |
+
foreach ($mailContent as $value)
|
70 |
+
{
|
71 |
+
$newContent = $newContent . "\r\n" . $value;
|
72 |
+
}
|
73 |
+
mail(Mage::getStoreConfig('trans_email/ident_general/email'), "Removed Products", $newContent, $headers);
|
74 |
+
}
|
75 |
+
$this->saleProductsImport(TRUE);
|
76 |
+
}
|
77 |
+
|
78 |
+
public function saleProductsImport($cron=null)
|
79 |
+
{
|
80 |
+
if (Mage::getStoreConfig('sale_category/general/offer_cron') || isset($cron))
|
81 |
+
{
|
82 |
+
$mailContent = array();
|
83 |
+
$categories = Mage::getModel('catalog/category')->getCollection()
|
84 |
+
->addAttributeToSelect('id')
|
85 |
+
->addAttributeToSelect('name')
|
86 |
+
->addAttributeToFilter('is_active', array('eq' => true))
|
87 |
+
->addAttributeToFilter('level', array('eq' => '1'))
|
88 |
+
->load();
|
89 |
+
echo '<pre/>';
|
90 |
+
foreach ($categories as $value)
|
91 |
+
{
|
92 |
+
$categoriesColl = Mage::getModel('catalog/category')->getCollection()
|
93 |
+
->addAttributeToFilter('name', Mage::getStoreConfig('sale_category/general/offer_category'))
|
94 |
+
->addAttributeToSelect('id')
|
95 |
+
->addAttributeToSelect('name')
|
96 |
+
->load($value['id']);
|
97 |
+
}
|
98 |
+
foreach ($categoriesColl as $value)
|
99 |
+
{
|
100 |
+
echo $value['entity_id'];
|
101 |
+
$todayDate = date('m/d/y');
|
102 |
+
$productCollection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('name');
|
103 |
+
$productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'from' => $todayDate));
|
104 |
+
foreach ($productCollection as $currentProduct)
|
105 |
+
{
|
106 |
+
|
107 |
+
$categoryIds = $currentProduct->getCategoryIds();
|
108 |
+
if (!in_array($value['entity_id'], $categoryIds))
|
109 |
+
{
|
110 |
+
echo "already in array";
|
111 |
+
array_push($categoryIds, $value['entity_id']);
|
112 |
+
array_push($mailContent, $currentProduct->getName());
|
113 |
+
}
|
114 |
+
$currentProduct->setCategoryIds($categoryIds);
|
115 |
+
$currentProduct->save();
|
116 |
+
print_r($categoryIds);
|
117 |
+
echo $currentProduct['name'];
|
118 |
+
}
|
119 |
+
echo '<br/>hiiii<br/>';
|
120 |
+
}
|
121 |
+
if (Mage::getStoreConfig('sale_category/general/offer_mail'))
|
122 |
+
{
|
123 |
+
$newContent = "Following products are Added to Sale/Offer Category by a cron job.<br/> You can turn of this mail notification in system->config->catalog->Sale / Offer\r\n";
|
124 |
+
$headers = "MIME-Version: 1.0" . "\r\n";
|
125 |
+
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
|
126 |
+
$headers .= 'From: <' . Mage::getStoreConfig('general/store_information/name') . '@magento.com>';
|
127 |
+
$mailContent = array_unique($mailContent);
|
128 |
+
foreach ($mailContent as $value)
|
129 |
+
{
|
130 |
+
$newContent = $newContent . "\r\n" . $value;
|
131 |
+
}
|
132 |
+
mail(Mage::getStoreConfig('trans_email/ident_general/email'), "Product Added to offer Category", $newContent, $headers);
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
}
|
138 |
+
|
139 |
+
?>
|
app/code/community/Manu/Saleproducts/controllers/Catalog/ProductController.php
ADDED
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Product list
|
4 |
+
*
|
5 |
+
* @category Manu
|
6 |
+
* @package Manu_Saleproducts
|
7 |
+
* @author Manu Jose K
|
8 |
+
*/
|
9 |
+
|
10 |
+
|
11 |
+
include_once("Mage/Adminhtml/controllers/Catalog/ProductController.php");
|
12 |
+
|
13 |
+
class Manu_Saleproducts_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController {
|
14 |
+
|
15 |
+
protected function _initProductSave() {
|
16 |
+
$product = $this->_initProduct();
|
17 |
+
$productData = $this->getRequest()->getPost('product');
|
18 |
+
if ($productData) {
|
19 |
+
if (!isset($productData['stock_data']['use_config_manage_stock'])) {
|
20 |
+
$productData['stock_data']['use_config_manage_stock'] = 0;
|
21 |
+
}
|
22 |
+
if (isset($productData['stock_data']['qty']) && (float) $productData['stock_data']['qty'] > self::MAX_QTY_VALUE) {
|
23 |
+
$productData['stock_data']['qty'] = self::MAX_QTY_VALUE;
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Websites
|
29 |
+
*/
|
30 |
+
if (!isset($productData['website_ids'])) {
|
31 |
+
$productData['website_ids'] = array();
|
32 |
+
}
|
33 |
+
|
34 |
+
$wasLockedMedia = false;
|
35 |
+
if ($product->isLockedAttribute('media')) {
|
36 |
+
$product->unlockAttribute('media');
|
37 |
+
$wasLockedMedia = true;
|
38 |
+
}
|
39 |
+
|
40 |
+
$product->addData($productData);
|
41 |
+
|
42 |
+
if ($wasLockedMedia) {
|
43 |
+
$product->lockAttribute('media');
|
44 |
+
}
|
45 |
+
|
46 |
+
if (Mage::app()->isSingleStoreMode()) {
|
47 |
+
$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Create Permanent Redirect for old URL key
|
52 |
+
*/
|
53 |
+
if ($product->getId() && isset($productData['url_key_create_redirect'])) {
|
54 |
+
// && $product->getOrigData('url_key') != $product->getData('url_key')
|
55 |
+
$product->setData('save_rewrites_history', (bool) $productData['url_key_create_redirect']);
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Check "Use Default Value" checkboxes values
|
60 |
+
*/
|
61 |
+
if ($useDefaults = $this->getRequest()->getPost('use_default')) {
|
62 |
+
foreach ($useDefaults as $attributeCode) {
|
63 |
+
$product->setData($attributeCode, false);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Init product links data (related, upsell, crosssel)
|
69 |
+
*/
|
70 |
+
$links = $this->getRequest()->getPost('links');
|
71 |
+
if (isset($links['related']) && !$product->getRelatedReadonly()) {
|
72 |
+
$product->setRelatedLinkData(Mage::helper('adminhtml/js')->decodeGridSerializedInput($links['related']));
|
73 |
+
}
|
74 |
+
if (isset($links['upsell']) && !$product->getUpsellReadonly()) {
|
75 |
+
$product->setUpSellLinkData(Mage::helper('adminhtml/js')->decodeGridSerializedInput($links['upsell']));
|
76 |
+
}
|
77 |
+
if (isset($links['crosssell']) && !$product->getCrosssellReadonly()) {
|
78 |
+
$product->setCrossSellLinkData(Mage::helper('adminhtml/js')
|
79 |
+
->decodeGridSerializedInput($links['crosssell']));
|
80 |
+
}
|
81 |
+
if (isset($links['grouped']) && !$product->getGroupedReadonly()) {
|
82 |
+
$product->setGroupedLinkData(Mage::helper('adminhtml/js')->decodeGridSerializedInput($links['grouped']));
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Initialize product categories
|
87 |
+
*/
|
88 |
+
/**
|
89 |
+
* Overriding core functionality-atomatically adds products to sale category
|
90 |
+
*/
|
91 |
+
$datasale = $this->getRequest()->getPost();
|
92 |
+
$categoryIds = $this->getRequest()->getPost('category_ids');
|
93 |
+
/**
|
94 |
+
* if categories are null in posted data, then retriving from model
|
95 |
+
*/
|
96 |
+
if (null == $categoryIds) {
|
97 |
+
$productId = $this->getRequest()->getParam('id');
|
98 |
+
$productModel = Mage::getModel('catalog/product')->load($productId);
|
99 |
+
$cats_ids = $productModel->getCategoryIds($productId);
|
100 |
+
$categoryIds = implode($cats_ids, ",");
|
101 |
+
}
|
102 |
+
$sales= array();
|
103 |
+
$i = 0;
|
104 |
+
$categories = Mage::getModel('catalog/category')->getCollection()
|
105 |
+
->addAttributeToFilter('name', Mage::getStoreConfig('sale_category/general/offer_category'))
|
106 |
+
->addAttributeToSelect('id')
|
107 |
+
->load();
|
108 |
+
foreach ($categories as $productcategory) {
|
109 |
+
$sales[$i] = $productcategory->getId();
|
110 |
+
$i++;
|
111 |
+
}
|
112 |
+
$todayDate = date('d/m/Y');
|
113 |
+
$data = $this->getRequest()->getPost();
|
114 |
+
$websiteId = $datasale['product']['website_ids'];
|
115 |
+
foreach ($websiteId as $siteId) {
|
116 |
+
if ($datasale['product']['special_price']) {
|
117 |
+
|
118 |
+
if($data['product']['special_from_date']=="")
|
119 |
+
$data['product']['special_from_date']=$todayDate;
|
120 |
+
if(($data['product']['special_from_date'] <= $todayDate) && ($data['product']['special_from_date']<=$data['product']['special_to_date'] || $data['product']['special_to_date']=="") && ($data['product']['special_to_date']>=$todayDate || $data['product']['special_to_date']=="") )
|
121 |
+
$categoryIds = $categoryIds . "," . $sales[$siteId - 1];
|
122 |
+
else
|
123 |
+
$categoryIds = str_replace($sales[$siteId - 1], "", $categoryIds);
|
124 |
+
|
125 |
+
|
126 |
+
} else {
|
127 |
+
$categoryIds = str_replace($sales[$siteId - 1], "", $categoryIds);
|
128 |
+
}
|
129 |
+
}
|
130 |
+
$websiteCount = Mage::app()->getWebsites();
|
131 |
+
for ($i = 1; $i <= count($websiteCount); $i++) {
|
132 |
+
if (!in_array($i, $websiteId)) {
|
133 |
+
$categoryIds = str_replace($sales[$i - 1], "", $categoryIds);
|
134 |
+
}
|
135 |
+
}
|
136 |
+
if (null !== $categoryIds) {
|
137 |
+
if (empty($categoryIds)) {
|
138 |
+
$categoryIds = array();
|
139 |
+
}
|
140 |
+
$product->setCategoryIds($categoryIds);
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Initialize data for configurable product
|
145 |
+
*/
|
146 |
+
if (($data = $this->getRequest()->getPost('configurable_products_data'))
|
147 |
+
&& !$product->getConfigurableReadonly()
|
148 |
+
) {
|
149 |
+
$product->setConfigurableProductsData(Mage::helper('core')->jsonDecode($data));
|
150 |
+
}
|
151 |
+
if (($data = $this->getRequest()->getPost('configurable_attributes_data'))
|
152 |
+
&& !$product->getConfigurableReadonly()
|
153 |
+
) {
|
154 |
+
$product->setConfigurableAttributesData(Mage::helper('core')->jsonDecode($data));
|
155 |
+
}
|
156 |
+
|
157 |
+
$product->setCanSaveConfigurableAttributes(
|
158 |
+
(bool) $this->getRequest()->getPost('affect_configurable_product_attributes')
|
159 |
+
&& !$product->getConfigurableReadonly()
|
160 |
+
);
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Initialize product options
|
164 |
+
*/
|
165 |
+
if (isset($productData['options']) && !$product->getOptionsReadonly()) {
|
166 |
+
$product->setProductOptions($productData['options']);
|
167 |
+
}
|
168 |
+
|
169 |
+
$product->setCanSaveCustomOptions(
|
170 |
+
(bool) $this->getRequest()->getPost('affect_product_custom_options')
|
171 |
+
&& !$product->getOptionsReadonly()
|
172 |
+
);
|
173 |
+
|
174 |
+
Mage::dispatchEvent(
|
175 |
+
'catalog_product_prepare_save', array('product' => $product, 'request' => $this->getRequest())
|
176 |
+
);
|
177 |
+
|
178 |
+
return $product;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Save product action
|
183 |
+
*/
|
184 |
+
public function saveAction() {
|
185 |
+
|
186 |
+
/**
|
187 |
+
* Overriding core functionality-atomatically adds products to sale category
|
188 |
+
*/
|
189 |
+
$sales= array ();
|
190 |
+
$i = 0;
|
191 |
+
$categories = Mage::getModel('catalog/category')->getCollection()
|
192 |
+
->addAttributeToFilter('name', Mage::getStoreConfig('sale_category/general/offer_category'))
|
193 |
+
->addAttributeToSelect('id')
|
194 |
+
->load();
|
195 |
+
foreach ($categories as $product) { //loop for getting products
|
196 |
+
$sales[$i] = $product->getId();
|
197 |
+
$i++;
|
198 |
+
}
|
199 |
+
$storeId = $this->getRequest()->getParam('store');
|
200 |
+
$redirectBack = $this->getRequest()->getParam('back', false);
|
201 |
+
$productId = $this->getRequest()->getParam('id');
|
202 |
+
$isEdit = (int) ($this->getRequest()->getParam('id') != null);
|
203 |
+
$categoryId_Sale = ",";
|
204 |
+
$categorySale = ",";
|
205 |
+
$data = $this->getRequest()->getPost();
|
206 |
+
$websiteId = $data['product']['website_ids'];
|
207 |
+
foreach ($websiteId as $siteId) {
|
208 |
+
if ($data['product']['special_price']) {
|
209 |
+
$categorySale = $categorySale . "," . $sales[$siteId - 1] . "," . $sales[$siteId - 1];
|
210 |
+
} else {
|
211 |
+
$categoryId_Sale = $categoryId_Sale . "," . $sales[$siteId - 1];
|
212 |
+
}
|
213 |
+
}
|
214 |
+
|
215 |
+
// $data['category_ids'] = $data['category_ids'] . $categorySale . $categoryId_Sale;
|
216 |
+
if ($data) {
|
217 |
+
if (!isset($data['product']['stock_data']['use_config_manage_stock'])) {
|
218 |
+
$data['product']['stock_data']['use_config_manage_stock'] = 0;
|
219 |
+
}
|
220 |
+
$product = $this->_initProductSave();
|
221 |
+
|
222 |
+
try {
|
223 |
+
$product->save();
|
224 |
+
$productId = $product->getId();
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Do copying data to stores
|
228 |
+
*/
|
229 |
+
if (isset($data['copy_to_stores'])) {
|
230 |
+
foreach ($data['copy_to_stores'] as $storeTo => $storeFrom) {
|
231 |
+
$newProduct = Mage::getModel('catalog/product')
|
232 |
+
->setStoreId($storeFrom)
|
233 |
+
->load($productId)
|
234 |
+
->setStoreId($storeTo)
|
235 |
+
->save();
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
Mage::getModel('catalogrule/rule')->applyAllRulesToProduct($productId);
|
240 |
+
|
241 |
+
$this->_getSession()->addSuccess($this->__('The product has been saved.'));
|
242 |
+
} catch (Mage_Core_Exception $e) {
|
243 |
+
$this->_getSession()->addError($e->getMessage())
|
244 |
+
->setProductData($data);
|
245 |
+
$redirectBack = true;
|
246 |
+
} catch (Exception $e) {
|
247 |
+
Mage::logException($e);
|
248 |
+
$this->_getSession()->addError($e->getMessage());
|
249 |
+
$redirectBack = true;
|
250 |
+
}
|
251 |
+
}
|
252 |
+
|
253 |
+
if ($redirectBack) {
|
254 |
+
$this->_redirect('*/*/edit', array(
|
255 |
+
'id' => $productId,
|
256 |
+
'_current' => true
|
257 |
+
));
|
258 |
+
} elseif ($this->getRequest()->getParam('popup')) {
|
259 |
+
$this->_redirect('*/*/created', array(
|
260 |
+
'_current' => true,
|
261 |
+
'id' => $productId,
|
262 |
+
'edit' => $isEdit
|
263 |
+
));
|
264 |
+
} else {
|
265 |
+
$this->_redirect('*/*/', array('store' => $storeId));
|
266 |
+
}
|
267 |
+
}
|
268 |
+
|
269 |
+
}
|
270 |
+
|
271 |
+
?>
|
app/code/community/Manu/Saleproducts/etc/config.xml
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* @category Manu
|
5 |
+
* @package Manu_Saleproducts
|
6 |
+
* @author Manu
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
-->
|
10 |
+
<config>
|
11 |
+
<modules>
|
12 |
+
<Manu_Saleproducts>
|
13 |
+
<version>0.1.0</version>
|
14 |
+
</Manu_Saleproducts>
|
15 |
+
</modules>
|
16 |
+
<frontend>
|
17 |
+
<routers>
|
18 |
+
<catalog>
|
19 |
+
<args>
|
20 |
+
<modules>
|
21 |
+
<Manu_Saleproducts before="Mage_Catalog">Manu_Saleproducts_Catalog</Manu_Saleproducts>
|
22 |
+
</modules>
|
23 |
+
</args>
|
24 |
+
</catalog>
|
25 |
+
</routers>
|
26 |
+
</frontend>
|
27 |
+
<admin>
|
28 |
+
<routers>
|
29 |
+
<adminhtml>
|
30 |
+
<args>
|
31 |
+
<modules>
|
32 |
+
<Manu_Saleproducts before="Mage_Adminhtml">Manu_Saleproducts</Manu_Saleproducts>
|
33 |
+
</modules>
|
34 |
+
</args>
|
35 |
+
</adminhtml>
|
36 |
+
</routers>
|
37 |
+
</admin>
|
38 |
+
<global>
|
39 |
+
<events>
|
40 |
+
<catalog_product_import_finish_before>
|
41 |
+
<observers>
|
42 |
+
<Manu_Saleproducts>
|
43 |
+
<type>singleton</type>
|
44 |
+
<class>Manu_Saleproducts_Model_Observer</class>
|
45 |
+
<method>saleProductsImport</method>
|
46 |
+
</Manu_Saleproducts>
|
47 |
+
</observers>
|
48 |
+
</catalog_product_import_finish_before>
|
49 |
+
|
50 |
+
</events>
|
51 |
+
<models>
|
52 |
+
|
53 |
+
<Saleproducts>
|
54 |
+
<class>Manu_Saleproducts_Model</class>
|
55 |
+
</Saleproducts>
|
56 |
+
|
57 |
+
</models>
|
58 |
+
<helpers>
|
59 |
+
<Saleproducts>
|
60 |
+
<class>Manu_Saleproducts_Helper</class>
|
61 |
+
</Saleproducts>
|
62 |
+
</helpers>
|
63 |
+
</global>
|
64 |
+
<adminhtml>
|
65 |
+
<acl>
|
66 |
+
<resources>
|
67 |
+
<admin>
|
68 |
+
<children>
|
69 |
+
<system>
|
70 |
+
<children>
|
71 |
+
<config>
|
72 |
+
<children>
|
73 |
+
<sale_category>
|
74 |
+
<title>Manu Sale Products</title>
|
75 |
+
</sale_category>
|
76 |
+
</children>
|
77 |
+
</config>
|
78 |
+
</children>
|
79 |
+
</system>
|
80 |
+
</children>
|
81 |
+
</admin>
|
82 |
+
</resources>
|
83 |
+
</acl>
|
84 |
+
</adminhtml>
|
85 |
+
<crontab>
|
86 |
+
<jobs>
|
87 |
+
<remove_offer_products>
|
88 |
+
<schedule><cron_expr>0 19 * * *</cron_expr></schedule>
|
89 |
+
<run><model>Saleproducts/observer::removeOfferProducts</model></run>
|
90 |
+
</remove_offer_products>
|
91 |
+
</jobs>
|
92 |
+
</crontab>
|
93 |
+
</config>
|
app/code/community/Manu/Saleproducts/etc/system.xml
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
|
3 |
+
<config>
|
4 |
+
<sections>
|
5 |
+
<sale_category translate="label" >
|
6 |
+
<label>Sale / Offers Category</label>
|
7 |
+
<tab>catalog</tab>
|
8 |
+
<frontend_type>text</frontend_type>
|
9 |
+
<sort_order>90</sort_order>
|
10 |
+
<show_in_default>1</show_in_default>
|
11 |
+
<show_in_website>1</show_in_website>
|
12 |
+
<show_in_store>1</show_in_store>
|
13 |
+
<groups>
|
14 |
+
<general translate="label">
|
15 |
+
<label>Sale / Offers Category Settings</label>
|
16 |
+
<frontend_type>text</frontend_type>
|
17 |
+
<sort_order>1</sort_order>
|
18 |
+
<show_in_default>1</show_in_default>
|
19 |
+
<show_in_website>1</show_in_website>
|
20 |
+
<show_in_store>1</show_in_store>
|
21 |
+
<fields>
|
22 |
+
<offer_category translate="label">
|
23 |
+
<label>Sale/Offer Category</label>
|
24 |
+
<comment><![CDATA[This category should be in category list.Give the name as it in the product category.
|
25 |
+
Product with Special price in other categories will automatically added to this category.
|
26 |
+
(Please consider the letter case.)]]></comment>
|
27 |
+
<frontend_type>select</frontend_type>
|
28 |
+
<source_model>Saleproducts/category</source_model>
|
29 |
+
<sort_order>3</sort_order>
|
30 |
+
<show_in_default>1</show_in_default>
|
31 |
+
<show_in_website>1</show_in_website>
|
32 |
+
<show_in_store>1</show_in_store>
|
33 |
+
</offer_category>
|
34 |
+
<offer_mail translate="label">
|
35 |
+
<label>Mail Notification.</label>
|
36 |
+
<comment><![CDATA[This option will send a mail to the store email id with the products removed from
|
37 |
+
Offer/Sale category.The product is only removed from the above category after the special price date ends]]></comment>
|
38 |
+
<frontend_type>select</frontend_type>
|
39 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
40 |
+
<sort_order>10</sort_order>
|
41 |
+
<show_in_default>1</show_in_default>
|
42 |
+
<show_in_website>1</show_in_website>
|
43 |
+
<show_in_store>1</show_in_store>
|
44 |
+
</offer_mail>
|
45 |
+
<offer_cron translate="label">
|
46 |
+
<label>Cron job after every Import.</label>
|
47 |
+
<comment><![CDATA[A cron job will run immediately after every product import.All product will be checked for special price
|
48 |
+
and will add to sale/offer category.]]></comment>
|
49 |
+
<frontend_type>select</frontend_type>
|
50 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
51 |
+
<sort_order>10</sort_order>
|
52 |
+
<show_in_default>1</show_in_default>
|
53 |
+
<show_in_website>1</show_in_website>
|
54 |
+
<show_in_store>1</show_in_store>
|
55 |
+
</offer_cron>
|
56 |
+
</fields>
|
57 |
+
</general>
|
58 |
+
|
59 |
+
</groups>
|
60 |
+
|
61 |
+
</sale_category>
|
62 |
+
</sections>
|
63 |
+
</config>
|
app/etc/modules/Manu_Saleproducts.xml
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* @category Community
|
5 |
+
* @package Manu_Saleproducts
|
6 |
+
* @author Manu
|
7 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
8 |
+
*/
|
9 |
+
-->
|
10 |
+
<config>
|
11 |
+
<modules>
|
12 |
+
<Manu_Saleproducts>
|
13 |
+
<active>true</active>
|
14 |
+
<codePool>community</codePool>
|
15 |
+
</Manu_Saleproducts>
|
16 |
+
</modules>
|
17 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Automatic_Sale_Category</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Simple extension, automatically add products with special price to Sale or Offer category.</summary>
|
10 |
+
<description>This extension will automatically add/remove products with special price into a Sale or Offer category according to the date specified. Daily Cron job to add or remove products from sale category. This extension also supports product import. If special price added in import csv, the product will automatically add to sale category.Administrator can create new category or existing category as sale category. 
|
11 |
+

|
12 |
+

|
13 |
+

|
14 |
+
</description>
|
15 |
+
<notes>This extension will automatically add/remove products with special price into a Sale or Offer category according to the date specified.
|
16 |
+

|
17 |
+
Supports:
|
18 |
+
MultiStore
|
19 |
+
Product import.
|
20 |
+

|
21 |
+
Features:
|
22 |
+
Mail Notification
|
23 |
+
Cron Job
|
24 |
+
</notes>
|
25 |
+
<authors><author><name>Manu Jose K</name><user>iammanujose</user><email>iammanujose@gmail.com</email></author></authors>
|
26 |
+
<date>2012-07-31</date>
|
27 |
+
<time>14:53:46</time>
|
28 |
+
<contents><target name="magecommunity"><dir name="Manu"><dir><dir name="Saleproducts"><dir name="Block"><file name="Saleproducts.php" hash="09c109bb3f6ef9427b2364ffe544f5a8"/></dir><dir name="Helper"><file name="Data.php" hash="c18f385a84745660c1bc48c55961c101"/></dir><dir name="Model"><file name="Category.php" hash="9aff440bb5927d5e54584afa2bfa8519"/><file name="Observer.php" hash="ee71dd0379be18613ca3733dec3dd1d4"/></dir><dir name="controllers"><dir name="Catalog"><file name="ProductController.php" hash="d5c9b645f150c1e35f02a386670eff30"/></dir></dir><dir name="etc"><file name="config.xml" hash="09503480d196ec36a83dff45bbdfa408"/><file name="system.xml" hash="a190157bb6c2350d3df37e66f3e6b9df"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Manu_Saleproducts.xml" hash="10e0c0c0f2eb317ec09b8ba1889e04ce"/></dir></target></contents>
|
29 |
+
<compatible/>
|
30 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
31 |
+
</package>
|