Example #1
0
 /**
  * Modifies filter items and filter model itself as specified by extensions subscribed to 
  * morphes_filters_process_items event.
  * @param Mage_Catalog_Model_Layer_Filter_Abstract $filter
  * @param array $items
  */
 public function processFilterItems($filter, $items)
 {
     $wrappedItems = new Varien_Object();
     $wrappedItems->setItems($items);
     Mage::dispatchEvent('morphes_filters_process_items', array('filter' => $filter, 'items' => $wrappedItems));
     return $wrappedItems->getItems();
 }
Example #2
0
 /**
  * Generate sitemap XML file - override to dispatch more events
  *
  * @return $this|Mage_Sitemap_Model_Sitemap
  */
 public function generateXml()
 {
     $io = new Varien_Io_File();
     $io->setAllowCreateFolders(true);
     $io->open(array('path' => $this->getPath()));
     if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) {
         Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath()));
     }
     $io->streamOpen($this->getSitemapFilename());
     $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
     $io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
     $storeId = $this->getStoreId();
     $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
     $baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
     /**
      * Generate categories sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
     $priority = (string) Mage::getStoreConfig('sitemap/category/priority', $storeId);
     $collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
     $categories = new Varien_Object();
     $categories->setItems($collection);
     Mage::dispatchEvent('sitemap_categories_generating_before', array('collection' => $categories));
     foreach ($categories->getItems() as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $io->streamWrite($xml);
     }
     unset($collection);
     /**
      * Generate products sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
     $priority = (string) Mage::getStoreConfig('sitemap/product/priority', $storeId);
     $collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
     $products = new Varien_Object();
     $products->setItems($collection);
     Mage::dispatchEvent('sitemap_products_generating_before', array('collection' => $products));
     foreach ($products->getItems() as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $io->streamWrite($xml);
     }
     unset($collection);
     /**
      * Generate cms pages sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
     $priority = (string) Mage::getStoreConfig('sitemap/page/priority', $storeId);
     $collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
     foreach ($collection as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $io->streamWrite($xml);
     }
     unset($collection);
     $io->streamWrite('</urlset>');
     $io->streamClose();
     $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
     $this->save();
     return $this;
 }
Example #3
0
 public function generateXml()
 {
     if (Mage::helper('blog')->extensionEnabled('AW_Ascurl')) {
         return Mage::getModel('ascurl/sitemap')->setData($this->getData())->generateXml();
     }
     $this->fileCreate();
     $storeId = $this->getStoreId();
     $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
     $baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
     /**
      * Generate categories sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq');
     $priority = (string) Mage::getStoreConfig('sitemap/category/priority');
     $collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId);
     $categories = new Varien_Object();
     $categories->setItems($collection);
     Mage::dispatchEvent('sitemap_categories_generating_before', array('collection' => $categories));
     foreach ($categories->getItems() as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $this->sitemapFileAddLine($xml);
     }
     unset($collection);
     /**
      * Generate products sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/product/changefreq');
     $priority = (string) Mage::getStoreConfig('sitemap/product/priority');
     $collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
     $products = new Varien_Object();
     $products->setItems($collection);
     Mage::dispatchEvent('sitemap_products_generating_before', array('collection' => $products));
     foreach ($products->getItems() as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $this->sitemapFileAddLine($xml);
     }
     unset($collection);
     /**
      * Generate cms pages sitemap
      */
     $changefreq = (string) Mage::getStoreConfig('sitemap/page/changefreq');
     $priority = (string) Mage::getStoreConfig('sitemap/page/priority');
     $collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
     foreach ($collection as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $this->sitemapFileAddLine($xml);
     }
     unset($collection);
     Mage::dispatchEvent('sitemap_add_xml_block_to_the_end', array('sitemap_object' => $this));
     $this->fileClose();
     $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
     $this->save();
     return $this;
 }
