/** * Render shipping methods xml * * @return string */ protected function _toHtml() { $methodsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<shipping_methods></shipping_methods>'); $_shippingRateGroups = $this->getShippingRates(); if ($_shippingRateGroups) { $store = $this->getQuote()->getStore(); $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates) { $methodXmlObj = $methodsXmlObj->addChild('method'); $methodXmlObj->addAttribute('label', $methodsXmlObj->xmlentities(strip_tags($this->getCarrierName($code)))); $ratesXmlObj = $methodXmlObj->addChild('rates'); $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate) { $rateXmlObj = $ratesXmlObj->addChild('rate'); $rateXmlObj->addAttribute('label', $methodsXmlObj->xmlentities(strip_tags($_rate->getMethodTitle()))); $rateXmlObj->addAttribute('code', $_rate->getCode()); if ($_rate->getErrorMessage()) { $rateXmlObj->addChild('error_message', $methodsXmlObj->xmlentities(strip_tags($_rate->getErrorMessage()))); } else { $price = Mage::helper('tax')->getShippingPrice($_rate->getPrice(), Mage::helper('tax')->displayShippingPriceIncludingTax(), $this->getAddress()); $formattedPrice = $store->convertPrice($price, true, false); $rateXmlObj->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml($store->convertPrice($price, false, false))); $rateXmlObj->addAttribute('formated_price', $formattedPrice); } } } } else { Mage::throwException($this->__('Sorry, no quotes are available for this order at this time.')); } return $methodsXmlObj->asNiceXml(); }
/** * Retrieve review data as xml object * * @param Mage_Review_Model_Review $review * @param string $itemNodeName * @return Mage_XmlConnect_Model_Simplexml_Element */ public function reviewToXmlObject(Mage_Review_Model_Review $review, $itemNodeName = 'item') { $rating = 0; $item = new Mage_XmlConnect_Model_Simplexml_Element('<' . $itemNodeName . '></' . $itemNodeName . '>'); if ($review->getId()) { $item->addChild('review_id', $review->getId()); $item->addChild('created_at', $this->formatDate($review->getCreatedAt())); $item->addChild('title', $item->xmlentities(strip_tags($review->getTitle()))); $item->addChild('nickname', $item->xmlentities(strip_tags($review->getNickname()))); $detail = $item->xmlentities($review->getDetail()); if ($itemNodeName == 'item') { $remainder = ''; $deviceType = Mage::helper('xmlconnect')->getDeviceType(); if ($deviceType != Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD) { $detail = Mage::helper('core/string')->truncate($detail, self::REVIEW_DETAIL_TRUNCATE_LEN, '', $remainder, false); } } $item->addChild('detail', $detail); $summary = Mage::getModel('rating/rating')->getReviewSummary($review->getId()); if ($summary->getCount() > 0) { $rating = round($summary->getSum() / $summary->getCount() / 10); } if ($rating) { $item->addChild('rating_votes', $rating); } } return $item; }
/** * Render customer wishlist xml * * @return string */ protected function _toHtml() { $wishlistXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<wishlist></wishlist>'); $hasMoreItems = 0; /** * Apply offset and count */ $request = $this->getRequest(); $offset = (int) $request->getParam('offset', 0); $count = (int) $request->getParam('count', 0); $count = $count <= 0 ? 1 : $count; if ($offset + $count < $this->getWishlistItems()->getSize()) { $hasMoreItems = 1; } $this->getWishlistItems()->getSelect()->limit($count, $offset); $wishlistXmlObj->addAttribute('items_count', $this->getWishlistItemsCount()); $wishlistXmlObj->addAttribute('has_more_items', $hasMoreItems); if ($this->hasWishlistItems()) { /** * @var Mage_Wishlist_Model_Mysql4_Product_Collection */ foreach ($this->getWishlistItems() as $item) { $itemXmlObj = $wishlistXmlObj->addChild('item'); $itemXmlObj->addChild('item_id', $item->getWishlistItemId()); $itemXmlObj->addChild('entity_id', $item->getProductId()); $itemXmlObj->addChild('entity_type_id', $item->getProduct()->getTypeId()); $itemXmlObj->addChild('name', $wishlistXmlObj->xmlentities(strip_tags($item->getName()))); $itemXmlObj->addChild('in_stock', (int) $item->getProduct()->isInStock()); $itemXmlObj->addChild('is_salable', (int) $item->getProduct()->getIsSalable()); /** * If product type is grouped than it has options as its grouped items */ if ($item->getProduct()->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) { $item->setHasOptions(true); } $itemXmlObj->addChild('has_options', (int) $item->getHasOptions()); $icon = $this->helper('catalog/image')->init($item->getProduct(), 'small_image')->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small')); $iconXml = $itemXmlObj->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); $description = $wishlistXmlObj->xmlentities(strip_tags($item->getDescription())); $itemXmlObj->addChild('description', $description); $addedDate = $wishlistXmlObj->xmlentities($this->getFormatedDate($item->getAddedAt())); $itemXmlObj->addChild('added_date', $addedDate); if ($this->getChild('product_price')) { $this->getChild('product_price')->setProduct($item->getProduct())->setProductXmlObj($itemXmlObj)->collectProductPrices(); } if (!$item->getProduct()->getRatingSummary()) { Mage::getModel('review/review')->getEntitySummary($item->getProduct(), Mage::app()->getStore()->getId()); } $ratingSummary = (int) $item->getProduct()->getRatingSummary()->getRatingSummary(); $itemXmlObj->addChild('rating_summary', round($ratingSummary / 10)); $itemXmlObj->addChild('reviews_count', $item->getProduct()->getRatingSummary()->getReviewsCount()); } } return $wishlistXmlObj->asNiceXml(); }
/** * Retrieve product attributes as xml object * * @param Mage_Catalog_Model_Product $product * @param string $itemNodeName * * @return Mage_XmlConnect_Model_Simplexml_Element */ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNodeName = 'item') { $item = new Mage_XmlConnect_Model_Simplexml_Element('<' . $itemNodeName . '></' . $itemNodeName . '>'); if ($product && $product->getId()) { $item->addChild('entity_id', $product->getId()); $item->addChild('name', $item->xmlentities(strip_tags($product->getName()))); $item->addChild('entity_type', $product->getTypeId()); $item->addChild('short_description', $item->xmlentities(strip_tags($product->getShortDescription()))); $description = Mage::helper('xmlconnect')->htmlize($item->xmlentities($product->getDescription())); $item->addChild('description', $description); $item->addChild('link', $product->getProductUrl()); if ($itemNodeName == 'item') { $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small'); $propertyToResizeName = 'small_image'; } else { $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_big'); $propertyToResizeName = 'image'; } $icon = clone Mage::helper('catalog/image')->init($product, $propertyToResizeName)->resize($imageToResize); $iconXml = $item->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); $item->addChild('in_stock', (int) $product->isInStock()); $item->addChild('is_salable', (int) $product->isSalable()); /** * By default all products has gallery (because of collection not load gallery attribute) */ $hasGallery = 1; if ($product->getMediaGalleryImages()) { $hasGallery = sizeof($product->getMediaGalleryImages()) > 0 ? 1 : 0; } $item->addChild('has_gallery', $hasGallery); /** * If product type is grouped than it has options as its grouped items */ if ($product->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) { $product->setHasOptions(true); } $item->addChild('has_options', (int) $product->getHasOptions()); if ($minSaleQty = $this->_getMinimalQty($product)) { $item->addChild('min_sale_qty', (int) $minSaleQty); } if (!$product->getRatingSummary()) { Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId()); } $item->addChild('rating_summary', round((int) $product->getRatingSummary()->getRatingSummary() / 10)); $item->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount()); if ($this->getChild('product_price')) { $this->getChild('product_price')->setProduct($product)->setProductXmlObj($item)->collectProductPrices(); } if ($this->getChild('additional_info')) { $this->getChild('additional_info')->addAdditionalData($product, $item); } } return $item; }
/** * Render cross sell items xml * * @return string */ protected function _toHtml() { $crossSellXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<crosssell></crosssell>'); if (!$this->getItemCount()) { return $crossSellXmlObj->asNiceXml(); } foreach ($this->getItems() as $_item) { $itemXmlObj = $crossSellXmlObj->addChild('item'); $itemXmlObj->addChild('name', $crossSellXmlObj->xmlentities(strip_tags($_item->getName()))); $icon = $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small')); $iconXml = $itemXmlObj->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); $itemXmlObj->addChild('entity_id', $_item->getId()); $itemXmlObj->addChild('entity_type', $_item->getTypeId()); $itemXmlObj->addChild('has_options', (int) $_item->getHasOptions()); if ($this->getChild('product_price')) { $this->getChild('product_price')->setProduct($_item)->setProductXmlObj($itemXmlObj)->collectProductPrices(); } if (!$_item->getRatingSummary()) { Mage::getModel('review/review')->getEntitySummary($_item, Mage::app()->getStore()->getId()); } $itemXmlObj->addChild('rating_summary', round((int) $_item->getRatingSummary()->getRatingSummary() / 10)); $itemXmlObj->addChild('reviews_count', $_item->getRatingSummary()->getReviewsCount()); } return $crossSellXmlObj->asNiceXml(); }
/** * Render agreements xml * * @return string */ protected function _toHtml() { $agreementsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<agreements></agreements>'); if ($this->getAgreements()) { foreach ($this->getAgreements() as $agreement) { $itemXmlObj = $agreementsXmlObj->addChild('item'); $content = $agreementsXmlObj->xmlentities($agreement->getContent()); if (!$agreement->getIsHtml()) { $content = nl2br(strip_tags($content)); } $itemXmlObj->addChild('label', $agreementsXmlObj->xmlentities(strip_tags($agreement->getCheckboxText()))); $itemXmlObj->addChild('content', $content); $itemXmlObj->addChild('code', 'agreement[' . $agreement->getId() . ']'); $itemXmlObj->addChild('agreement_id', $agreement->getId()); } } return $agreementsXmlObj->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(); }
/** * Create produc custom options Mage_XmlConnect_Model_Simplexml_Element object * * @param Mage_Catalog_Model_Product $product * @return Mage_XmlConnect_Model_Simplexml_Element */ public function getProductCustomOptionsXmlObject(Mage_Catalog_Model_Product $product) { $xmlModel = new Mage_XmlConnect_Model_Simplexml_Element('<product></product>'); $optionsNode = $xmlModel->addChild('options'); if (!$product->getId()) { return $xmlModel; } $xmlModel->addAttribute('id', $product->getId()); if (!$product->isSaleable() || !sizeof($product->getOptions())) { return $xmlModel; } foreach ($product->getOptions() as $option) { $optionNode = $optionsNode->addChild('option'); $type = $this->_getOptionTypeForXmlByRealType($option->getType()); $code = 'options[' . $option->getId() . ']'; if ($type == self::OPTION_TYPE_CHECKBOX) { $code .= '[]'; } $optionNode->addAttribute('code', $code); $optionNode->addAttribute('type', $type); $optionNode->addAttribute('label', $xmlModel->xmlentities(strip_tags($option->getTitle()))); if ($option->getIsRequire()) { $optionNode->addAttribute('is_required', 1); } /** * Process option price */ $price = Mage::helper('xmlconnect')->formatPriceForXml($option->getPrice()); if ($price > 0.0) { $optionNode->addAttribute('price', $price); $formatedPrice = Mage::app()->getStore($product->getStoreId())->formatPrice($price, false); $optionNode->addAttribute('formated_price', $formatedPrice); } if ($type == self::OPTION_TYPE_CHECKBOX || $type == self::OPTION_TYPE_SELECT) { foreach ($option->getValues() as $value) { $valueNode = $optionNode->addChild('value'); $valueNode->addAttribute('code', $value->getId()); $valueNode->addAttribute('label', $xmlModel->xmlentities(strip_tags($value->getTitle()))); $price = Mage::helper('xmlconnect')->formatPriceForXml($value->getPrice()); if ($price > 0.0) { $valueNode->addAttribute('price', $price); $formatedPrice = $this->_formatPriceString($price, $product); $valueNode->addAttribute('formated_price', $formatedPrice); } } } } return $xmlModel; }
/** * 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(); }
/** * Search suggestions xml renderer * * @return string */ protected function _toHtml() { $suggestXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<suggestions></suggestions>'); if (!$this->getRequest()->getParam('q', false)) { return $suggestXmlObj->asNiceXml(); } $handler = Mage::getSingleton('factfinder_suggest/handler_suggest', array($this->getRequest()->getParam('q'))); $suggestData = $handler->getSuggestionsAsArray(); if (!($count = count($suggestData))) { return $suggestXmlObj->asNiceXml(); } $items = ''; foreach ($suggestData as $index => $item) { $items .= $suggestXmlObj->xmlentities(strip_tags($item['query'])) . self::SUGGEST_ITEM_SEPARATOR . (int) $item['hitCount'] . self::SUGGEST_ITEM_SEPARATOR; } $suggestXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<suggestions>' . $items . '</suggestions>'); return $suggestXmlObj->asNiceXml(); }
/** * Retrieve product sort fields as xml object * * @return Mage_XmlConnect_Model_Simplexml_Element */ public function getProductSortFeildsXmlObject() { $ordersXmlObject = new Mage_XmlConnect_Model_Simplexml_Element('<orders></orders>'); /* @var $category Mage_Catalog_Model_Category */ $category = Mage::getModel('catalog/category'); $sortOptions = $category->getAvailableSortByOptions(); $sortOptions = array_slice($sortOptions, 0, self::PRODUCT_SORT_FIELDS_NUMBER); $defaultSort = $category->getDefaultSortBy(); foreach ($sortOptions as $code => $name) { $item = $ordersXmlObject->addChild('item'); if ($code == $defaultSort) { $item->addAttribute('isDefault', 1); } $item->addChild('code', $code); $item->addChild('name', $ordersXmlObject->xmlentities(strip_tags($name))); } return $ordersXmlObject; }
/** * Render billing shipping xml * * @return string */ protected function _toHtml() { $shippingXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<shipping></shipping>'); $addressId = $this->getAddress()->getId(); $address = $this->getCustomer()->getPrimaryShippingAddress(); if ($address) { $addressId = $address->getId(); } foreach ($this->getCustomer()->getAddresses() as $address) { $item = $shippingXmlObj->addChild('item'); if ($addressId == $address->getId()) { $item->addAttribute('selected', 1); } $this->getChild('address_list')->prepareAddressData($address, $item); $item->addChild('address_line', $shippingXmlObj->xmlentities($address->format('oneline'))); } return $shippingXmlObj->asNiceXml(); }
/** * Generate bundle product options xml * * @param Mage_Catalog_Model_Product $product * @param bool $isObject * @return string | Mage_XmlConnect_Model_Simplexml_Element */ public function getProductOptionsXml(Mage_Catalog_Model_Product $product, $isObject = false) { $xmlModel = new Mage_XmlConnect_Model_Simplexml_Element('<product></product>'); $optionsNode = $xmlModel->addChild('options'); if (!$product->getId()) { return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } $xmlModel->addAttribute('id', $product->getId()); if (!$product->isSaleable()) { return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } /** * Grouped (associated) products */ $_associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product); if (!sizeof($_associatedProducts)) { return $isObject ? $xmlModel : $xmlModel->asNiceXml(); } foreach ($_associatedProducts as $_item) { if (!$_item->isSaleable()) { continue; } $optionNode = $optionsNode->addChild('option'); $optionNode->addAttribute('code', 'super_group[' . $_item->getId() . ']'); $optionNode->addAttribute('type', 'product'); $optionNode->addAttribute('label', $xmlModel->xmlentities(strip_tags($_item->getName()))); $optionNode->addAttribute('is_qty_editable', 1); $optionNode->addAttribute('qty', $_item->getQty() * 1); /** * Process product price */ if ($_item->getPrice() != $_item->getFinalPrice()) { $productPrice = $_item->getFinalPrice(); } else { $productPrice = $_item->getPrice(); } $productPrice = Mage::helper('xmlconnect')->formatPriceForXml($productPrice); if ($productPrice != 0.0) { $optionNode->addAttribute('price', Mage::helper('xmlconnect')->formatPriceForXml(Mage::helper('core')->currency($productPrice, false, false))); $optionNode->addAttribute('formated_price', $this->_formatPriceString($productPrice, $product)); } } return $isObject ? $xmlModel : $xmlModel->asNiceXml(); }
/** * Search suggestions xml renderer * * @return string */ protected function _toHtml() { $suggestXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<suggestions></suggestions>'); if (!$this->getRequest()->getParam('q', false)) { return $suggestXmlObj->asNiceXml(); } $suggestData = $this->getSuggestData(); if (!($count = count($suggestData))) { return $suggestXmlObj->asNiceXml(); } $items = ''; foreach ($suggestData as $index => $item) { $items .= $suggestXmlObj->xmlentities(strip_tags($item['title'])) . self::SUGGEST_ITEM_SEPARATOR . (int) $item['num_of_results'] . self::SUGGEST_ITEM_SEPARATOR; // $itemXmlObj = $suggestXmlObj->addChild('item'); // $itemXmlObj->addChild('title', $suggestXmlObj->xmlentities(strip_tags($item['title']))); // $itemXmlObj->addChild('count', (int)$item['num_of_results']); } $suggestXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<suggestions>' . $items . '</suggestions>'); return $suggestXmlObj->asNiceXml(); }
/** * Render customer orders list xml * * @return string */ protected function _toHtml() { $ordersXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<orders></orders>'); $orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))->setOrder('created_at', 'desc'); $orders->getSelect()->limit(self::ORDERS_LIST_LIMIT, 0); $orders->load(); if (sizeof($orders->getItems())) { foreach ($orders as $_order) { $item = $ordersXmlObj->addChild('item'); $item->addChild('entity_id', $_order->getId()); $item->addChild('number', $_order->getRealOrderId()); $item->addChild('date', $this->formatDate($_order->getCreatedAtStoreDate())); if ($_order->getShippingAddress()) { $item->addChild('ship_to', $ordersXmlObj->xmlentities(strip_tags($_order->getShippingAddress()->getName()))); } $item->addChild('total', $_order->getOrderCurrency()->formatPrecision($_order->getGrandTotal(), 2, array(), false, false)); $item->addChild('status', $_order->getStatusLabel()); } } return $ordersXmlObj->asNiceXml(); }
/** * Render home category list xml * * @return string */ protected function _toHtml() { $homeXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<home></home>'); $categoryCollection = Mage::getResourceModel('xmlconnect/category_collection'); $categoryCollection->setStoreId(Mage::app()->getStore()->getId())->addParentIdFilter(Mage::app()->getStore()->getRootCategoryId())->setOrder('position', 'ASC')->setLimit(0, self::HOME_PAGE_CATEGORIES_COUNT); if (sizeof($categoryCollection)) { $itemsXmlObj = $homeXmlObj->addChild('categories'); } foreach ($categoryCollection->getItems() as $item) { $itemXmlObj = $itemsXmlObj->addChild('item'); $itemXmlObj->addChild('label', $homeXmlObj->xmlentities(strip_tags($item->getName()))); $itemXmlObj->addChild('entity_id', $item->getEntityId()); $itemXmlObj->addChild('content_type', $item->hasChildren() ? 'categories' : 'products'); $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)); } $homeXmlObj->addChild('home_banner', '/current/media/catalog/category/banner_home.png'); return $homeXmlObj->asNiceXml(); }
/** * Produce category info xml object * * @return Mage_XmlConnect_Model_Simplexml_Element */ public function getCategoryInfoXmlObject() { $infoXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<category_info></category_info>'); $category = $this->getCategory(); if ($category && is_object($category) && $category->getId()) { /** * @var string $title * * Copied data from "getDefaultApplicationDesignTabs()" method in "Mage_XmlConnect_Helper_Data" */ $title = $this->__('Shop'); if ($category->getParentCategory()->getLevel() > 1) { $title = $infoXmlObj->xmlentities(strip_tags($category->getParentCategory()->getName())); } $infoXmlObj->addChild('parent_title', $title); $pId = 0; if ($category->getLevel() > 1) { $pId = $category->getParentId(); } $infoXmlObj->addChild('parent_id', $pId); } return $infoXmlObj; }
/** * Add total data to totals xml object * * @param Mage_XmlConnect_Model_Simplexml_Element $totalsXmlObj * @param string $code * @param string $title * @param float $value */ protected function _addTotalDataToXmlObj($totalsXmlObj, $code, $title, $value) { $value = Mage::helper('xmlconnect')->formatPriceForXml($value); $totalXmlObj = $totalsXmlObj->addChild($code); $totalXmlObj->addChild('title', $totalsXmlObj->xmlentities($title)); $formattedValue = $this->getQuote()->getStore()->formatPrice($value, false); $totalXmlObj->addChild('value', $value); $totalXmlObj->addChild('formated_value', $formattedValue); }
/** * Add payment method through Pbridge iframe XML object * * @param Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj * @return Mage_XmlConnect_Model_Simplexml_Element */ public function addPaymentFormToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $paymentItemXmlObj) { $paymentItemXmlObj->addAttribute('is_pbridge', 1); $paymentItemXmlObj->addChild('pb_iframe', $paymentItemXmlObj->xmlentities($this->createIframe())); return $paymentItemXmlObj; }
/** * Render order review items * * @return string */ protected function _toHtml() { $itemsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<products></products>'); $quote = Mage::getSingleton('checkout/session')->getQuote(); /* @var $item Mage_Sales_Model_Quote_Item */ foreach ($this->getItems() as $item) { $type = $this->_getItemType($item); $renderer = $this->getItemRenderer($type)->setItem($item); /** * General information */ $itemXml = $itemsXmlObj->addChild('item'); $itemXml->addChild('entity_id', $item->getProduct()->getId()); $itemXml->addChild('entity_type', $type); $itemXml->addChild('item_id', $item->getId()); $itemXml->addChild('name', $itemsXmlObj->xmlentities(strip_tags($renderer->getProductName()))); $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()) { $typeOfDisplay = Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales'); if ($typeOfDisplay && $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); $typeOfDisplay = Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales'); if ($typeOfDisplay && $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()) { $typeOfDisplay = Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales'); if ($typeOfDisplay && $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'); $labelValue = $itemsXmlObj->xmlentities(strip_tags($_option['label'])); $optionXml->addAttribute('label', $labelValue); $textValue = $itemsXmlObj->xmlentities(strip_tags($_formatedOptionValue['value'])); $optionXml->addAttribute('text', $textValue); // if (isset($_formatedOptionValue['full_view'])) { // $label = strip_tags($_option['label']); // $value = strip_tags($_formatedOptionValue['full_view']); // } } } } return $itemsXmlObj->asNiceXml(); }
/** * 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 customer address form xml * * @return string */ protected function _toHtml() { $address = $this->getAddress(); $xmlModel = new Mage_XmlConnect_Model_Simplexml_Element('<node></node>'); $customer = Mage::getSingleton('customer/session')->getCustomer(); $addressType = $this->getType() == 'shipping' || $this->getType() == 'billing' ? $this->getType() : 'billing'; $isAllowedGuestCheckout = Mage::getSingleton('checkout/session')->getQuote()->isAllowedGuestCheckout(); if ($addressType == 'shipping') { $addressId = $customer->getDefaultShipping(); $address = $customer->getAddressById($addressId); } else { $addressId = $customer->getDefaultBilling(); $address = $customer->getAddressById($addressId); } if ($addressId && $address && $address->getId()) { $firstname = $xmlModel->xmlentities(strip_tags($address->getFirstname())); $lastname = $xmlModel->xmlentities(strip_tags($address->getLastname())); $company = $xmlModel->xmlentities(strip_tags($address->getCompany())); if ($isAllowedGuestCheckout) { $email = $xmlModel->xmlentities(strip_tags($address->getEmail())); } $street1 = $xmlModel->xmlentities(strip_tags($address->getStreet(1))); $street2 = $xmlModel->xmlentities(strip_tags($address->getStreet(2))); $city = $xmlModel->xmlentities(strip_tags($address->getCity())); $regionId = $xmlModel->xmlentities($address->getRegionId()); $region = Mage::getModel('directory/region')->load($regionId)->getName(); if (!$region) { $region = $address->getRegion(); } $region = $xmlModel->xmlentities(strip_tags($region)); $postcode = $xmlModel->xmlentities(strip_tags($address->getPostcode())); $countryId = $xmlModel->xmlentities($address->getCountryId()); $telephone = $xmlModel->xmlentities(strip_tags($address->getTelephone())); $fax = $xmlModel->xmlentities(strip_tags($address->getFax())); } else { $firstname = $lastname = $company = $email = $street1 = $street2 = ''; $city = $region = $postcode = $telephone = $fax = ''; $countryId = $regionId = null; } $countries = $this->_getCountryOptions(); $regions = array(); $countryOptionsXml = '<values>'; if (is_array($countries)) { foreach ($countries as $key => $data) { if ($data['value']) { $regions = $this->_getRegionOptions($data['value']); } $countryOptionsXml .= ' <item relation="' . (is_array($regions) && !empty($regions) ? 'region_id' : 'region') . '"' . ($countryId == $data['value'] ? ' selected="1"' : '') . '> <label>' . $xmlModel->xmlentities((string) $data['label']) . '</label> <value>' . $xmlModel->xmlentities($data['value']) . '</value>'; if (is_array($regions) && !empty($regions)) { $countryOptionsXml .= '<regions>'; foreach ($regions as $_key => $_data) { $countryOptionsXml .= '<region_item' . ($regionId == $_data['value'] ? ' selected="1"' : '') . '>'; $countryOptionsXml .= '<label>' . $xmlModel->xmlentities((string) $_data['label']) . '</label> <value>' . $xmlModel->xmlentities($_data['value']) . '</value>'; $countryOptionsXml .= '</region_item>'; } $countryOptionsXml .= '</regions>'; } $countryOptionsXml .= '</item>'; } } $countryOptionsXml .= '</values>'; $xml = <<<EOT <form name="address_form" method="post"> <field name="{$addressType}[firstname]" type="text" label="{$xmlModel->xmlentities($this->__('First Name'))}" required="true" value="{$firstname}" /> <field name="{$addressType}[lastname]" type="text" label="{$xmlModel->xmlentities($this->__('Last Name'))}" required="true" value="{$lastname}" /> <field name="{$addressType}[company]" type="text" label="{$xmlModel->xmlentities($this->__('Company'))}" value="{$company}" /> EOT; if ($isAllowedGuestCheckout && !Mage::getSingleton('customer/session')->isLoggedIn() && $addressType == 'billing') { $xml .= <<<EOT <field name="{$addressType}[email]" type="text" label="{$xmlModel->xmlentities($this->__('Email Address'))}" value="{$email}" required="true" > <validators> <validator type="email" message="{$xmlModel->xmlentities($this->__('Wrong email format'))}"/> </validators> </field> EOT; } $xml .= <<<EOT <field name="{$addressType}[street][]" type="text" label="{$xmlModel->xmlentities($this->__('Address'))}" required="true" value="{$street1}" /> <field name="{$addressType}[street][]" type="text" label="{$xmlModel->xmlentities($this->__('Address 2'))}" value="{$street2}" /> <field name="{$addressType}[city]" type="text" label="{$xmlModel->xmlentities($this->__('City'))}" required="true" value="{$city}" /> <field name="{$addressType}[country_id]" type="select" label="{$xmlModel->xmlentities($this->__('Country'))}" required="true"> {$countryOptionsXml} </field> <field name="{$addressType}[region]" type="text" label="{$xmlModel->xmlentities($this->__('State/Province'))}" value="{$region}" /> <field name="{$addressType}[region_id]" type="select" label="{$xmlModel->xmlentities($this->__('State/Province'))}" required="true" /> <field name="{$addressType}[postcode]" type="text" label="{$xmlModel->xmlentities($this->__('Zip/Postal Code'))}" required="true" value="{$postcode}" /> <field name="{$addressType}[telephone]" type="text" label="{$xmlModel->xmlentities($this->__('Telephone'))}" required="true" value="{$telephone}" /> <field name="{$addressType}[fax]" type="text" label="{$xmlModel->xmlentities($this->__('Fax'))}" value="{$fax}" /> <field name="{$addressType}[save_in_address_book]" type="checkbox" label="{$xmlModel->xmlentities($this->__('Save in address book'))}"/> </form> EOT; return $xml; }
/** * Render customer form xml * * @return string */ protected function _toHtml() { $editFlag = (int) $this->getRequest()->getParam('edit'); $customer = $this->getCustomer(); $xmlModel = new Mage_XmlConnect_Model_Simplexml_Element('<node></node>'); if ($editFlag == 1 && $customer && $customer->getId()) { $firstname = $xmlModel->xmlentities(strip_tags($customer->getFirstname())); $lastname = $xmlModel->xmlentities(strip_tags($customer->getLastname())); $email = $xmlModel->xmlentities(strip_tags($customer->getEmail())); } else { $firstname = $lastname = $email = ''; } if ($editFlag) { $passwordManageXml = ' <field name="change_password" type="checkbox" label="' . $xmlModel->xmlentities($this->__('Change Password')) . '"/> </fieldset> <fieldset> <field name="current_password" type="password" label="' . $xmlModel->xmlentities($this->__('Current Password')) . '"/> <field name="password" type="password" label="' . $xmlModel->xmlentities($this->__('New Password')) . '"/> <field name="confirmation" type="password" label="' . $xmlModel->xmlentities($this->__('Confirm New Password')) . '"> <validators> <validator type="confirmation" message="' . $xmlModel->xmlentities($this->__('Regular and confirmation passwords must be equal')) . '">password</validator> </validators> </field> </fieldset>'; } else { $passwordManageXml = ' <field name="password" type="password" label="' . $xmlModel->xmlentities($this->__('Password')) . '" required="true"/> <field name="confirmation" type="password" label="' . $xmlModel->xmlentities($this->__('Confirm Password')) . '" required="true"> <validators> <validator type="confirmation" message="' . $xmlModel->xmlentities($this->__('Regular and confirmation passwords must be equal')) . '">password</validator> </validators> </field> </fieldset>'; } $xml = <<<EOT <form name="account_form" method="post"> <fieldset> <field name="firstname" type="text" label="{$xmlModel->xmlentities($this->__('First Name'))}" required="true" value="{$firstname}" /> <field name="lastname" type="text" label="{$xmlModel->xmlentities($this->__('Last Name'))}" required="true" value="{$lastname}" /> <field name="email" type="text" label="{$xmlModel->xmlentities($this->__('Email'))}" required="true" value="{$email}"> <validators> <validator type="email" message="{$xmlModel->xmlentities($this->__('Wrong email format'))}"/> </validators> </field> {$passwordManageXml} </form> EOT; return $xml; }
/** * Collect address data to xml node * Remove objects from data array and escape data values * * @param Mage_Customer_Model_Address $address * @param Mage_XmlConnect_Model_Simplexml_Element $item * @return array */ public function prepareAddressData(Mage_Customer_Model_Address $address, Mage_XmlConnect_Model_Simplexml_Element $item) { if (!$address) { return array(); } $attributes = Mage::helper('customer/address')->getAttributes(); $data = array('entity_id' => $address->getId()); foreach ($attributes as $attribute) { /* @var $attribute Mage_Customer_Model_Attribute */ if (!$attribute->getIsVisible()) { continue; } if ($attribute->getAttributeCode() == 'country_id') { $data['country'] = $address->getCountryModel()->getName(); $data['country_id'] = $address->getCountryId(); } else { if ($attribute->getAttributeCode() == 'region') { $data['region'] = $address->getRegion(); } else { $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $address); $value = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE); if ($attribute->getFrontendInput() == 'multiline') { $values = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY); // explode lines foreach ($values as $k => $v) { $key = sprintf('%s%d', $attribute->getAttributeCode(), $k + 1); $data[$key] = $v; } } $data[$attribute->getAttributeCode()] = $value; } } } foreach ($data as $key => $value) { if (empty($value)) { continue; } $item->addChild($key, $item->xmlentities($value)); } }
/** * Render payment methods xml * * @return string * @throw Mage_Core_Exception */ protected function _toHtml() { $methodsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<payment_methods></payment_methods>'); $methodBlocks = $this->getChild(); $methodArray = array('payment_ccsave' => 'Mage_Payment_Model_Method_Cc', 'payment_checkmo' => 'Mage_Payment_Model_Method_Checkmo', 'payment_purchaseorder' => 'Mage_Payment_Model_Method_Purchaseorder'); $usedMethods = $sortedAvailableMethodCodes = $usedCodes = array(); $allAvailableMethods = Mage::helper('payment')->getStoreMethods(Mage::app()->getStore(), $this->getQuote()); foreach ($allAvailableMethods as $method) { $sortedAvailableMethodCodes[] = $method->getCode(); } /** * Collect directly supported by xmlconnect methods */ foreach ($methodBlocks as $block) { if (!$block) { continue; } $method = $block->getMethod(); if (!$this->_canUseMethod($method) || in_array($method->getCode(), $usedCodes)) { continue; } $this->_assignMethod($method); $usedCodes[] = $method->getCode(); $usedMethods[$method->getCode()] = array('renderer' => $block, 'method' => $method); } /** * Collect all "Credit Card" / "CheckMo" / "Purchaseorder" method compatible methods */ foreach ($methodArray as $methodName => $methodModelClassName) { $methodRenderer = $this->getChild($methodName); if (!is_null($methodRenderer)) { foreach ($sortedAvailableMethodCodes as $methodCode) { /** * Skip used methods */ if (in_array($methodCode, $usedCodes)) { continue; } try { $method = Mage::helper('payment')->getMethodInstance($methodCode); if (!is_subclass_of($method, $methodModelClassName)) { continue; } if (!$this->_canUseMethod($method)) { continue; } $this->_assignMethod($method); $usedCodes[] = $method->getCode(); $usedMethods[$method->getCode()] = array('renderer' => $methodRenderer, 'method' => $method); } catch (Exception $e) { Mage::logException($e); } } } } /** * Generate methods XML according to sort order */ foreach ($sortedAvailableMethodCodes as $code) { if (!in_array($code, $usedCodes)) { continue; } $method = $usedMethods[$code]['method']; $renderer = $usedMethods[$code]['renderer']; /** * Render all Credit Card method compatible methods */ if ($renderer instanceof Mage_XmlConnect_Block_Checkout_Payment_Method_Ccsave) { $renderer->setData('method', $method); } $methodItemXmlObj = $methodsXmlObj->addChild('method'); $methodItemXmlObj->addAttribute('post_name', 'payment[method]'); $methodItemXmlObj->addAttribute('code', $method->getCode()); $methodItemXmlObj->addAttribute('label', $methodsXmlObj->xmlentities(strip_tags($method->getTitle()))); if ($this->getQuote()->getPayment()->getMethod() == $method->getCode()) { $methodItemXmlObj->addAttribute('selected', 1); } $renderer->addPaymentFormToXmlObj($methodItemXmlObj); } if (!count($usedMethods)) { Mage::throwException($this->__('Sorry, no payment options are available for this order at this time.')); } return $methodsXmlObj->asNiceXml(); }
/** * Render customer address form xml * * @return string */ protected function _toHtml() { $address = $this->getAddress(); $xmlModel = new Mage_XmlConnect_Model_Simplexml_Element('<node></node>'); /** * Init address object and save its data to variables */ $addressId = (int) $this->getRequest()->getParam('id'); if ($addressId && $address && $address->getId()) { $defaultBillingAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling(); $defaultShippingAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping(); $billingChecked = $addressId == $defaultBillingAddressId ? ' checked="1"' : ''; $shippingChecked = $addressId == $defaultShippingAddressId ? ' checked="1"' : ''; $firstname = $xmlModel->xmlentities(strip_tags($address->getFirstname())); $lastname = $xmlModel->xmlentities(strip_tags($address->getLastname())); $company = $xmlModel->xmlentities(strip_tags($address->getCompany())); $street1 = $xmlModel->xmlentities(strip_tags($address->getStreet(1))); $street2 = $xmlModel->xmlentities(strip_tags($address->getStreet(2))); $city = $xmlModel->xmlentities(strip_tags($address->getCity())); $regionId = $xmlModel->xmlentities($address->getRegionId()); $region = Mage::getModel('directory/region')->load($regionId)->getName(); if (!$region) { $region = $address->getRegion(); } $region = $xmlModel->xmlentities(strip_tags($region)); $postcode = $xmlModel->xmlentities(strip_tags($address->getPostcode())); $countryId = $xmlModel->xmlentities($address->getCountryId()); $telephone = $xmlModel->xmlentities(strip_tags($address->getTelephone())); $fax = $xmlModel->xmlentities(strip_tags($address->getFax())); } else { $firstname = $lastname = $company = $street1 = $street2 = $billingChecked = $shippingChecked = ''; $city = $region = $postcode = $telephone = $fax = ''; $countryId = $regionId = null; } $countries = $this->_getCountryOptions(); $regions = array(); $countryOptionsXml = '<values>'; if (is_array($countries)) { foreach ($countries as $key => $data) { if ($data['value']) { $regions = $this->_getRegionOptions($data['value']); } $countryOptionsXml .= ' <item relation="' . (is_array($regions) && !empty($regions) ? 'region_id' : 'region') . '"' . ($countryId == $data['value'] ? ' selected="1"' : '') . '> <label>' . $xmlModel->xmlentities((string) $data['label']) . '</label> <value>' . $xmlModel->xmlentities($data['value']) . '</value>'; if (is_array($regions) && !empty($regions)) { $countryOptionsXml .= '<regions>'; foreach ($regions as $_key => $_data) { $countryOptionsXml .= '<region_item' . ($regionId == $_data['value'] ? ' selected="1"' : '') . '>'; $countryOptionsXml .= '<label>' . $xmlModel->xmlentities((string) $_data['label']) . '</label> <value>' . $xmlModel->xmlentities($_data['value']) . '</value>'; $countryOptionsXml .= '</region_item>'; } $countryOptionsXml .= '</regions>'; } $countryOptionsXml .= '</item>'; } } $countryOptionsXml .= '</values>'; $xml = <<<EOT <form name="address_form" method="post"> <fieldset legend="{$xmlModel->xmlentities($this->__('Contact Information'))}"> <field name="firstname" type="text" label="{$xmlModel->xmlentities($this->__('First Name'))}" required="true" value="{$firstname}" /> <field name="lastname" type="text" label="{$xmlModel->xmlentities($this->__('Last Name'))}" required="true" value="{$lastname}" /> <field name="company" type="text" label="{$xmlModel->xmlentities($this->__('Company'))}" value="{$company}" /> <field name="telephone" type="text" label="{$xmlModel->xmlentities($this->__('Telephone'))}" required="true" value="{$telephone}" /> <field name="fax" type="text" label="{$xmlModel->xmlentities($this->__('Fax'))}" value="{$fax}" /> </fieldset> <fieldset legend="Address"> <field name="street[]" type="text" label="{$xmlModel->xmlentities($this->__('Street Address'))}" required="true" value="{$street1}" /> <field name="street[]" type="text" label="{$xmlModel->xmlentities($this->__('Street Address 2'))}" value="{$street2}" /> <field name="city" type="text" label="{$xmlModel->xmlentities($this->__('City'))}" required="true" value="{$city}" /> <field name="country_id" type="select" label="{$xmlModel->xmlentities($this->__('Country'))}" required="true"> {$countryOptionsXml} </field> <field name="region" type="text" label="{$xmlModel->xmlentities($this->__('State/Province'))}" value="{$region}" /> <field name="region_id" type="select" label="{$xmlModel->xmlentities($this->__('State/Province'))}" required="true" /> <field name="postcode" type="text" label="{$xmlModel->xmlentities($this->__('Zip/Postal Code'))}" required="true" value="{$postcode}" /> <field name="default_billing" type="checkbox" {$billingChecked} label="{$xmlModel->xmlentities($this->__('Use as my default billing address'))}"/> <field name="default_shipping" type="checkbox" {$shippingChecked} label="{$xmlModel->xmlentities($this->__('Use as my default shipping address'))}"/> </fieldset> </form> EOT; return $xml; }
/** * Add weee tax product info to xml object * * @param Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj * @param bool $subtotalFlag use true to get subtotal product info * @return Mage_XmlConnect_Model_Simplexml_Element */ protected function _addWeeeToXmlObj(Mage_XmlConnect_Model_Simplexml_Element $priceXmlObj, $subtotalFlag = false) { $_item = $this->getItem(); $weeeXmlObj = $priceXmlObj->addCustomChild('weee'); if ($subtotalFlag) { $_incl = $this->helper('checkout')->getSubtotalInclTax($_item); } else { $_incl = $this->helper('checkout')->getPriceInclTax($_item); } $typeOfDisplay2 = Mage::helper('weee')->typeOfDisplay($_item, 2, 'sales'); if (Mage::helper('weee')->typeOfDisplay($_item, 1, 'sales') && $_item->getWeeeTaxAppliedAmount()) { foreach (Mage::helper('weee')->getApplied($_item) as $tax) { if ($subtotalFlag) { $amount = $tax['row_amount']; } else { $amount = $tax['amount']; } $weeeXmlObj->addCustomChild('item', null, array('name' => $tax['title'], 'amount' => $this->_formatPrice($amount))); } } elseif ($_item->getWeeeTaxAppliedAmount() && ($typeOfDisplay2 || Mage::helper('weee')->typeOfDisplay($_item, 4, 'sales'))) { foreach (Mage::helper('weee')->getApplied($_item) as $tax) { if ($subtotalFlag) { $amount = $tax['row_amount_incl_tax']; } else { $amount = $tax['amount_incl_tax']; } $weeeXmlObj->addCustomChild('item', null, array('name' => $tax['title'], 'amount' => $this->_formatPrice($amount))); } } if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) { if ($subtotalFlag) { $totalExcl = $_item->getRowTotal() + $_item->getWeeeTaxAppliedRowAmount() + $_item->getWeeeTaxRowDisposition(); } else { $totalExcl = $_item->getCalculationPrice() + $_item->getWeeeTaxAppliedAmount() + $_item->getWeeeTaxDisposition(); } $totalExcl = $this->_formatPrice($totalExcl); $priceXmlObj->addAttribute('total_excluding_tax', $priceXmlObj->xmlentities($totalExcl)); } if ($typeOfDisplay2 && $_item->getWeeeTaxAppliedAmount()) { if ($subtotalFlag) { $totalIncl = $_incl + $_item->getWeeeTaxAppliedRowAmount(); } else { $totalIncl = $_incl + $_item->getWeeeTaxAppliedAmount(); } $totalIncl = $this->_formatPrice($totalIncl); $priceXmlObj->addAttribute('total_including_tax', $priceXmlObj->xmlentities($totalIncl)); } return $priceXmlObj; }
/** * Render payment methods xml * * @return string * @throw Mage_Core_Exception */ protected function _toHtml() { $methodsXmlObj = new Mage_XmlConnect_Model_Simplexml_Element('<payment_methods></payment_methods>'); /** * Pre-defined array of methods that we are going to render */ $methodArray = array('payment_ccsave' => 'Mage_Payment_Model_Method_Cc', 'payment_checkmo' => 'Mage_Payment_Model_Method_Checkmo', 'payment_purchaseorder' => 'Mage_Payment_Model_Method_Purchaseorder'); /** * Check is available Payment Bridge and add methods for rendering */ if (is_object(Mage::getConfig()->getNode('modules/Enterprise_Pbridge'))) { $pbridgeMethodArray = array('pbridge_authorizenet' => 'Enterprise_Pbridge_Model_Payment_Method_Authorizenet', 'pbridge_paypal' => 'Enterprise_Pbridge_Model_Payment_Method_Paypal', 'pbridge_verisign' => 'Enterprise_Pbridge_Model_Payment_Method_Payflow_Pro', 'pbridge_paypaluk' => 'Enterprise_Pbridge_Model_Payment_Method_Paypaluk'); $pbBlockRenderer = 'xmlconnect/checkout_payment_method_'; $pbBlockName = 'xmlconnect.checkout.payment.method.'; foreach ($pbridgeMethodArray as $block => $class) { $currentBlockRenderer = $pbBlockRenderer . $block; $currentBlockName = $pbBlockName . $block; $this->getLayout()->addBlock($currentBlockRenderer, $currentBlockName); $this->setChild($block, $currentBlockName); } $methodArray = $methodArray + $pbridgeMethodArray; } $usedMethods = $sortedAvailableMethodCodes = $usedCodes = array(); /** * Receive available methods for checkout */ $allAvailableMethods = Mage::helper('payment')->getStoreMethods(Mage::app()->getStore(), $this->getQuote()); /** * Get sorted codes of available methods */ foreach ($allAvailableMethods as $method) { $sortedAvailableMethodCodes[] = $method->getCode(); } /** * Get blocks for layout to check available renderers */ $methodBlocks = $this->getChild(); /** * Collect directly supported by xmlconnect methods */ if (!empty($methodBlocks) && is_array($methodBlocks)) { foreach ($methodBlocks as $block) { if (!$block) { continue; } $method = $block->getMethod(); if (!$this->_canUseMethod($method) || in_array($method->getCode(), $usedCodes)) { continue; } $this->_assignMethod($method); $usedCodes[] = $method->getCode(); $usedMethods[$method->getCode()] = array('renderer' => $block, 'method' => $method); } } /** * Collect all "Credit Card" / "CheckMo" / "Purchaseorder" method compatible methods */ foreach ($methodArray as $methodName => $methodModelClassName) { $methodRenderer = $this->getChild($methodName); if (!empty($methodRenderer)) { foreach ($sortedAvailableMethodCodes as $methodCode) { /** * Skip used methods */ if (in_array($methodCode, $usedCodes)) { continue; } try { $method = Mage::helper('payment')->getMethodInstance($methodCode); if (!is_subclass_of($method, $methodModelClassName)) { continue; } if (!$this->_canUseMethod($method)) { continue; } $this->_assignMethod($method); $usedCodes[] = $method->getCode(); $usedMethods[$method->getCode()] = array('renderer' => $methodRenderer, 'method' => $method); } catch (Exception $e) { Mage::logException($e); } } } } /** * Generate methods XML according to sort order */ foreach ($sortedAvailableMethodCodes as $code) { if (!in_array($code, $usedCodes)) { continue; } $method = $usedMethods[$code]['method']; $renderer = $usedMethods[$code]['renderer']; /** * Render all Credit Card method compatible methods */ if ($renderer instanceof Mage_XmlConnect_Block_Checkout_Payment_Method_Ccsave) { $renderer->setData('method', $method); } $methodItemXmlObj = $methodsXmlObj->addChild('method'); $methodItemXmlObj->addAttribute('post_name', 'payment[method]'); $methodItemXmlObj->addAttribute('code', $method->getCode()); $methodItemXmlObj->addAttribute('label', $methodsXmlObj->xmlentities(strip_tags($method->getTitle()))); if ($this->getQuote()->getPayment()->getMethod() == $method->getCode()) { $methodItemXmlObj->addAttribute('selected', 1); } $renderer->addPaymentFormToXmlObj($methodItemXmlObj); } if (!count($usedMethods)) { Mage::throwException($this->__('Sorry, no payment options are available for this order at this time.')); } return $methodsXmlObj->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(); }