/** * Render order review xml * * @return string */ protected function _toHtml() { $orderXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<order></order>'); /** * Order items */ $products = $this->getChildHtml('order_products'); if ($products) { $productsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element($products); $orderXmlObj->appendChild($productsXmlObj); } /** * Totals */ $totalsXml = $this->getChildHtml('totals'); if ($totalsXml) { $totalsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element($totalsXml); $orderXmlObj->appendChild($totalsXmlObj); } /** * Agreements */ $agreements = $this->getChildHtml('agreements'); if ($agreements) { $agreementsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element($agreements); $orderXmlObj->appendChild($agreementsXmlObj); } return $orderXmlObj->asNiceXml(); }
/** * Render block HTML * * @return string */ protected function _toHtml() { $categoryXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<category></category>'); $categoryId = $this->getRequest()->getParam('id', null); if ($categoryId === null) { $categoryId = Mage::app()->getStore()->getRootCategoryId(); } $productsXmlObj = $productListBlock = false; $categoryModel = Mage::getModel('catalog/category')->load($categoryId); if ($categoryModel->getId()) { $hasMoreProductItems = 0; $productListBlock = $this->getChild('product_list'); if ($productListBlock && $categoryModel->getLevel() > 1) { $layer = Mage::getSingleton('catalog/layer'); $productsXmlObj = $productListBlock->setCategory($categoryModel)->setLayer($layer)->getProductsXmlObject(); $hasMoreProductItems = (int) $productListBlock->getHasProductItems(); } $infoBlock = $this->getChild('category_info'); if ($infoBlock) { $categoryInfoXmlObj = $infoBlock->setCategory($categoryModel)->getCategoryInfoXmlObject(); $categoryInfoXmlObj->addChild('has_more_items', $hasMoreProductItems); $categoryXmlObj->appendChild($categoryInfoXmlObj); } } /** @var $categoryCollection Mage_XmlConnect_Model_Mysql4_Category_Collection */ $categoryCollection = Mage::getResourceModel('xmlconnect/category_collection'); $categoryCollection->setStoreId(Mage::app()->getStore()->getId())->setOrder('position', 'ASC')->addParentIdFilter($categoryId); // subcategories are exists if (sizeof($categoryCollection)) { $itemsXmlObj = $categoryXmlObj->addChild('items'); foreach ($categoryCollection->getItems() as $item) { $itemXmlObj = $itemsXmlObj->addChild('item'); $itemXmlObj->addChild('label', $categoryXmlObj->xmlentities(strip_tags($item->getName()))); $itemXmlObj->addChild('entity_id', $item->getEntityId()); $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products'); if (!is_null($categoryId)) { $itemXmlObj->addChild('parent_id', $item->getParentId()); } $icon = Mage::helper('xmlconnect/catalog_category_image')->initialize($item, 'thumbnail')->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('category')); $iconXml = $itemXmlObj->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); } } if ($productListBlock && $productsXmlObj) { $categoryXmlObj->appendChild($productsXmlObj); } return $categoryXmlObj->asNiceXml(); }
/** * Add cart details to XML object * * @param Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj * @return Mage_XmlConnect_Model_Simplexml_Element */ public function addDetailsToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $reviewXmlObj) { $itemsXmlObj = $reviewXmlObj->addChild('ordered_items'); foreach ($this->getItems() as $item) { $this->getItemXml($item, $itemsXmlObj); } $reviewXmlObj->appendChild($this->getChild('totals')->setReturnObjectFlag(true)->_toHtml()); return $reviewXmlObj; }
/** * Add related products info to xml object * * @param Mage_XmlConnect_Model_Simplexml_Element $relatedXmlObj * @param array $collection * @return Mage_XmlConnect_Model_Simplexml_Element */ protected function _addProductXmlObj(Mage_XmlConnect_Model_Simplexml_Element $relatedXmlObj, $collection) { foreach ($collection as $product) { $productXmlObj = $this->productToXmlObject($product); if (!$productXmlObj) { continue; } if ($this->getParentBlock()->getChild('product_price')) { $this->getParentBlock()->getChild('product_price')->setProduct($product)->setProductXmlObj($productXmlObj)->collectProductPrices(); } $relatedXmlObj->appendChild($productXmlObj); } return $relatedXmlObj; }
/** * Produce reviews list xml object * * @return Mage_XmlConnect_Model_Simplexml_Element */ public function getReviewsXmlObject() { $reviewsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<reviews></reviews>'); $collection = $this->_getReviewCollection(); if (!$collection) { return $reviewsXmlObj; } foreach ($collection->getItems() as $review) { $reviewXmlObj = $this->reviewToXmlObject($review); if ($reviewXmlObj) { $reviewsXmlObj->appendChild($reviewXmlObj); } } return $reviewsXmlObj; }
/** * Produce products list xml object * * @return Mage_XmlConnect_Model_Simplexml_Element */ public function getProductsXmlObject() { $productsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<products></products>'); $collection = $this->_getProductCollection(); if (!$collection) { return false; } foreach ($collection->getItems() as $product) { $productXmlObj = $this->productToXmlObject($product); if ($productXmlObj) { $productsXmlObj->appendChild($productXmlObj); } } return $productsXmlObj; }
/** * Add sales info to xml object * * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj * @return Mage_XmlConnect_Block_Adminhtml_Connect_StoreSwitcher */ public function addSwitcherToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) { $websites = $this->getWebsites(); if ($websites) { $this->setUseConfirm(false); /** @var $storeSwitcherField Mage_XmlConnect_Model_Simplexml_Form_Element_Custom */ $storeSwitcherField = Mage::getModel('xmlconnect/simplexml_form_element_custom', array('label' => $this->__('Choose Store View'))); $storeSwitcherField->setId('store_id'); $storeSwitcherXmlObj = $storeSwitcherField->toXmlObject(); $this->_createStoreItemList($websites, $storeSwitcherXmlObj); if (!$storeSwitcherXmlObj->getAttribute('value')) { $storeSwitcherXmlObj->addAttribute('value', Mage_XmlConnect_Helper_AdminApplication::ALL_STORE_VIEWS); } $xmlObj->appendChild($storeSwitcherXmlObj); } return $this; }
/** * Render cart summary xml * * @return string */ protected function _toHtml() { $quote = $this->getQuote(); $xmlObject = new Mage_XmlConnect_Model_Simplexml_Element('<cart></cart>'); $xmlObject->addChild('is_virtual', (int) $this->helper('checkout/cart')->getIsVirtualQuote()); $xmlObject->addChild('summary_qty', (int) $this->helper('checkout/cart')->getSummaryCount()); $xmlObject->addChild('virtual_qty', (int) $quote->getItemVirtualQty()); if (strlen($quote->getCouponCode())) { $xmlObject->addChild('has_coupon_code', 1); } $totalsXml = $this->getChildHtml('totals'); if ($totalsXml) { $totalsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element($totalsXml); $xmlObject->appendChild($totalsXmlObj); } return $xmlObject->asNiceXml(); }
/** * Add sales info to xml object * * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj * @return Mage_XmlConnect_Block_Adminhtml_Connect_SalesInfo */ public function addSalesInfoToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) { if (count($this->getTotals()) > 0) { /** @var $salesInfoField Mage_XmlConnect_Model_Simplexml_Form_Element_Custom */ $salesInfoField = Mage::getModel('xmlconnect/simplexml_form_element_custom', array('label' => '')); $salesInfoField->setId('sales_info'); $salesInfoXmlObj = $salesInfoField->toXmlObject(); $storeId = null; foreach ($this->getTotals() as $total) { if (null === $storeId || $storeId !== $total['store_id']) { $storeId = $total['store_id']; $valuesXmlObj = $salesInfoXmlObj->addCustomChild('values', null, array('store_id' => $storeId)); } $valuesXmlObj->addCustomChild('item', strip_tags($total['value']), array('label' => $total['label'])); } $xmlObj->appendChild($salesInfoXmlObj); } return $this; }
/** * Retrieve related products xml object based on current product * * @return Mage_XmlConnect_Model_Simplexml_Element * @see $this->getProduct() */ public function getRelatedProductsXmlObj() { $relatedXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<related_products></related_products>'); if ($this->getParentBlock()->getProduct()->getId() > 0) { $collection = $this->_getProductCollection(); if (!$collection) { return $relatedXmlObj; } foreach ($collection->getItems() as $product) { $productXmlObj = $this->productToXmlObject($product); if ($productXmlObj) { if ($this->getParentBlock()->getChild('product_price')) { $this->getParentBlock()->getChild('product_price')->setProduct($product)->setProductXmlObj($productXmlObj)->collectProductPrices(); } $relatedXmlObj->appendChild($productXmlObj); } } } return $relatedXmlObj; }
/** * Render filters list xml * * @return string */ protected function _toHtml() { $categoryId = $this->getRequest()->getParam('category_id', null); $categoryXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<category></category>'); $filtersCollection = Mage::getResourceModel('xmlconnect/filter_collection')->setCategoryId($categoryId); $filtersXmlObj = $categoryXmlObj->addChild('filters'); foreach ($filtersCollection->getItems() as $item) { if (!sizeof($item->getValues())) { continue; } $itemXmlObj = $filtersXmlObj->addChild('item'); $itemXmlObj->addChild('name', $categoryXmlObj->xmlentities(strip_tags($item->getName()))); $itemXmlObj->addChild('code', $categoryXmlObj->xmlentities($item->getCode())); $valuesXmlObj = $itemXmlObj->addChild('values'); foreach ($item->getValues() as $value) { $valueXmlObj = $valuesXmlObj->addChild('value'); $valueXmlObj->addChild('id', $categoryXmlObj->xmlentities($value->getValueString())); $valueXmlObj->addChild('label', $categoryXmlObj->xmlentities(strip_tags($value->getLabel()))); $valueXmlObj->addChild('count', (int) $value->getProductsCount()); } } $categoryXmlObj->appendChild($this->getProductSortFeildsXmlObject()); return $categoryXmlObj->asNiceXml(); }
/** * Add data select field to xml object * * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj * @return Mage_XmlConnect_Block_Adminhtml_Connect_Dashboard_GraphInfo */ protected function _addDataSelector(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) { /** @var $rangeXmlObj Mage_XmlConnect_Model_Simplexml_Form_Element_Select */ $rangeXmlObj = Mage::getModel('xmlconnect/simplexml_form_element_select', array('label' => $this->__('Select Chart'), 'value' => 'orders', 'options' => array(array('label' => $this->__('Orders'), 'value' => 'orders'), array('label' => $this->__('Amounts'), 'value' => 'amounts')))); $rangeXmlObj->setId('data_details_id'); $xmlObj->appendChild($rangeXmlObj->toXmlObject()); return $this; }
/** * Add after element xml to object * * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObj * @return Mage_XmlConnect_Model_Simplexml_Form_Abstract */ public function addAfterXmlElementToObj(Mage_XmlConnect_Model_Simplexml_Element $xmlObj) { if ($this->_checkXmlInstance($this->getAfterElementXml())) { $xmlObj->appendChild($this->getAfterElementXml()); } elseif (is_array($this->getAfterElementXml())) { foreach ($this->getAfterElementXml() as $afterElement) { if (!$this->_checkXmlInstance($afterElement)) { continue; } $xmlObj->appendChild($afterElement); } } return $this; }
/** * Search results xml renderer * XML also contains filters that can be apply (accorfingly already applyed filters and search query) * and sort fields * * @return string */ protected function _toHtml() { $searchXmlObject = new Mage_XmlConnect_Model_Simplexml_Element('<search></search>'); $filtersXmlObject = new Mage_XmlConnect_Model_Simplexml_Element('<filters></filters>'); $helper = Mage::helper('catalogsearch'); if (method_exists($helper, 'getEngine')) { $engine = Mage::helper('catalogsearch')->getEngine(); $isLayeredNavigationAllowed = $engine instanceof Varien_Object ? $engine->isLeyeredNavigationAllowed() : true; } else { $isLayeredNavigationAllowed = true; } $request = $this->getRequest(); $requestParams = $request->getParams(); $hasMoreProductItems = 0; /** * Products */ $productListBlock = $this->getChild('product_list'); if ($productListBlock) { $layer = Mage::getSingleton('catalogsearch/layer'); $productsXmlObj = $productListBlock->setLayer($layer)->setNeedBlockApplyingFilters(!$isLayeredNavigationAllowed)->getProductsXmlObject(); $searchXmlObject->appendChild($productsXmlObj); $hasMoreProductItems = (int) $productListBlock->getHasProductItems(); } $searchXmlObject->addAttribute('has_more_items', $hasMoreProductItems); /** * Filters */ $showFiltersAndOrders = (bool) count($productsXmlObj); $reguest = $this->getRequest(); foreach ($reguest->getParams() as $key => $value) { if (0 === strpos($key, parent::REQUEST_SORT_ORDER_PARAM_REFIX) || 0 === strpos($key, parent::REQUEST_FILTER_PARAM_REFIX)) { $showFiltersAndOrders = false; break; } } if ($isLayeredNavigationAllowed && $productListBlock && $showFiltersAndOrders) { $filters = $productListBlock->getCollectedFilters(); /** * Render filters xml */ foreach ($filters as $filter) { if (!$this->_isFilterItemsHasValues($filter)) { continue; } $item = $filtersXmlObject->addChild('item'); $item->addChild('name', $searchXmlObject->xmlentities($filter->getName())); $item->addChild('code', $filter->getRequestVar()); $values = $item->addChild('values'); foreach ($filter->getItems() as $valueItem) { $count = (int) $valueItem->getCount(); if (!$count) { continue; } $value = $values->addChild('value'); $value->addChild('id', $valueItem->getValueString()); $value->addChild('label', $searchXmlObject->xmlentities(strip_tags($valueItem->getLabel()))); $value->addChild('count', $count); } } $searchXmlObject->appendChild($filtersXmlObject); } /** * Sort fields */ if ($showFiltersAndOrders) { $searchXmlObject->appendChild($this->getProductSortFeildsXmlObject()); } return $searchXmlObject->asNiceXml(); }
/** * Render shopping cart xml * * @return string */ protected function _toHtml() { $cartMessages = $this->getMessages(); $quote = $this->getQuote(); $xmlObject = new Mage_XmlConnect_Model_Simplexml_Element('<cart></cart>'); $xmlObject->addAttribute('is_virtual', (int) $this->helper('checkout/cart')->getIsVirtualQuote()); $xmlObject->addAttribute('summary_qty', (int) $this->helper('checkout/cart')->getSummaryCount()); if (strlen($quote->getCouponCode())) { $xmlObject->addAttribute('has_coupon_code', 1); } $products = $xmlObject->addChild('products'); /* @var $item Mage_Sales_Model_Quote_Item */ foreach ($this->getItems() as $item) { $type = $item->getProductType(); $renderer = $this->getItemRenderer($type)->setItem($item); /** * General information */ $itemXml = $products->addChild('item'); $itemXml->addChild('entity_id', $item->getProduct()->getId()); $itemXml->addChild('entity_type', $type); $itemXml->addChild('item_id', $item->getId()); $itemXml->addChild('name', $xmlObject->xmlentities(strip_tags($renderer->getProductName()))); $itemXml->addChild('code', 'cart[' . $item->getId() . '][qty]'); $itemXml->addChild('qty', $renderer->getQty()); $icon = $renderer->getProductThumbnail()->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small')); $iconXml = $itemXml->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); /** * Price */ $exclPrice = $inclPrice = 0.0; if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') && $item->getWeeeTaxAppliedAmount()) { $exclPrice = $item->getCalculationPrice() + $item->getWeeeTaxAppliedAmount() + $item->getWeeeTaxDisposition(); } else { $exclPrice = $item->getCalculationPrice(); } } if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { $_incl = $this->helper('checkout')->getPriceInclTax($item); if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') && $item->getWeeeTaxAppliedAmount()) { $inclPrice = $_incl + $item->getWeeeTaxAppliedAmount(); } else { $inclPrice = $_incl - $item->getWeeeTaxDisposition(); } } $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); $formatedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); $formatedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); $priceXmlObj = $itemXml->addChild('price'); $formatedPriceXmlObj = $itemXml->addChild('formated_price'); if ($this->helper('tax')->displayCartBothPrices()) { $priceXmlObj->addAttribute('excluding_tax', $exclPrice); $priceXmlObj->addAttribute('including_tax', $inclPrice); $formatedPriceXmlObj->addAttribute('excluding_tax', $formatedExclPrice); $formatedPriceXmlObj->addAttribute('including_tax', $formatedInclPrice); } else { if ($this->helper('tax')->displayCartPriceExclTax()) { $priceXmlObj->addAttribute('regular', $exclPrice); $formatedPriceXmlObj->addAttribute('regular', $formatedExclPrice); } if ($this->helper('tax')->displayCartPriceInclTax()) { $priceXmlObj->addAttribute('regular', $inclPrice); $formatedPriceXmlObj->addAttribute('regular', $formatedInclPrice); } } /** * Subtotal */ $exclPrice = $inclPrice = 0.0; if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') && $item->getWeeeTaxAppliedAmount()) { $exclPrice = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount() + $item->getWeeeTaxRowDisposition(); } else { $exclPrice = $item->getRowTotal(); } } if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { $_incl = $this->helper('checkout')->getSubtotalInclTax($item); if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') && $item->getWeeeTaxAppliedAmount()) { $inclPrice = $_incl + $item->getWeeeTaxAppliedRowAmount(); } else { $inclPrice = $_incl - $item->getWeeeTaxRowDisposition(); } } $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); $formatedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); $formatedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); $subtotalPriceXmlObj = $itemXml->addChild('subtotal'); $subtotalFormatedPriceXmlObj = $itemXml->addChild('formated_subtotal'); if ($this->helper('tax')->displayCartBothPrices()) { $subtotalPriceXmlObj->addAttribute('excluding_tax', $exclPrice); $subtotalPriceXmlObj->addAttribute('including_tax', $inclPrice); $subtotalFormatedPriceXmlObj->addAttribute('excluding_tax', $formatedExclPrice); $subtotalFormatedPriceXmlObj->addAttribute('including_tax', $formatedInclPrice); } else { if ($this->helper('tax')->displayCartPriceExclTax()) { $subtotalPriceXmlObj->addAttribute('regular', $exclPrice); $subtotalFormatedPriceXmlObj->addAttribute('regular', $formatedExclPrice); } if ($this->helper('tax')->displayCartPriceInclTax()) { $subtotalPriceXmlObj->addAttribute('regular', $inclPrice); $subtotalFormatedPriceXmlObj->addAttribute('regular', $formatedInclPrice); } } /** * Options list */ if ($_options = $renderer->getOptionList()) { $itemOptionsXml = $itemXml->addChild('options'); foreach ($_options as $_option) { $_formatedOptionValue = $renderer->getFormatedOptionValue($_option); $optionXml = $itemOptionsXml->addChild('option'); $optionXml->addAttribute('label', $xmlObject->xmlentities(strip_tags($_option['label']))); $optionXml->addAttribute('text', $xmlObject->xmlentities(strip_tags($_formatedOptionValue['value']))); // if (isset($_formatedOptionValue['full_view'])) { // $label = strip_tags($_option['label']); // $value = strip_tags($_formatedOptionValue['full_view']); // } } } /** * Item messages */ if ($messages = $renderer->getMessages()) { $itemMessagesXml = $itemXml->addChild('messages'); foreach ($messages as $message) { $messageXml = $itemMessagesXml->addChild('option'); $messageXml->addChild('type', $message['type']); $messageXml->addChild('text', $xmlObject->xmlentities(strip_tags($message['text']))); } } } /** * Cart messages */ if ($cartMessages) { $messagesXml = $xmlObject->addChild('messages'); foreach ($cartMessages as $status => $messages) { foreach ($messages as $message) { $messageXml = $messagesXml->addChild('message'); $messageXml->addChild('status', $status); $messageXml->addChild('text', strip_tags($message)); } } } /** * Cross Sell Products */ $crossSellXmlObj = new Mage_XmlConnect_Model_Simplexml_Element($this->getChildHtml('crosssell')); $xmlObject->appendChild($crossSellXmlObj); return $xmlObject->asNiceXml(); }