Example #1
0
 /**
  * @param Varien_Object $dataObject
  */
 public function runConverter(Varien_Object $dataObject)
 {
     $stylaField = $this->getStylaField();
     $environmentInfo = $this->_emulateFrontend();
     //we need to temporarily set the same store id to the object, or else we won't get a rewritten url
     $oldId = $dataObject->getStoreId();
     $dataObject->setStoreId($this->_getDefaultStoreViewId());
     $productUrl = $dataObject->getProductUrl();
     if ($this->_useRelativeUrls()) {
         $productUrl = str_replace(Mage::getBaseUrl(), "/", $productUrl);
     }
     $dataObject->setStoreId($oldId);
     $this->_stopEmulation($environmentInfo);
     $dataObject->setData($stylaField, $productUrl);
 }
Example #2
0
 /**
  * Before save
  *
  * @param Varien_Object $object
  * @return Mage_Customer_Model_Customer_Attribute_Backend_Store
  */
 public function beforeSave($object)
 {
     if ($object->getId()) {
         return $this;
     }
     if (!$object->hasStoreId()) {
         $object->setStoreId(Mage::app()->getStore()->getId());
     }
     if (!$object->hasData('created_in')) {
         $object->setData('created_in', Mage::app()->getStore($object->getStoreId())->getName());
     }
     return $this;
 }
Example #3
0
 /**
  * Prepare html output
  *
  * @return string
  */
 protected function _toHtml()
 {
     $previewModel = Mage::getModel('hackathon_emailpreview/emailPreview');
     $storeId = $this->getRequest()->getParam('storeId');
     $templateId = $this->getRequest()->getParam('templateId');
     $templateType = $this->getRequest()->getParam('templateType');
     $templateParams = new Varien_Object();
     $templateParams->setRequestParams($this->getRequest()->getParams());
     $templateParams->setStoreId($storeId);
     $eventData = array('templateParams' => $templateParams, 'templateType' => $templateType);
     Mage::dispatchEvent('hackathon_emailpreview_render_email_before', $eventData);
     $storeId = $templateParams->getStoreId();
     $templateParams->setStore(Mage::app()->getStore($storeId));
     $html = $previewModel->renderEmail($templateId, $templateParams->getData());
     return $html;
 }
 private function setUpHelperMock($returnStatus, $setStoreId = true)
 {
     $paymentHelperMock = $this->getHelperMock('ops/payment', array('applyStateForOrder', 'shaCryptValidation'));
     $paymentHelperMock->expects($this->any())->method('applyStateForOrder')->will($this->returnValue($returnStatus));
     $paymentHelperMock->expects($this->any())->method('shaCryptValidation')->will($this->returnValue(true));
     $this->replaceByMock('helper', 'ops/payment', $paymentHelperMock);
     $fakePayment = new Varien_Object();
     $fakePayment->setMethodInstance(Mage::getModel('ops/payment_cc'));
     $fakeOrder = new Varien_Object();
     $fakeOrder->setPayment($fakePayment);
     $fakeOrder->setId(1);
     if ($setStoreId) {
         $fakeOrder->setStoreId(1);
     }
     $orderHelperMock = $this->getHelperMock('ops/order', array('getOrder'));
     $orderHelperMock->expects($this->any())->method('getOrder')->will($this->returnValue($fakeOrder));
     $this->replaceByMock('helper', 'ops/order', $orderHelperMock);
 }
Example #5
0
 /**
  * After save process
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Bundle_Model_Resource_Option
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     parent::_afterSave($object);
     $condition = array('option_id = ?' => $object->getId(), 'store_id = ? OR store_id = 0' => $object->getStoreId());
     $write = $this->_getWriteAdapter();
     $write->delete($this->getTable('bundle/option_value'), $condition);
     $data = new Varien_Object();
     $data->setOptionId($object->getId())->setStoreId($object->getStoreId())->setTitle($object->getTitle());
     $write->insert($this->getTable('bundle/option_value'), $data->getData());
     /**
      * also saving default value if this store view scope
      */
     if ($object->getStoreId()) {
         $data->setStoreId(0);
         $data->setTitle($object->getDefaultTitle());
         $write->insert($this->getTable('bundle/option_value'), $data->getData());
     }
     return $this;
 }
Example #6
0
 /**
  * After save process
  *
  * @param Mage_Core_Model_Abstract $object
  * @return Mage_Bundle_Model_Mysql4_Option
  */
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     parent::_afterSave($object);
     $condition = $this->_getWriteAdapter()->quoteInto('option_id = ?', $object->getId());
     $condition .= ' and (' . $this->_getWriteAdapter()->quoteInto('store_id = ?', $object->getStoreId());
     $condition .= ' or store_id = 0)';
     $this->_getWriteAdapter()->delete($this->getTable('option_value'), $condition);
     $data = new Varien_Object();
     $data->setOptionId($object->getId())->setStoreId($object->getStoreId())->setTitle($object->getTitle());
     $this->_getWriteAdapter()->insert($this->getTable('option_value'), $data->getData());
     /**
      * also saving default value if this store view scope
      */
     if ($object->getStoreId()) {
         $data->setStoreId('0');
         $data->setTitle($object->getDefaultTitle());
         $this->_getWriteAdapter()->insert($this->getTable('option_value'), $data->getData());
     }
     return $this;
 }
Example #7
0
 protected function _getProducts($productIds = null, $storeId, $entityId = 0, &$lastEntityId)
 {
     $products = array();
     $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
     if (!is_null($productIds)) {
         if (!is_array($productIds)) {
             $productIds = array($productIds);
         }
     }
     $select = $this->_getWriteAdapter()->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), $this->_getWriteAdapter()->quoteInto('e.entity_id=w.product_id AND w.website_id=?', $websiteId), array())->where('e.entity_id>?', $entityId)->order('e.entity_id')->limit($this->_productLimit);
     if (!is_null($productIds)) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     $query = $this->_getWriteAdapter()->query($select);
     while ($row = $query->fetch()) {
         $product = new Varien_Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(array());
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($query);
     if ($products) {
         $select = $this->_getReadAdapter()->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products));
         $categories = $this->_getReadAdapter()->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (array('name', 'url_key', 'url_path', 'visibility', "status") as $attributeCode) {
             $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
             foreach ($attributes as $productId => $attributeValue) {
                 $products[$productId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $products;
 }
 protected function _getCategories($categoryIds, $storeId = null, $path = null)
 {
     $isActiveAttribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_category', 'is_active');
     $categories = array();
     if (!is_array($categoryIds)) {
         $categoryIds = array($categoryIds);
     }
     $select = $this->_getWriteAdapter()->select()->from(array('main_table' => $this->getTable('catalog/category')), array('main_table.entity_id', 'main_table.parent_id', 'is_active' => 'IFNULL(c.value, d.value)', 'main_table.path'));
     if (is_null($path)) {
         $select->where('main_table.entity_id IN(?)', $categoryIds);
     } else {
         $select->where('main_table.path LIKE ?', $path . '%')->order('main_table.path');
     }
     $table = $this->getTable('catalog/category') . '_int';
     $select->joinLeft(array('d' => $table), "d.attribute_id = '{$isActiveAttribute->getId()}' AND d.store_id = 0 AND d.entity_id = main_table.entity_id", array())->joinLeft(array('c' => $table), "c.attribute_id = '{$isActiveAttribute->getId()}' AND c.store_id = '{$storeId}' AND c.entity_id = main_table.entity_id", array());
     if (!is_null($storeId)) {
         $rootCategoryPath = $this->getStores($storeId)->getRootCategoryPath();
         $rootCategoryPathLength = strlen($rootCategoryPath);
     }
     $rowSet = $this->_getWriteAdapter()->fetchAll($select);
     foreach ($rowSet as $row) {
         if (!is_null($storeId) && substr($row['path'], 0, $rootCategoryPathLength) != $rootCategoryPath) {
             continue;
         }
         $category = new Varien_Object($row);
         $category->setIdFieldName('entity_id');
         $category->setStoreId($storeId);
         $this->_prepareCategoryParentId($category);
         $categories[$category->getId()] = $category;
     }
     unset($rowSet);
     if (!is_null($storeId) && $categories) {
         foreach (array('name', 'url_key', 'url_path') as $attributeCode) {
             $attributes = $this->_getCategoryAttribute($attributeCode, array_keys($categories), $category->getStoreId());
             foreach ($attributes as $categoryId => $attributeValue) {
                 $categories[$categoryId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $categories;
 }
Example #9
0
 public function previewAction()
 {
     $data = $this->getRequest()->getParams();
     $product = Mage::getModel('catalog/product')->load($data['product']);
     if (Mage::helper('giftcards')->isUseDefaultPicture() || !$product->getId()) {
         $picture = Mage::getDesign()->getSkinUrl('images/giftcard.png', array('_area' => 'frontend'));
     } else {
         if ($product->getId() && $product->getImage() != 'no_selection') {
             $picture = Mage::helper('catalog/image')->init($product, 'image');
         } else {
             $picture = Mage::getDesign()->getSkinUrl('images/giftcard.png', array('_area' => 'frontend'));
         }
     }
     $currencySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
     if ($currencySymbol == '€') {
         $currencySymbol = '€';
     } elseif ($currencySymbol == '£') {
         $currencySymbol = '£';
     }
     $storeId = Mage::app()->getStore()->getId();
     $post = array('amount' => $currencySymbol . $data['price'], 'code' => 'XXXX-XXXX-XXXX', 'email-to' => $data['mail-to'], 'email-from' => $data['mail-from'], 'link' => '#', 'email-message' => $data['mail-message'], 'store-phone' => Mage::getStoreConfig('general/store_information/phone'), 'picture' => $picture);
     $mailTemplate = Mage::getModel('core/email_template');
     $postObject = new Varien_Object();
     $postObject->setData($post);
     $postObject->setStoreId($storeId);
     if ($data['card-type'] == 'email') {
         $template = 'giftcards/email/email_template';
     } elseif ($data['card-type'] == 'print') {
         $template = 'giftcards/email/print_template';
     }
     $mailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->sendTransactional(Mage::getStoreConfig($template), 'general', '', null, array('data' => $postObject));
     //$emailTemplate  = Mage::getModel('core/email_template')->loadDefault('giftcards_email_email_template');
     $mail = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
     $mail .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2) . '" lang="' . substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2) . '">';
     $mail .= $mailTemplate->getProcessedTemplate();
     $mail .= '</html>';
     echo $mail;
     exit;
 }
Example #10
0
 /**
  * Prepare grid collection
  */
 protected function _prepareCollection()
 {
     $collection = new Varien_Data_Collection();
     $cache = Mage::helper('varnish')->getRedisCache()->getFrontend();
     $ids = $cache->getIdsMatchingTags(array('VARNISH-CACHETYPE-PER-PAGE'));
     foreach ($ids as $id) {
         $data = unserialize($cache->load($id));
         $item = new Varien_Object();
         $item->setId($id);
         $item->setStoreId($data->getStoreId());
         $item->setParentUrl($data->getParentUrl());
         $item->setBlockName($data->getNameInLayout());
         $item->setFingerprint($id);
         $item->setProbeUrl($data->getUrl());
         $collection->addItem($item);
     }
     $this->setCollection($collection);
     $sort = $this->getParam($this->getVarNameSort()) ? $this->getParam($this->getVarNameSort()) : $this->getDefaultSort();
     $dir = $this->getParam($this->getVarNameDir()) ? $this->getParam($this->getVarNameDir()) : $this->getDefaultDir();
     $this->_sortCollectionBy($sort, $dir);
     return parent::_prepareCollection();
 }
Example #11
0
 /**
  * Retrieve Product data objects
  * LOE: remove if status(=2) is disabled or visibility(=1) false
  *
  * @param int|array $productIds
  * @param int $storeId
  * @param int $entityId
  * @param int $lastEntityId
  * @return array
  */
 protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
 {
     $products = array();
     $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
     $adapter = $this->_getReadAdapter();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = array($productIds);
         }
     }
     $bind = array('website_id' => (int) $websiteId, 'entity_id' => (int) $entityId);
     $select = $adapter->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), 'e.entity_id = w.product_id AND w.website_id = :website_id', array())->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit);
     if ($productIds !== null) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     //if we are to ignore disabled products... add the necessary joins and conditions
     if ($this->_helper()->HideDisabledProducts($storeId)) {
         $statusCode = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', 'status');
         $bind['status_id'] = (int) $statusCode;
         $bind['disabled'] = Mage_Catalog_Model_Product_Status::STATUS_DISABLED;
         $bind['store_id'] = (int) $storeId;
         $bind['default_store_id'] = 0;
         $select->joinLeft(array('s' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = s.entity_id AND s.attribute_id = :status_id AND s.store_id = :store_id', array());
         $select->joinLeft(array('ds' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = ds.entity_id AND ds.attribute_id = :status_id AND ds.store_id = :default_store_id', array());
         $select->where('s.value <> :disabled OR (s.value IS NULL AND ds.value <> :disabled)');
     }
     //if we are to ignore not visible products... add the necessary joins and conditions
     if ($this->_helper()->HideNotVisibileProducts($storeId)) {
         $visibilityCode = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', 'visibility');
         $bind['not_visible'] = Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
         $bind['visibility_id'] = (int) $visibilityCode;
         $bind['store_id'] = (int) $storeId;
         $bind['default_store_id'] = 0;
         $select->joinLeft(array('v' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = v.entity_id AND v.attribute_id = :visibility_id AND v.store_id = :store_id', array());
         $select->joinLeft(array('dv' => $this->getTable(array('catalog/product', 'int'))), 'e.entity_id = dv.entity_id AND dv.attribute_id = :visibility_id AND dv.store_id = :default_store_id', array());
         $select->where('v.value <> :not_visible OR (v.value IS NULL AND dv.value <> :not_visible)');
     }
     $rowSet = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new Varien_Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(array());
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($rowSet);
     if ($products) {
         $select = $adapter->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products));
         $categories = $adapter->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (array('name', 'url_key', 'url_path') as $attributeCode) {
             $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
             foreach ($attributes as $productId => $attributeValue) {
                 $products[$productId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $products;
 }
Example #12
0
 /**
  * Register on Magento's registry GUEST customer data for MergeVars for on checkout subscribe
  *
  * @param Mage_Sales_Model_Order $order
  * @return void
  */
 public function registerGuestCustomer($order)
 {
     if (Mage::registry('mc_guest_customer')) {
         return;
     }
     $customer = new Varien_Object();
     $customer->setId('guest' . time());
     $customer->setEmail($order->getBillingAddress()->getEmail());
     $customer->setStoreId($order->getStoreId());
     $customer->setFirstname($order->getBillingAddress()->getFirstname());
     $customer->setLastname($order->getBillingAddress()->getLastname());
     $customer->setPrimaryBillingAddress($order->getBillingAddress());
     $customer->setPrimaryShippingAddress($order->getShippingAddress());
     Mage::register('mc_guest_customer', $customer, TRUE);
 }
Example #13
0
 /**
  * Prepare and set request in property of current instance
  *
  * @param Varien_Object $request
  * @return Mage_Usa_Model_Shipping_Carrier_Dhl
  */
 public function setRequest(Varien_Object $request)
 {
     $this->_request = $request;
     $this->setStore($request->getStoreId());
     $requestObject = new Varien_Object();
     $requestObject->setIsGenerateLabelReturn($request->getIsGenerateLabelReturn());
     $requestObject->setStoreId($request->getStoreId());
     if ($request->getLimitMethod()) {
         $requestObject->setService($request->getLimitMethod());
     }
     $requestObject = $this->_addParams($requestObject);
     if ($request->getDestPostcode()) {
         $requestObject->setDestPostal($request->getDestPostcode());
     }
     $requestObject->setOrigCountry($this->_getDefaultValue($request->getOrigCountry(), Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID))->setOrigCountryId($this->_getDefaultValue($request->getOrigCountryId(), Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID));
     $shippingWeight = $request->getPackageWeight();
     $requestObject->setValue(round($request->getPackageValue(), 2))->setValueWithDiscount($request->getPackageValueWithDiscount())->setCustomsValue($request->getPackageCustomsValue())->setDestStreet(Mage::helper('core/string')->substr(str_replace("\n", '', $request->getDestStreet()), 0, 35))->setDestStreetLine2($request->getDestStreetLine2())->setDestCity($request->getDestCity())->setOrigCompanyName($request->getOrigCompanyName())->setOrigCity($request->getOrigCity())->setOrigPhoneNumber($request->getOrigPhoneNumber())->setOrigPersonName($request->getOrigPersonName())->setOrigEmail(Mage::getStoreConfig('trans_email/ident_general/email', $requestObject->getStoreId()))->setOrigCity($request->getOrigCity())->setOrigPostal($request->getOrigPostal())->setOrigStreetLine2($request->getOrigStreetLine2())->setDestPhoneNumber($request->getDestPhoneNumber())->setDestPersonName($request->getDestPersonName())->setDestCompanyName($request->getDestCompanyName());
     $originStreet2 = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_ADDRESS2, $requestObject->getStoreId());
     $requestObject->setOrigStreet($request->getOrigStreet() ? $request->getOrigStreet() : $originStreet2);
     if (is_numeric($request->getOrigState())) {
         $requestObject->setOrigState(Mage::getModel('directory/region')->load($request->getOrigState())->getCode());
     } else {
         $requestObject->setOrigState($request->getOrigState());
     }
     if ($request->getDestCountryId()) {
         $destCountry = $request->getDestCountryId();
     } else {
         $destCountry = self::USA_COUNTRY_ID;
     }
     // for DHL, Puerto Rico state for US will assume as Puerto Rico country
     // for Puerto Rico, dhl will ship as international
     if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
         $destCountry = self::PUERTORICO_COUNTRY_ID;
     }
     $requestObject->setDestCountryId($destCountry)->setDestState($request->getDestRegionCode())->setWeight($shippingWeight)->setFreeMethodWeight($request->getFreeMethodWeight())->setOrderShipment($request->getOrderShipment());
     if ($request->getPackageId()) {
         $requestObject->setPackageId($request->getPackageId());
     }
     $requestObject->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
     $this->_rawRequest = $requestObject;
     return $this;
 }
Example #14
0
 protected function _prepareLayout()
 {
     $entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
     $modelName = Mage::helper('amshopby')->isVersionLessThan(1, 4) ? 'catalog/entity_attribute' : 'catalog/resource_eav_attribute';
     $attribute = Mage::getModel($modelName)->loadByCode($entityTypeId, $this->getAttributeCode());
     if (!$attribute->getId()) {
         return parent::_prepareLayout();
     }
     //1.3 only
     if (!$attribute->getSourceModel()) {
         $attribute->setSourceModel('eav/entity_attribute_source_table');
     }
     $options = $attribute->getFrontend()->getSelectOptions();
     array_shift($options);
     $filter = new Varien_Object();
     // important when used at category pages
     $layer = Mage::getModel('catalog/layer')->setCurrentCategory(Mage::app()->getStore()->getRootCategoryId());
     $filter->setLayer($layer);
     $filter->setStoreId(Mage::app()->getStore()->getId());
     $filter->setAttributeModel($attribute);
     $optionsCount = array();
     if (Mage::helper('amshopby')->isVersionLessThan(1, 4)) {
         $category = Mage::getModel('catalog/category')->load(Mage::app()->getStore()->getRootCategoryId());
         $collection = $category->getProductCollection();
         Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
         Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
         $optionsCount = Mage::getSingleton('catalogindex/attribute')->getCount($attribute, $collection->getSelect());
     } else {
         $optionsCount = Mage::getResourceModel('catalog/layer_filter_attribute')->getCount($filter);
     }
     usort($options, array($this, '_sortByName'));
     // add images
     $ids = array();
     foreach ($options as $opt) {
         $ids[] = $opt['value'];
     }
     $collection = Mage::getResourceModel('amshopby/value_collection')->addFieldToFilter('option_id', array('in' => $ids))->load();
     $images = array();
     foreach ($collection as $value) {
         $images[$value->getOptionId()] = $value->getImgBig() ? Mage::getBaseUrl('media') . 'amshopby/' . $value->getImgBig() : '';
     }
     // end add images
     $c = 0;
     $letters = array();
     $hlp = Mage::helper('amshopby/url');
     foreach ($options as $opt) {
         if (!empty($optionsCount[$opt['value']])) {
             $opt['cnt'] = $optionsCount[$opt['value']];
             $opt['url'] = $hlp->getOptionUrl($attribute->getAttributeCode(), $opt['label'], $opt['value']);
             $opt['img'] = isset($images[$opt['value']]) ? $images[$opt['value']] : '';
             //$i = mb_strtoupper(mb_substr($opt['label'], 0, 1, 'UTF-8'));
             $i = strtoupper(substr($opt['label'], 0, 1));
             if (!isset($letters[$i]['items'])) {
                 $letters[$i]['items'] = array();
             }
             $letters[$i]['items'][] = $opt;
             if (!isset($letters[$i]['count'])) {
                 $letters[$i]['count'] = 0;
             }
             $letters[$i]['count']++;
             ++$c;
         }
     }
     if (!$letters) {
         return parent::_prepareLayout();
     }
     $itemsPerColumn = ceil(($c + sizeof($letters)) / max(1, abs(intVal($this->getColumns()))));
     $col = 0;
     // current column
     $num = 0;
     // current number of items in column
     foreach ($letters as $letter => $items) {
         $this->items[$col][$letter] = $items['items'];
         $num += $items['count'];
         $num++;
         if ($num >= $itemsPerColumn) {
             $num = 0;
             $col++;
         }
     }
     return parent::_prepareLayout();
 }
Example #15
0
 protected function _prepareLayout()
 {
     $entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
     /** @var Mage_Eav_Model_Attribute $attribute */
     $attribute = Mage::getModel('catalog/resource_eav_attribute')->loadByCode($entityTypeId, $this->getAttributeCode());
     if (!$attribute->getId()) {
         return parent::_prepareLayout();
     }
     $options = $attribute->getFrontend()->getSelectOptions();
     array_shift($options);
     $filter = new Varien_Object();
     // important when used at category pages
     $layer = Mage::getModel('catalog/layer')->setCurrentCategory(Mage::app()->getStore()->getRootCategoryId());
     $filter->setLayer($layer);
     $filter->setStoreId(Mage::app()->getStore()->getId());
     $filter->setAttributeModel($attribute);
     $optionsCount = Mage::getResourceModel('catalog/layer_filter_attribute')->getCount($filter);
     usort($options, array($this, '_sortByName'));
     $images = Mage::getStoreConfig('amshopby/brands/show_images') ? $this->_getOptionImages($options) : null;
     /** @var Amasty_Shopby_Helper_Url $urlHelper */
     $urlHelper = Mage::helper('amshopby/url');
     $c = 0;
     $letters = array();
     foreach ($options as $opt) {
         if (!empty($optionsCount[$opt['value']])) {
             $opt['cnt'] = $optionsCount[$opt['value']];
             $opt['url'] = $urlHelper->getOptionUrl($attribute->getAttributeCode(), $opt['value']);
             $opt['img'] = $images ? $images[$opt['value']] : null;
             if (function_exists('mb_strtoupper')) {
                 $i = mb_strtoupper(mb_substr($opt['label'], 0, 1, 'UTF-8'));
             } else {
                 $i = strtoupper(substr($opt['label'], 0, 1));
             }
             if (is_numeric($i)) {
                 $i = '#';
             }
             if (!isset($letters[$i]['items'])) {
                 $letters[$i]['items'] = array();
             }
             $letters[$i]['items'][] = $opt;
             if (!isset($letters[$i]['count'])) {
                 $letters[$i]['count'] = 0;
             }
             $letters[$i]['count']++;
             ++$c;
         }
     }
     if (!$letters) {
         return parent::_prepareLayout();
     }
     $itemsPerColumn = ceil(($c + sizeof($letters)) / max(1, abs(intVal($this->getColumns()))));
     $col = 0;
     // current column
     $num = 0;
     // current number of items in column
     foreach ($letters as $letter => $items) {
         $this->items[$col][$letter] = $items['items'];
         $num += $items['count'];
         $num++;
         if ($num >= $itemsPerColumn) {
             $num = 0;
             $col++;
         }
     }
     return parent::_prepareLayout();
 }
Example #16
0
 /**
  * Retrieve categories objects
  * Either $categoryIds or $path (with ending slash) must be specified
  *
  * @param int|array $categoryIds
  * @param int       $storeId
  * @param string    $path
  *
  * @return array
  */
 protected function _getCategories($categoryIds, $storeId = null, $path = null)
 {
     if (false === $this->_getHelper()->excludeDisabledCategories($storeId)) {
         return parent::_getCategories($categoryIds, $storeId, $path);
     }
     /** @var Mage_Catalog_Model_Resource_Eav_Attribute $isActiveAttribute */
     $isActiveAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_active');
     $categories = array();
     $adapter = $this->_getReadAdapter();
     if (!is_array($categoryIds)) {
         $categoryIds = array($categoryIds);
     }
     // the method parent::_getCategories has a bug in getCheckSql
     $isActiveExpr = $adapter->getCheckSql('IFNULL(c.value_id,0) > 0', 'c.value', 'd.value');
     $select = $adapter->select()->from(array('main_table' => $this->getTable('catalog/category')), array('main_table.entity_id', 'main_table.parent_id', 'main_table.level', 'is_active' => $isActiveExpr, 'main_table.path'));
     // Prepare variables for checking whether categories belong to store
     if ($path === null) {
         $select->where('main_table.entity_id IN(?)', $categoryIds);
     } else {
         // Ensure that path ends with '/', otherwise we can get wrong results - e.g. $path = '1/2' will get '1/20'
         if (substr($path, -1) != '/') {
             $path .= '/';
         }
         $select->where('main_table.path LIKE ?', $path . '%')->order('main_table.path');
     }
     $table = $this->getTable(array('catalog/category', 'int'));
     $select->joinLeft(array('d' => $table), 'd.attribute_id = :attribute_id AND d.store_id = 0 AND d.entity_id = main_table.entity_id', array())->joinLeft(array('c' => $table), 'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = main_table.entity_id', array());
     if (true === $this->_getHelper()->excludeDisabledCategories($storeId)) {
         $select->where($isActiveExpr . '=1');
     }
     if ($storeId !== null) {
         $rootCategoryPath = $this->getStores($storeId)->getRootCategoryPath();
         $rootCategoryPathLength = strlen($rootCategoryPath);
     }
     $bind = array('attribute_id' => (int) $isActiveAttribute->getId(), 'store_id' => (int) $storeId);
     $this->_addCategoryAttributeToSelect($select, 'name', $storeId);
     $this->_addCategoryAttributeToSelect($select, 'url_key', $storeId);
     $this->_addCategoryAttributeToSelect($select, 'url_path', $storeId);
     Mage::dispatchEvent('fastindexer_get_categories_select', array('model' => $this, 'select' => $select, 'store_id' => $storeId));
     $rowSet = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         if ($storeId !== null) {
             // Check the category to be either store's root or its descendant
             // First - check that category's start is the same as root category
             if (substr($row['path'], 0, $rootCategoryPathLength) !== $rootCategoryPath) {
                 continue;
             }
             // Second - check non-root category - that it's really a descendant, not a simple string match
             if (strlen($row['path']) > $rootCategoryPathLength && $row['path'][$rootCategoryPathLength] !== '/') {
                 continue;
             }
         }
         $category = new Varien_Object($row);
         $category->setIdFieldName('entity_id');
         $category->setStoreId($storeId);
         $this->_prepareCategoryParentId($category);
         $categories[$category->getId()] = $category;
     }
     unset($rowSet);
     return $categories;
 }
Example #17
0
 /**
  * Generate ESI data to be encoded in URL
  *
  * @param  Mage_Core_Block_Template $blockObject
  * @param  array $esiOptions
  * @return Varien_Object
  */
 protected function _getEsiData($blockObject, $esiOptions)
 {
     Varien_Profiler::start('turpentine::observer::esi::_getEsiData');
     $esiHelper = Mage::helper('turpentine/esi');
     $cacheTypeParam = $esiHelper->getEsiCacheTypeParam();
     $scopeParam = $esiHelper->getEsiScopeParam();
     $methodParam = $esiHelper->getEsiMethodParam();
     $esiData = new Varien_Object();
     $esiData->setStoreId(Mage::app()->getStore()->getId());
     $esiData->setDesignPackage(Mage::getDesign()->getPackageName());
     $esiData->setDesignTheme(Mage::getDesign()->getTheme('layout'));
     $esiData->setNameInLayout($blockObject->getNameInLayout());
     $esiData->setBlockType(get_class($blockObject));
     $esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject));
     $esiData->setEsiMethod($esiOptions[$methodParam]);
     if ($esiOptions[$cacheTypeParam] == 'private' || $esiOptions[$cacheTypeParam] == 'customer_group') {
         if (is_array(@$esiOptions['flush_events'])) {
             $esiData->setFlushEvents(array_merge($esiHelper->getDefaultCacheClearEvents(), array_keys($esiOptions['flush_events'])));
         } else {
             $esiData->setFlushEvents($esiHelper->getDefaultCacheClearEvents());
         }
     }
     if ($esiOptions[$scopeParam] == 'page') {
         $esiData->setParentUrl(Mage::app()->getRequest()->getRequestString());
     }
     if (is_array($esiOptions['dummy_blocks'])) {
         $dummyBlocks = array();
         foreach ($esiOptions['dummy_blocks'] as $key => $value) {
             $dummyBlocks[] = empty($value) && !is_numeric($key) ? $key : $value;
         }
         $esiData->setDummyBlocks($dummyBlocks);
     } else {
         Mage::helper('turpentine/debug')->logWarn('Invalid dummy_blocks for block: %s', $blockObject->getNameInLayout());
     }
     $simpleRegistry = array();
     $complexRegistry = array();
     if (is_array($esiOptions['registry_keys'])) {
         foreach ($esiOptions['registry_keys'] as $key => $options) {
             $value = Mage::registry($key);
             if ($value) {
                 if (is_object($value) && $value instanceof Mage_Core_Model_Abstract) {
                     $complexRegistry[$key] = $this->_getComplexRegistryData($options, $value);
                 } else {
                     $simpleRegistry[$key] = $value;
                 }
             }
         }
     } else {
         Mage::helper('turpentine/debug')->logWarn('Invalid registry_keys for block: %s', $blockObject->getNameInLayout());
     }
     $esiData->setSimpleRegistry($simpleRegistry);
     $esiData->setComplexRegistry($complexRegistry);
     Varien_Profiler::stop('turpentine::observer::esi::_getEsiData');
     return $esiData;
 }
Example #18
0
 public function setRequest(Mage_Shipping_Model_Rate_Request $request)
 {
     $this->_request = $request;
     $r = new Varien_Object();
     $r->setStoreId($request->getStoreId());
     if ($request->getLimitMethod()) {
         $r->setService($request->getLimitMethod());
     }
     if ($request->getDhlId()) {
         $id = $request->getDhlId();
     } else {
         $id = $this->getConfigData('id');
     }
     $r->setId($id);
     if ($request->getDhlPassword()) {
         $password = $request->getDhlPassword();
     } else {
         $password = $this->getConfigData('password');
     }
     $r->setPassword($password);
     if ($request->getDhlAccount()) {
         $accountNbr = $request->getDhlAccount();
     } else {
         $accountNbr = $this->getConfigData('account');
     }
     $r->setAccountNbr($accountNbr);
     if ($request->getDhlShippingKey()) {
         $shippingKey = $request->getDhlShippingKey();
     } else {
         $shippingKey = $this->getConfigData('shipping_key');
     }
     $r->setShippingKey($shippingKey);
     if ($request->getDhlShippingIntlKey()) {
         $shippingKey = $request->getDhlShippingIntlKey();
     } else {
         $shippingKey = $this->getConfigData('shipping_intlkey');
     }
     $r->setShippingIntlKey($shippingKey);
     if ($request->getDhlShipmentType()) {
         $shipmentType = $request->getDhlShipmentType();
     } else {
         $shipmentType = $this->getConfigData('shipment_type');
     }
     $r->setShipmentType($shipmentType);
     if ($request->getDhlDutiable()) {
         $shipmentDutible = $request->getDhlDutiable();
     } else {
         $shipmentDutible = $this->getConfigData('dutiable');
     }
     $r->setDutiable($shipmentDutible);
     if ($request->getDhlDutyPaymentType()) {
         $dutypaytype = $request->getDhlDutyPaymentType();
     } else {
         $dutypaytype = $this->getConfigData('dutypaymenttype');
     }
     $r->setDutyPaymentType($dutypaytype);
     if ($request->getDhlContentDesc()) {
         $contentdesc = $request->getDhlContentDesc();
     } else {
         $contentdesc = $this->getConfigData('contentdesc');
     }
     $r->setContentDesc($contentdesc);
     if ($request->getDestPostcode()) {
         $r->setDestPostal($request->getDestPostcode());
     }
     if ($request->getOrigCountry()) {
         $origCountry = $request->getOrigCountry();
     } else {
         $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
     }
     $r->setOrigCountry($origCountry);
     /*
      * DHL only accepts weight as a whole number. Maximum length is 3 digits.
      */
     $weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
     $shippingWeight = round(max(1, $weight), 0);
     $r->setValue(round($request->getPackageValue(), 2));
     $r->setValueWithDiscount($request->getPackageValueWithDiscount());
     $r->setDestStreet(Mage::helper('core/string')->substr($request->getDestStreet(), 0, 35));
     $r->setDestCity($request->getDestCity());
     if ($request->getDestCountryId()) {
         $destCountry = $request->getDestCountryId();
     } else {
         $destCountry = self::USA_COUNTRY_ID;
     }
     //for DHL, puero rico state for US will assume as puerto rico country
     //for puerto rico, dhl will ship as international
     if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
         $destCountry = self::PUERTORICO_COUNTRY_ID;
     }
     $r->setDestCountryId($destCountry);
     $r->setDestState($request->getDestRegionCode());
     $r->setWeight($shippingWeight);
     $r->setFreeMethodWeight($request->getFreeMethodWeight());
     $this->_rawRequest = $r;
     //        $methods = explode(',', $this->getConfigData('allowed_methods'));
     //
     //        $freeMethod = $this->getConfigData('free_method');
     //
     //        $internationcode = $this->getCode('international_searvice');
     //        $minOrderAmount = $this->getConfigData('cutoff_cost') ? $this->getConfigData('cutoff_cost') : 0;
     //        if ($shippingWeight>0) {
     //             $this->_rawRequest->setWeight($shippingWeight);
     //             $this->_getQuotes();
     //            foreach ($methods as $method) {
     //                if(($method==$internationcode && ($r->getDestCountryId() != self::USA_COUNTRY_ID)) ||
     //                ($method!=$internationcode && ($r->getDestCountryId() == self::USA_COUNTRY_ID)))
     //                {
     //                    $weight = $freeMethod==$method && $this->getConfigData('cutoff_cost') <= $r->getValue() ? 0 : $shippingWeight;
     //                    if ($weight>0) {
     //                        $this->_rawRequest->setWeight($weight);
     //                	    $this->_rawRequest->setService($method);
     //                        $this->_getQuotes();
     //                    } else {
     //                        $this->_dhlRates[$method] = array(
     //                            'term' => $this->getCode('service', $method),
     //                            'price_total' => 0,
     //                        );
     //                    }
     //                }
     //            }
     //        } else {
     //           $this->_errors[] = Mage::helper('usa')->__('Please enter the package weight');
     //        }
     return $this;
 }
Example #19
0
 /**
  * Get all product images
  *
  * @param Varien_Object $product
  * @param int $storeId
  * @return array
  */
 protected function _getAllProductImages($product, $storeId)
 {
     $product->setStoreId($storeId);
     /** @var $mediaGallery Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media */
     $mediaGallery = Mage::getResourceSingleton('Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media');
     $gallery = $mediaGallery->loadGallery($product, $this->_getMediaGalleryModel());
     $imagesCollection = array();
     if ($gallery) {
         $productMediaPath = $this->_getMediaConfig()->getBaseMediaUrlAddition();
         foreach ($gallery as $image) {
             $imagesCollection[] = new Varien_Object(array('url' => $productMediaPath . $image['file'], 'caption' => $image['label'] ? $image['label'] : $image['label_default']));
         }
     }
     return $imagesCollection;
 }
Example #20
0
 protected function _send($post, $template, $email, $storeId)
 {
     if ($email) {
         $translate = Mage::getSingleton('core/translate');
         $translate->setTranslateInline(false);
         $postObject = new Varien_Object();
         $postObject->setData($post);
         $postObject->setStoreId($storeId);
         $mailTemplate = Mage::getModel('core/email_template');
         $pdfGenerator = new Webtex_Giftcards_Model_Email_Pdf();
         //$this->_addAttachment($mailTemplate, $pdfGenerator->getPdf($postObject), 'giftcard.pdf');
         $mailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->sendTransactional(Mage::getStoreConfig($template), 'general', $email, null, array('data' => $postObject));
         $translate->setTranslateInline(true);
     } else {
         throw new Exception('Invalid recipient email address.');
     }
 }
Example #21
0
 /**
  * Retrieve Product data objects
  *
  * @param int|array $productIds
  * @param int $storeId
  * @param int $entityId
  * @param int $lastEntityId
  * @return array
  */
 protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
 {
     $products = array();
     $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
     $adapter = $this->_getReadAdapter();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = array($productIds);
         }
     }
     $bind = array('website_id' => (int) $websiteId, 'entity_id' => (int) $entityId);
     $select = $adapter->select()->useStraightJoin(true)->from(array('e' => $this->getTable('catalog/product')), array('entity_id'))->join(array('w' => $this->getTable('catalog/product_website')), 'e.entity_id = w.product_id AND w.website_id = :website_id', array())->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit);
     if ($productIds !== null) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     $rowSet = $adapter->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new Varien_Object($row);
         $product->setIdFieldName('entity_id');
         $product->setCategoryIds(array());
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($rowSet);
     if ($products) {
         $select = $adapter->select()->from($this->getTable('catalog/category_product'), array('product_id', 'category_id'))->where('product_id IN(?)', array_keys($products));
         $categories = $adapter->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (array('name', 'url_key', 'url_path') as $attributeCode) {
             $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
             foreach ($attributes as $productId => $attributeValue) {
                 $products[$productId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $products;
 }
 /**
  * prepare tab form's information
  *
  * @return Magestore_AffiliateplusBanner_Block_Adminhtml_Affiliateplusbanner_Edit_Tab_Form
  */
 protected function _prepareForm()
 {
     $form = new Varien_Data_Form();
     $this->setForm($form);
     if (Mage::getSingleton('adminhtml/session')->getBannerData()) {
         $data = Mage::getSingleton('adminhtml/session')->getBannerData();
         Mage::getSingleton('adminhtml/session')->setBannerData(null);
     } elseif (Mage::registry('banner_data')) {
         $data = Mage::registry('banner_data')->getData();
     }
     $obj = new Varien_Object($data);
     $fieldset = $form->addFieldset('banner_form', array('legend' => Mage::helper('affiliateplus')->__('Banner information')));
     $inStore = $this->getRequest()->getParam('store');
     $defaultLabel = Mage::helper('affiliateplus')->__('Use Default');
     $defaultTitle = Mage::helper('affiliateplus')->__('-- Please Select --');
     $scopeLabel = Mage::helper('affiliateplus')->__('STORE VIEW');
     if (!$inStore) {
         $disabledTitle = false;
     } else {
         $disabledTitle = !$obj->getData('title_in_store');
     }
     $isDefaultTitleCheck = $disabledTitle ? 'checked="checked"' : '';
     $fieldset->addField('title', 'text', array('label' => Mage::helper('affiliateplus')->__('Title'), 'class' => 'required-entry', 'required' => true, 'name' => 'title', 'disabled' => $disabledTitle, 'after_element_html' => $inStore ? '</td><td class="use-default">
         <input id="title_default" name="title_default" type="checkbox" value="1" class="checkbox config-inherit" ' . $isDefaultTitleCheck . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" />
         <label for="title_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label>
         </td><td class="scope-label">
         [' . $scopeLabel . ']' : '</td><td class="scope-label">[' . $scopeLabel . ']'));
     if (!$inStore) {
         $disabledStatus = false;
     } else {
         $disabledStatus = !$obj->getData('status_in_store');
     }
     $isDefaultStatusCheck = $disabledStatus ? 'checked="checked"' : '';
     $fieldset->addField('status', 'select', array('label' => Mage::helper('affiliateplus')->__('Status'), 'name' => 'status', 'values' => array(array('value' => 1, 'label' => Mage::helper('affiliateplus')->__('Enabled')), array('value' => 2, 'label' => Mage::helper('affiliateplus')->__('Disabled'))), 'disabled' => $disabledStatus, 'after_element_html' => $inStore ? '</td><td class="use-default">
             <input id="status_default" name="status_default" type="checkbox" value="1"' . ' class="checkbox config-inherit" ' . $isDefaultStatusCheck . ' onclick="toggleValueElements(this, Element.previous(this.parentNode))" />
             <label for="status_default" class="inherit" title="' . $defaultTitle . '">' . $defaultLabel . '</label>
             </td><td class="scope-label">
             [' . $scopeLabel . ']' : '</td><td class="scope-label">[' . $scopeLabel . ']'));
     Mage::dispatchEvent('affiliateplus_adminhtml_add_field_banner_form', array('fieldset' => $fieldset, 'form' => $form));
     /** Types Options */
     $fieldset->addField('type_id', 'select', array('label' => Mage::helper('affiliateplus')->__('Banner Type'), 'name' => 'type_id', 'required' => true, 'values' => Mage::helper('affiliateplusbanner')->getOptionArray(), 'disabled' => (bool) $obj->getData('banner_id'), 'onchange' => 'changeBannerType(this)', 'after_element_html' => '</td><td class="label"><a href="javascript:showBannerRotatorTab()" title="' . Mage::helper('affiliateplus')->__('Select Rotator Banners') . '" id="type_id_rotator_banners">' . Mage::helper('affiliateplus')->__('Select Rotator Banners') . '</a>'));
     if ($obj->getData('source_file')) {
         $isRequired = false;
     } else {
         $isRequired = true;
     }
     $sourceConfig = array('label' => Mage::helper('affiliateplus')->__('Source File'), 'name' => 'source_file', 'required' => $isRequired);
     $widthConfig = array('label' => Mage::helper('affiliateplus')->__('Width (px)'), 'name' => 'width');
     $heightConfig = array('label' => Mage::helper('affiliateplus')->__('Height (px)'), 'name' => 'height');
     // Image banner option
     $imgBanner = Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_IMAGE;
     $fieldset->addField("source_file{$imgBanner}", 'file', $sourceConfig);
     $fieldset->addField("width{$imgBanner}", 'text', $widthConfig);
     $fieldset->addField("height{$imgBanner}", 'text', $heightConfig);
     // Flash banner option
     $flashBanner = Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_FLASH;
     $fieldset->addField("source_file{$flashBanner}", 'file', $sourceConfig);
     $fieldset->addField("width{$flashBanner}", 'text', $widthConfig);
     $fieldset->addField("height{$flashBanner}", 'text', $heightConfig);
     // Hover banner option
     $hoverBanner = Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_HOVER;
     $fieldset->addField("source_file{$hoverBanner}", 'file', $sourceConfig);
     $fieldset->addField("width{$hoverBanner}", 'text', $widthConfig);
     $fieldset->addField("height{$hoverBanner}", 'text', $heightConfig);
     // Peel banner option
     $sourceConfig['label'] = Mage::helper('affiliateplus')->__('Small Image');
     $peelBanner = Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_PEEL;
     $fieldset->addField("source_file{$peelBanner}", 'file', $sourceConfig);
     $fieldset->addField("width{$peelBanner}", 'text', $widthConfig);
     $fieldset->addField("height{$peelBanner}", 'text', $heightConfig);
     $fieldset->addField('peel_image', 'file', array('label' => Mage::helper('affiliateplusbanner')->__('Large Image'), 'name' => 'peel_image'));
     $fieldset->addField('peel_width', 'text', array('label' => Mage::helper('affiliateplusbanner')->__('Large Image Width'), 'name' => 'peel_width'));
     $fieldset->addField('peel_height', 'text', array('label' => Mage::helper('affiliateplusbanner')->__('Large Image Height'), 'name' => 'peel_height'));
     $fieldset->addField('peel_direction', 'select', array('label' => Mage::helper('affiliateplusbanner')->__('Banner Position'), 'name' => 'peel_direction', 'values' => Mage::helper('affiliateplusbanner')->getDirectionsArray()));
     // Rotator banner option
     $rotatorBanner = Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_ROTATOR;
     $fieldset->addField("width{$rotatorBanner}", 'text', $widthConfig);
     $fieldset->addField("height{$rotatorBanner}", 'text', $heightConfig);
     $depend = $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')->addFieldMap('type_id', 'type_id')->addFieldMap("source_file{$imgBanner}", "source_file{$imgBanner}")->addFieldMap("width{$imgBanner}", "width{$imgBanner}")->addFieldMap("height{$imgBanner}", "height{$imgBanner}")->addFieldDependence("source_file{$imgBanner}", 'type_id', $imgBanner)->addFieldDependence("width{$imgBanner}", 'type_id', $imgBanner)->addFieldDependence("height{$imgBanner}", 'type_id', $imgBanner)->addFieldMap("source_file{$flashBanner}", "source_file{$flashBanner}")->addFieldMap("width{$flashBanner}", "width{$flashBanner}")->addFieldMap("height{$flashBanner}", "height{$flashBanner}")->addFieldDependence("source_file{$flashBanner}", 'type_id', $flashBanner)->addFieldDependence("width{$flashBanner}", 'type_id', $flashBanner)->addFieldDependence("height{$flashBanner}", 'type_id', $flashBanner)->addFieldMap("source_file{$hoverBanner}", "source_file{$hoverBanner}")->addFieldMap("width{$hoverBanner}", "width{$hoverBanner}")->addFieldMap("height{$hoverBanner}", "height{$hoverBanner}")->addFieldDependence("source_file{$hoverBanner}", 'type_id', $hoverBanner)->addFieldDependence("width{$hoverBanner}", 'type_id', $hoverBanner)->addFieldDependence("height{$hoverBanner}", 'type_id', $hoverBanner)->addFieldMap("source_file{$peelBanner}", "source_file{$peelBanner}")->addFieldMap("width{$peelBanner}", "width{$peelBanner}")->addFieldMap("height{$peelBanner}", "height{$peelBanner}")->addFieldMap('peel_image', 'peel_image')->addFieldMap('peel_width', 'peel_width')->addFieldMap('peel_height', 'peel_height')->addFieldMap('peel_direction', 'peel_direction')->addFieldDependence("source_file{$peelBanner}", 'type_id', $peelBanner)->addFieldDependence("width{$peelBanner}", 'type_id', $peelBanner)->addFieldDependence("height{$peelBanner}", 'type_id', $peelBanner)->addFieldDependence('peel_image', 'type_id', $peelBanner)->addFieldDependence('peel_width', 'type_id', $peelBanner)->addFieldDependence('peel_height', 'type_id', $peelBanner)->addFieldDependence('peel_direction', 'type_id', $peelBanner)->addFieldMap("width{$rotatorBanner}", "width{$rotatorBanner}")->addFieldMap("height{$rotatorBanner}", "height{$rotatorBanner}")->addFieldDependence("width{$rotatorBanner}", 'type_id', $rotatorBanner)->addFieldDependence("height{$rotatorBanner}", 'type_id', $rotatorBanner);
     if ($obj->getData('type_id') != Magestore_AffiliateplusBanner_Helper_Data::BANNER_TYPE_TEXT && $obj->getData('banner_id')) {
         $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'affiliateplus/banner/';
         $fieldset->addField('banner_view', 'note', array('label' => Mage::helper('affiliateplus')->__('Preview'), 'text' => $this->getLayout()->createBlock('affiliateplusbanner/adminhtml_banner_view')->setBannerObj($obj->setStoreId($inStore))->toHtml()));
         // $depend->addFieldMap('banner_view', 'banner_view')
         //        ->addFieldDependence('banner_view', 'type_id', $obj->getData('type_id'));
     }
     $this->setChild('form_after', $depend);
     foreach (Mage::helper('affiliateplusbanner')->getOptionHash() as $type => $label) {
         $obj->setData('source_file' . $type, $obj->getData('source_file'))->setData('width' . $type, $obj->getData('width'))->setData('height' . $type, $obj->getData('height'));
     }
     /** End types options */
     $fieldset->addField('link', 'text', array('label' => Mage::helper('affiliateplus')->__('Link'), 'name' => 'link'));
     $fieldset->addField('target', 'select', array('label' => Mage::helper('affiliateplus')->__('Target'), 'name' => 'target', 'values' => Mage::helper('affiliateplusbanner')->getTargetArray()));
     $fieldset->addField('rel_nofollow', 'select', array('label' => Mage::helper('affiliateplus')->__('Rel Nofollow'), 'name' => 'rel_nofollow', 'values' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray()));
     if ($obj->getData('banner_id')) {
         $actionCollection = Mage::getResourceModel('affiliateplus/action_collection');
         $actionCollection->getSelect()->columns(array('raw_total' => 'SUM(totals)', 'uni_total' => 'SUM(is_unique)'))->group('type')->where('banner_id = ?', $obj->getData('banner_id'));
         $traffics = array('raw_click' => 0, 'uni_click' => 0, 'raw_view' => 0, 'uni_view' => 0);
         foreach ($actionCollection as $item) {
             if ($item->getType() == '1') {
                 $traffics['raw_view'] = $item->getRawTotal();
                 $traffics['uni_view'] = $item->getUniTotal();
             } else {
                 $traffics['raw_click'] = $item->getRawTotal();
                 $traffics['uni_click'] = $item->getUniTotal();
             }
         }
         $fieldset->addField('clicks', 'note', array('label' => Mage::helper('affiliateplus')->__('Clicks (unique/ raw)'), 'text' => $traffics['uni_click'] . ' / ' . $traffics['raw_click']));
         $fieldset->addField('views', 'note', array('label' => Mage::helper('affiliateplus')->__('Impressions (unique/ raw)'), 'text' => $traffics['uni_view'] . ' / ' . $traffics['raw_view']));
     }
     $form->setValues($obj->getData());
     return parent::_prepareForm();
 }
Example #23
0
 protected function _afterSave(Mage_Core_Model_Abstract $object)
 {
     parent::_afterSave($object);
     if ($object->hasRatingCodes()) {
         try {
             $this->_getWriteAdapter()->beginTransaction();
             $condition = $this->_getWriteAdapter()->quoteInto('rating_id = ?', $object->getId());
             $this->_getWriteAdapter()->delete($this->getTable('rating_title'), $condition);
             if ($ratingCodes = $object->getRatingCodes()) {
                 foreach ($ratingCodes as $storeId => $value) {
                     if (trim($value) == '') {
                         continue;
                     }
                     $data = new Varien_Object();
                     $data->setRatingId($object->getId())->setStoreId($storeId)->setValue($value);
                     $this->_getWriteAdapter()->insert($this->getTable('rating_title'), $data->getData());
                 }
             }
             $this->_getWriteAdapter()->commit();
         } catch (Exception $e) {
             $this->_getWriteAdapter()->rollBack();
         }
     }
     if ($object->hasStores()) {
         try {
             $condition = $this->_getWriteAdapter()->quoteInto('rating_id = ?', $object->getId());
             $this->_getWriteAdapter()->delete($this->getTable('rating_store'), $condition);
             foreach ($object->getStores() as $storeId) {
                 $storeInsert = new Varien_Object();
                 $storeInsert->setStoreId($storeId);
                 $storeInsert->setRatingId($object->getId());
                 $this->_getWriteAdapter()->insert($this->getTable('rating_store'), $storeInsert->getData());
             }
         } catch (Exception $e) {
             $this->_getWriteAdapter()->rollBack();
         }
     }
     return $this;
 }
Example #24
0
 public function onepageCheckoutSaveOrderBefore($observer)
 {
     $quote = $observer->getQuote();
     $order = $observer->getOrder();
     $haveSarpItems = false;
     foreach ($quote->getAllItems() as $item) {
         $sarpSubscriptionType = $item->getProduct()->getCustomOption('aw_sarp_subscription_type');
         if (Mage::helper('sarp')->isSubscriptionType($item) && !is_null($sarpSubscriptionType)) {
             $haveSarpItems = true;
             break;
         }
     }
     if (!Mage::getSingleton('sarp/subscription')->getId() && $haveSarpItems) {
         foreach ($quote->getAllItems() as $item) {
             $sarpSubscriptionType = $item->getProduct()->getCustomOption('aw_sarp_subscription_type');
             if (Mage::helper('sarp')->isSubscriptionType($item) && !is_null($sarpSubscriptionType)) {
                 $startDate = $item->getProduct()->getCustomOption('aw_sarp_subscription_start');
                 if (!$startDate) {
                     continue;
                 }
                 $period = Mage::getModel('sarp/period')->load($sarpSubscriptionType->getValue());
                 $today = Mage::app()->getLocale()->date();
                 if (!$item->getProduct()->getTypeInstance()->isVirtual($item->getProduct())) {
                     $today->addDayOfYear($period->getPaymentOffset());
                 }
                 $startDate = $startDate->getValue();
                 $date = $date = new Zend_Date($startDate, 'Y-MM-dd');
                 if ($date->compare($today, Zend_Date::DATE_SHORT) < 0 || !$period->isAllowedDate($date, $item->getProduct())) {
                     throw new Mage_Core_Exception(Mage::helper('sarp')->__("Selected start date for product '%s' is not valid for specified period", $item->getProduct()->getName()));
                 }
             }
         }
         switch ($order->getPayment()->getMethod()) {
             case AW_Sarp_Model_Payment_Method_Authorizenet::PAYMENT_METHOD_CODE:
                 $paymentModel = Mage::getModel('sarp/payment_method_authorizenet');
                 //hardcode because unable get p.method without subscription
                 $service = $paymentModel->getWebService();
                 $service->setPayment($quote->getPayment());
                 $subscription = new Varien_Object();
                 $subscription->setStoreId($order->getStoreId());
                 $service->setSubscription($subscription);
                 break;
             default:
         }
     }
 }
Example #25
0
 /**
  * Prepare and set request in property of current instance
  *
  * @param Varien_Object $request
  * @return Mage_Usa_Model_Shipping_Carrier_Dhl
  */
 public function setRequest(Varien_Object $request)
 {
     $this->_request = $request;
     $r = new Varien_Object();
     if ($request->getAction() == 'GenerateLabel') {
         $r->setAction('GenerateLabel');
     } else {
         $r->setAction('RateEstimate');
     }
     $r->setIsGenerateLabelReturn($request->getIsGenerateLabelReturn());
     $r->setStoreId($request->getStoreId());
     if ($request->getLimitMethod()) {
         $r->setService($request->getLimitMethod());
     }
     if ($request->getDhlId()) {
         $id = $request->getDhlId();
     } else {
         $id = $this->getConfigData('id');
     }
     $r->setId($id);
     if ($request->getDhlPassword()) {
         $password = $request->getDhlPassword();
     } else {
         $password = $this->getConfigData('password');
     }
     $r->setPassword($password);
     if ($request->getDhlAccount()) {
         $accountNbr = $request->getDhlAccount();
     } else {
         $accountNbr = $this->getConfigData('account');
     }
     $r->setAccountNbr($accountNbr);
     if ($request->getDhlShippingKey()) {
         $shippingKey = $request->getDhlShippingKey();
     } else {
         $shippingKey = $this->getConfigData('shipping_key');
     }
     $r->setShippingKey($shippingKey);
     if ($request->getDhlShippingIntlKey()) {
         $shippingKey = $request->getDhlShippingIntlKey();
     } else {
         $shippingKey = $this->getConfigData('shipping_intlkey');
     }
     $r->setShippingIntlKey($shippingKey);
     if ($request->getDhlShipmentType()) {
         $shipmentType = $request->getDhlShipmentType();
     } else {
         $shipmentType = $this->getConfigData('shipment_type');
     }
     $r->setShipmentType($shipmentType);
     if ($request->getDhlDutiable()) {
         $shipmentDutible = $request->getDhlDutiable();
     } else {
         $shipmentDutible = $this->getConfigData('dutiable');
     }
     $r->setDutiable($shipmentDutible);
     if ($request->getDhlDutyPaymentType()) {
         $dutypaytype = $request->getDhlDutyPaymentType();
     } else {
         $dutypaytype = $this->getConfigData('dutypaymenttype');
     }
     $r->setDutyPaymentType($dutypaytype);
     if ($request->getDhlContentDesc()) {
         $contentdesc = $request->getDhlContentDesc();
     } else {
         $contentdesc = $this->getConfigData('contentdesc');
     }
     $r->setContentDesc($contentdesc);
     if ($request->getDestPostcode()) {
         $r->setDestPostal($request->getDestPostcode());
     }
     if ($request->getOrigCountry()) {
         $origCountry = $request->getOrigCountry();
     } else {
         $origCountry = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $r->getStoreId());
     }
     $r->setOrigCountry($origCountry);
     if ($request->getOrigCountryId()) {
         $origCountryId = $request->getOrigCountryId();
     } else {
         $origCountryId = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $r->getStoreId());
     }
     $r->setOrigCountryId($origCountryId);
     if ($request->getAction() == 'GenerateLabel') {
         $packageParams = $request->getPackageParams();
         $shippingWeight = $request->getPackageWeight();
         if ($packageParams->getWeightUnits() != Zend_Measure_Weight::POUND) {
             $shippingWeight = round(Mage::helper('usa')->convertMeasureWeight($request->getPackageWeight(), $packageParams->getWeightUnits(), Zend_Measure_Weight::POUND));
         }
         if ($packageParams->getDimensionUnits() != Zend_Measure_Length::INCH) {
             $packageParams->setLength(round(Mage::helper('usa')->convertMeasureDimension($packageParams->getLength(), $packageParams->getDimensionUnits(), Zend_Measure_Length::INCH)));
             $packageParams->setWidth(round(Mage::helper('usa')->convertMeasureDimension($packageParams->getWidth(), $packageParams->getDimensionUnits(), Zend_Measure_Length::INCH)));
             $packageParams->setHeight(round(Mage::helper('usa')->convertMeasureDimension($packageParams->getHeight(), $packageParams->getDimensionUnits(), Zend_Measure_Length::INCH)));
         }
         $r->setPackageParams($packageParams);
     } else {
         /*
          * DHL only accepts weight as a whole number. Maximum length is 3 digits.
          */
         $shippingWeight = $request->getPackageWeight();
         if ($shipmentType != 'L') {
             $weight = $this->getTotalNumOfBoxes($shippingWeight);
             $shippingWeight = round(max(1, $weight), 0);
         }
     }
     $r->setValue(round($request->getPackageValue(), 2));
     $r->setValueWithDiscount($request->getPackageValueWithDiscount());
     $r->setCustomsValue($request->getPackageCustomsValue());
     $r->setDestStreet(Mage::helper('core/string')->substr(str_replace("\n", '', $request->getDestStreet()), 0, 35));
     $r->setDestStreetLine2($request->getDestStreetLine2());
     $r->setDestCity($request->getDestCity());
     $r->setOrigCompanyName($request->getOrigCompanyName());
     $r->setOrigCity($request->getOrigCity());
     $r->setOrigPhoneNumber($request->getOrigPhoneNumber());
     $r->setOrigPersonName($request->getOrigPersonName());
     $r->setOrigEmail(Mage::getStoreConfig('trans_email/ident_general/email', $r->getStoreId()));
     $r->setOrigCity($request->getOrigCity());
     $r->setOrigPostal($request->getOrigPostal());
     $originStreet1 = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_ADDRESS1, $r->getStoreId());
     $originStreet2 = Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_ADDRESS2, $r->getStoreId());
     $r->setOrigStreet($request->getOrigStreet() ? $request->getOrigStreet() : $originStreet2);
     $r->setOrigStreetLine2($request->getOrigStreetLine2());
     $r->setDestPhoneNumber($request->getDestPhoneNumber());
     $r->setDestPersonName($request->getDestPersonName());
     $r->setDestCompanyName($request->getDestCompanyName());
     if (is_numeric($request->getOrigState())) {
         $r->setOrigState(Mage::getModel('directory/region')->load($request->getOrigState())->getCode());
     } else {
         $r->setOrigState($request->getOrigState());
     }
     if ($request->getDestCountryId()) {
         $destCountry = $request->getDestCountryId();
     } else {
         $destCountry = self::USA_COUNTRY_ID;
     }
     //for DHL, puero rico state for US will assume as puerto rico country
     //for puerto rico, dhl will ship as international
     if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
         $destCountry = self::PUERTORICO_COUNTRY_ID;
     }
     $r->setDestCountryId($destCountry);
     $r->setDestState($request->getDestRegionCode());
     $r->setWeight($shippingWeight);
     $r->setFreeMethodWeight($request->getFreeMethodWeight());
     $r->setOrderShipment($request->getOrderShipment());
     if ($request->getPackageId()) {
         $r->setPackageId($request->getPackageId());
     }
     $r->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
     $this->_rawRequest = $r;
     return $this;
 }
Example #26
0
 /**
  * Called on 
  * 	core_block_abstract_to_html_before
  *
  * Checks if the "esi" variable is set on a block.
  * 	If yes, the template of the block is replaced by varnish/esi.phtml which contains the <esi:include> tag
  * 	it also adds to the response the header X-magento-doesi which will be interpreted by varnish and tell it to do the esi processing
  * 
  * @param array $eventObject
  */
 public function injectEsi($eventObject)
 {
     //No ESI injection if the module is disabled or the request is made on HTTPS
     if (!Mage::helper('varnish')->isVarnishModuleEnabled() || Mage::app()->getRequest()->isSecure()) {
         return;
     }
     $block = $eventObject->getBlock();
     if ($block instanceof Mage_Core_Block_Template) {
         $esi = $block->getEsi();
         if ($esi == true) {
             //We don't allow ESI in admin, for now. Maybe in future releases.
             if (Mage::app()->getStore()->getCode() == 'admin') {
                 throw new Mage_Adminhtml_Exception("ESI includes are forbidden in Admin");
             }
             // We replace the template of the block by the varnish/esi.phtml template
             // The HTML of our template will replace the real HTML of the block
             $block->setTemplate('varnish/esi.phtml');
             $src = new Varien_Object();
             //Blocks change depending on the store id, so we keep track of that
             $src->setStoreId(Mage::app()->getStore()->getId());
             //Blocks also change depending on the design so we keep track of the package and the theme of the current block
             $src->setDesignPackage(Mage::getDesign()->getPackageName());
             $src->setDesignTheme(Mage::getDesign()->getTheme('layout'));
             $src->setNameInLayout($block->getNameInLayout());
             /*
              * Set the cache type
              * 	per-client
              *  per-page
              * 	global
              *
              * 
              * per-client tells varnish to cache the block per-client basis.
              * per-page tells varnish to cache the content based on the url of the page.
              * global tells varnish to serve the same cached version to every client.
              * 
              * The per-client cache is based on the frontend cookie of the client.
              * 
              * We default the cache type to "global"
              */
             if (empty($esi['cache_type'])) {
                 $esi['cache_type'] = 'global';
             }
             $src->setCacheType($esi['cache_type']);
             /**
              *	If the block is cached on a per-page basis
              *	we create an entry in our ESI table to keep track the URLs where the block appear
              *	 
              */
             if ($src->getCacheType() === 'per-page') {
                 $parentUrl = Mage::app()->getRequest()->getRequestString();
                 $src->setParentUrl($parentUrl);
             }
             /**
              * Expiry (or TTL in Varnish lingo). How lon will the object be stored in Varnish?
              * TODO: make sure the expiry is in format 1d 24h 1140m 86400s
              */
             if (!empty($esi['expiry'])) {
                 $src->setExpiry($esi['expiry']);
             } else {
                 if ($src->getCacheType() === 'per-client') {
                     $src->setExpiry(Mage::getStoreConfig('varnish/cache/per_client_default_expiry'));
                 } else {
                     if ($src->getCacheType() === 'per-page') {
                         $src->setExpiry(Mage::getStoreConfig('varnish/cache/per_page_default_expiry'));
                     } else {
                         $src->setExpiry(Mage::getStoreConfig('varnish/cache/global_default_expiry'));
                     }
                 }
             }
             //We create a unique fingerprint with all our values
             foreach ($src->getData() as $value) {
                 $this->_hash($value);
             }
             // $src is the source for our <esi:include> it is composed of all the above variables
             $src->setUrl("/varnish/cache/getBlock/cachetype/{$src->getCacheType()}/expiry/{$src->getExpiry()}/fingerprint/{$this->_hash()}");
             /**
              * Registry save:
              * 	some block rely on values stored in the Mage::registry().
              * 	For example, the product page relies on Mage::registry('current_product');
              *  The problem is that the Mage::registry is not persistent between requests. This means that once the request is served,
              *  the registry looses its data.
              *  This means that when Varnish makes the ESI request, the registry is empty and if the block makes a call to Mage::registry('current_product')
              *  the function will return null.
              *  In order to strive this problem, when you setEsi on a block using the mage registry, you need to specify in the layout which keys you want to keep.
              *  These keys will be saved in the magento cache and thus be accessible when the ESI request is made
              */
             if (!empty($esi['registry_keys'])) {
                 // We create an array with the <registry_keys></registry_keys> set in the layout
                 $registryKeys = explode(',', $esi['registry_keys']);
                 // We iterate through each of the registrykey...
                 foreach ($registryKeys as $registryKey) {
                     $registryContent = Mage::registry($registryKey);
                     if ($registryContent !== null) {
                         // If the key exist we save the content in an array
                         $registry[] = array("key" => $registryKey, "content" => $registryContent);
                     }
                 }
                 $src->setRegistry($registry);
             }
             $src->setBlockType(get_class($block));
             // and we save the content in the cache with the hash as the id
             $cache = Mage::helper('varnish')->getRedisCache();
             $tags = array("VARNISH_CACHETYPE_{$src->getCacheType()}", "VARNISH_BLOCKTYPE_{$src->getBlockType()}", "VARNISH_BLOCKNAME_{$src->getNameInLayout()}");
             $cache->save(serialize($src), $this->_hash(), $tags, null);
             $block->setSrc($src);
             // Tell varnish to do esi processing on the page
             Mage::getSingleton('varnish/cache')->setDoEsi(true);
         }
     }
 }