Example #4
0
 /**
  * Get line items and totals from sales quote or order
  *
  * PayPal calculates grand total by this formula:
  * sum(item_base_price * qty) + subtotal + shipping + shipping_discount
  * where subtotal doesn't include anything, shipping_discount is negative
  * the items discount should go as separate cart line item with negative amount
  * the shipping_discount is outlined in PayPal API docs, but ignored for some reason. Hence commented out.
  *
  * @param Mage_Sales_Model_Order $salesEntity
  * @return array (array of $items, array of totals, $discountTotal, $shippingTotal)
  */
 public function prepareLineItems(Mage_Core_Model_Abstract $salesEntity, $discountTotalAsItem = true, $shippingTotalAsItem = false)
 {
     $items = array();
     foreach ($salesEntity->getAllItems() as $item) {
         if (!$item->getParentItem()) {
             $items[] = new Varien_Object($this->_prepareLineItemFields($salesEntity, $item));
         }
     }
     $additionalItems = new Varien_Object(array('items' => array()));
     Mage::dispatchEvent('paypal_prepare_line_items', array('sales_entity' => $salesEntity, 'additional' => $additionalItems));
     $additionalAmount = 0;
     $discountAmount = 0;
     // this amount always includes the shipping discount
     foreach ($additionalItems->getItems() as $item) {
         if ($item['amount'] > 0) {
             $additionalAmount += $item['amount'];
             $items[] = $item;
         } else {
             $discountAmount += abs($item['amount']);
         }
     }
     $shippingDescription = '';
     if ($salesEntity instanceof Mage_Sales_Model_Order) {
         $discountAmount += abs($salesEntity->getBaseDiscountAmount());
         $shippingDescription = $salesEntity->getShippingDescription();
         $totals = array('subtotal' => $salesEntity->getBaseSubtotal() - $discountAmount, 'tax' => $salesEntity->getBaseTaxAmount(), 'shipping' => $salesEntity->getBaseShippingAmount(), 'discount' => $discountAmount);
     } else {
         $address = $salesEntity->getIsVirtual() ? $salesEntity->getBillingAddress() : $salesEntity->getShippingAddress();
         $discountAmount += abs($address->getBaseDiscountAmount());
         $shippingDescription = $address->getShippingDescription();
         $totals = array('subtotal' => $salesEntity->getBaseSubtotal() - $discountAmount, 'tax' => $address->getBaseTaxAmount(), 'shipping' => $address->getBaseShippingAmount(), 'discount' => $discountAmount);
     }
     // discount total as line item (negative)
     if ($discountTotalAsItem && $discountAmount) {
         $items[] = new Varien_Object(array('name' => Mage::helper('paypal')->__('Discount'), 'qty' => 1, 'amount' => -1.0 * $discountAmount));
     }
     // shipping total as line item
     if ($shippingTotalAsItem && !$salesEntity->getIsVirtual() && (double) $totals['shipping']) {
         $items[] = new Varien_Object(array('id' => Mage::helper('paypal')->__('Shipping'), 'name' => $shippingDescription, 'qty' => 1, 'amount' => (double) $totals['shipping']));
     }
     $hiddenTax = (double) $salesEntity->getBaseHiddenTaxAmount();
     if ($hiddenTax) {
         $items[] = new Varien_Object(array('name' => Mage::helper('paypal')->__('Discount Tax'), 'qty' => 1, 'amount' => (double) $hiddenTax));
     }
     return array($items, $totals, $discountAmount, $totals['shipping']);
 }
Example #5
0
 /**
  * Draw packages block
  *
  * @param  Zend_Pdf_Page $page
  * @return Mage_Sales_Model_Order_Pdf_Shipment_Packaging
  */
 protected function _drawPackageBlock(Zend_Pdf_Page $page)
 {
     if ($this->getPackageShippingBlock()) {
         $packaging = $this->getPackageShippingBlock();
     } else {
         $packaging = Mage::getBlockSingleton('adminhtml/sales_order_shipment_packaging');
     }
     $packages = $packaging->getPackages();
     $packageNum = 1;
     foreach ($packages as $packageId => $package) {
         $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
         $page->drawRectangle(25, $this->y + 15, 190, $this->y - 35);
         $page->drawRectangle(190, $this->y + 15, 350, $this->y - 35);
         $page->drawRectangle(350, $this->y + 15, 570, $this->y - 35);
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $page->drawRectangle(520, $this->y + 15, 570, $this->y - 5);
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         $packageText = Mage::helper('sales')->__('Package') . ' ' . $packageNum;
         $page->drawText($packageText, 525, $this->y, 'UTF-8');
         $packageNum++;
         $package = new Varien_Object($package);
         $params = new Varien_Object($package->getParams());
         $dimensionUnits = Mage::helper('usa')->getMeasureDimensionName($params->getDimensionUnits());
         $typeText = Mage::helper('sales')->__('Type') . ' : ' . $packaging->getContainerTypeByCode($params->getContainer());
         $page->drawText($typeText, 35, $this->y, 'UTF-8');
         if ($params->getLength() != null) {
             $lengthText = $params->getLength() . ' ' . $dimensionUnits;
         } else {
             $lengthText = '--';
         }
         $lengthText = Mage::helper('sales')->__('Length') . ' : ' . $lengthText;
         $page->drawText($lengthText, 200, $this->y, 'UTF-8');
         if ($params->getDeliveryConfirmation() != null) {
             $confirmationText = Mage::helper('sales')->__('Signature Confirmation') . ' : ' . $packaging->getDeliveryConfirmationTypeByCode($params->getDeliveryConfirmation());
             $page->drawText($confirmationText, 355, $this->y, 'UTF-8');
         }
         $this->y = $this->y - 10;
         if ($packaging->displayCustomsValue() != null) {
             $customsValueText = Mage::helper('sales')->__('Customs Value') . ' : ' . $packaging->displayPrice($params->getCustomsValue());
             $page->drawText($customsValueText, 35, $this->y, 'UTF-8');
         }
         if ($params->getWidth() != null) {
             $widthText = $params->getWidth() . ' ' . $dimensionUnits;
         } else {
             $widthText = '--';
         }
         $widthText = Mage::helper('sales')->__('Width') . ' : ' . $widthText;
         $page->drawText($widthText, 200, $this->y, 'UTF-8');
         if ($params->getContentType() != null) {
             if ($params->getContentType() == 'OTHER') {
                 $contentsValue = $params->getContentTypeOther();
             } else {
                 $contentsValue = $packaging->getContentTypeByCode($params->getContentType());
             }
             $contentsText = Mage::helper('sales')->__('Contents') . ' : ' . $contentsValue;
             $page->drawText($contentsText, 355, $this->y, 'UTF-8');
         }
         $this->y = $this->y - 10;
         $weightText = Mage::helper('sales')->__('Total Weight') . ' : ' . $params->getWeight() . ' ' . Mage::helper('usa')->getMeasureWeightName($params->getWeightUnits());
         $page->drawText($weightText, 35, $this->y, 'UTF-8');
         if ($params->getHeight() != null) {
             $heightText = $params->getHeight() . ' ' . $dimensionUnits;
         } else {
             $heightText = '--';
         }
         $heightText = Mage::helper('sales')->__('Height') . ' : ' . $heightText;
         $page->drawText($heightText, 200, $this->y, 'UTF-8');
         $this->y = $this->y - 10;
         if ($params->getSize()) {
             $sizeText = Mage::helper('sales')->__('Size') . ' : ' . ucfirst(strtolower($params->getSize()));
             $page->drawText($sizeText, 35, $this->y, 'UTF-8');
         }
         if ($params->getGirth() != null) {
             $dimensionGirthUnits = Mage::helper('usa')->getMeasureDimensionName($params->getGirthDimensionUnits());
             $girthText = Mage::helper('sales')->__('Girth') . ' : ' . $params->getGirth() . ' ' . $dimensionGirthUnits;
             $page->drawText($girthText, 200, $this->y, 'UTF-8');
         }
         $this->y = $this->y - 5;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $page->drawRectangle(25, $this->y, 570, $this->y - 30 - count($package->getItems()) * 12);
         $this->y = $this->y - 10;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         $page->drawText(Mage::helper('sales')->__('Items in the Package'), 30, $this->y, 'UTF-8');
         $txtIndent = 5;
         $itemCollsNumber = $packaging->displayCustomsValue() ? 5 : 4;
         $itemCollsX[0] = 30;
         //  coordinate for Product name
         $itemCollsX[1] = 250;
         // coordinate for Product name
         $itemCollsXEnd = 565;
         $itemCollsXStep = round(($itemCollsXEnd - $itemCollsX[1]) / ($itemCollsNumber - 1));
         // calculate coordinates for all other cells (Weight, Customs Value, Qty Ordered, Qty)
         for ($i = 2; $i <= $itemCollsNumber; $i++) {
             $itemCollsX[$i] = $itemCollsX[$i - 1] + $itemCollsXStep;
         }
         $i = 0;
         $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
         $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsXEnd, $this->y - 15);
         $this->y = $this->y - 12;
         $i = 0;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         $page->drawText(Mage::helper('sales')->__('Product'), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Weight'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         if ($packaging->displayCustomsValue()) {
             $page->drawText(Mage::helper('sales')->__('Customs Value'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         }
         $page->drawText(Mage::helper('sales')->__('Qty Ordered'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Qty'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         $i = 0;
         foreach ($package->getItems() as $itemId => $item) {
             $item = new Varien_Object($item);
             $i = 0;
             $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
             $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsXEnd, $this->y - 15);
             $this->y = $this->y - 12;
             $i = 0;
             $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
             $page->drawText($item->getName(), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8');
             $page->drawText($item->getWeight(), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
             if ($packaging->displayCustomsValue()) {
                 $page->drawText($packaging->displayPrice($item->getCustomsValue()), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
             }
             $page->drawText($packaging->getQtyOrderedItem($item->getOrderItemId()), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
             $page->drawText($item->getQty() * 1, $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
         }
         $this->y = $this->y - 30;
     }
     return $this;
 }
 /**
  * Render Code Dump
  *
  * @param Varien_Object $row
  *
  * @return string
  */
 public function render(Varien_Object $row)
 {
     $items = $row->getItems();
     $item = $items['code'];
     return Mage::helper('enterprise_support')->getItemStatusLabel($item);
 }