Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Add “Affected Products” in catalog price rule

public function getSpecialPriceProducts()
{
            $categoryID = $this->getCategoryId();
            if($categoryID)
            {
              $category = new Mage_Catalog_Model_Category();
              $category->load($categoryID); // this is category id
              $collection = $category->getProductCollection();
            } else
            {
              $collection = Mage::getResourceModel('catalog/product_collection');
            }

            $todayDate = date('m/d/y');
            $tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
            $tomorrowDate = date('m/d/y', $tomorrow);

            Mage::getModel('catalog/layer')->prepareProductCollection($collection);
            $collection->addAttributeToSort('created_at', 'desc');
            $collection->addStoreFilter()
                    ->addAttributeToSelect(array('name', 'price', 'short_description','image','small_image','url_key'), 'inner');
            $collection->addAttributeToFilter('special_price', array('gt' => 0));
            $collection->addAttributeToFilter('special_to_date', array('date' => true, 'to' => $todayDate))
                ->addAttributeToFilter('special_from_date', array('or'=> array(
                0 => array('date' => true, 'from' => $tomorrowDate),
                1 => array('is' => new Zend_Db_Expr('null')))
                ), 'left');

$rules = Mage::getResourceModel('catalogrule/rule_collection')->load();

            // read: if there are active rules
            if($rules->getData()) {
                $rule_ids = array(); // i used this down below to style the products according to which rule affected
                $productIds[] = array(); // this will hold the ids of the products

                foreach($rules as $rule) {
                    $rule_ids[] = $rule->getId();
                    $productIds = $rule->getMatchingProductIds(); // affected products come in here
                }

                // merge the collections: $arr is an array and keeps all product IDs we fetched before with the special-price-stuff
                $arr = $collection->getAllIds();
                if($productIds) {
                    // if there are products affected by catalog price rules, $arr now also keeps their IDs
                    $arr = array_merge($arr,$productIds);
                }

                // we initialize a new collection and filter solely by the product IDs we got before, read: select all products with their entity_id in $arr
                $collection = Mage::getModel('catalog/product')->getCollection()
                    ->addAttributeToSelect(array('name', 'price', 'short_description','image','small_image','url_key'), 'inner')
                    ->addAttributeToFilter('entity_id',array('in'=>$arr))
                    ->load();
            }
return $collection;
}
Comment

PREVIOUS NEXT
Code Example
Php :: check if order id exists wordpress woccommerce 
Php :: php find odd even number in loop 
Php :: Lity in Wordpress 
Php :: debugger not installed phpstorm 
Php :: flask like framework for php 
Php :: laravel notion require 
Php :: download xampp php 5.3 for windows 7 64 bit 
Php :: php href variable in javascript alert 
Php :: what is type-hinting in php 
Php :: Primary Termlaravel recursive relationships 
Php :: Ajuster la taille par défaut pour le contenu intégré 
Php :: php echo to stderr 
Php :: cake php 2.x group 
Php :: can we generate alphanumeric 6 digit primary key in phpmyadmin 
Php :: If you wanted all questions that had all three of those tags, your query would look like: 
Php :: show all errors in php 
Php :: wordpress deny user to access wp-admin programmatically 
Php :: get pages with tempalte wp 
Php :: php usort two columns 
Php :: call a class in another class php 
Php :: remove public from url laravel 8 
Php :: echo fread($myfile,filesize("webdictionary.txt")); 
Php :: Convert English Date Time To Persian Date Time JDF PHP 
Php :: remove elements to this array 
Php :: laravel view not created using foreign keys 
Php :: desactivar estilos globales wordpress 5.9 
Php :: laravel validateexception no error description 
Php :: get_html_translation_table (PHP 4, PHP 5, PHP 7, PHP 8) get_html_translation_table — Returns the translation table 
Php :: default password when you make users in laravel 
Php :: Breaking of code snippets in CKEditor as result code blocks are empty. 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =