/** * Update stock data of multiple products at once * * @param array $itemData * @return array */ public function inventoryPush($itemData) { if (isset($itemData['records'])) { $itemData = $itemData['records']; } $response = array(); $response['records'] = array(); $orderItemsCollection = Mage::getResourceModel('retailops_api/api')->getRetailopsReadyOrderItems(); $orderItems = $this->filterOrderItems($orderItemsCollection); $productIds = $this->getProductIds($itemData); foreach ($itemData as $item) { try { $itemObj = new Varien_Object($item); Mage::dispatchEvent('retailops_inventory_push_record', array('record' => $itemObj)); $result = array(); $result['sku'] = $itemObj->getSku(); $itemObj->setQty($itemObj->getQuantity()); // api update accepts qty not quantity parameter $qty = $itemObj->getQty(); if (isset($orderItems[$itemObj->getSku()])) { $qty = $itemObj->getQty() - $orderItems[$itemObj->getSku()]; } $itemObj->setQty($qty); Mage::dispatchEvent('retailops_inventory_push_record_qty_processed', array('record' => $itemObj)); $this->update($productIds[$itemObj->getSku()], $itemObj->getData()); $result['status'] = RetailOps_Api_Helper_Data::API_STATUS_SUCCESS; } catch (Mage_Core_Exception $e) { $result['status'] = RetailOps_Api_Helper_Data::API_STATUS_FAIL; $result['error'] = array('code' => $e->getCode(), 'message' => $e->getMessage()); } $response['records'][] = $result; } return $response; }
public function _getValue(Varien_Object $row) { if ($row->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) { $value = '<span id="qty_label_' . $row->getId() . '" data-id="' . $row->getId() . '">' . (int) $row->getQty() . '</span>'; $value .= '<input type="text" id="qty_value_' . $row->getId() . '" name="qty_value[' . $row->getId() . ']" data-id="' . $row->getId() . '" value="' . (int) $row->getQty() . '" style="width: 100px;margin-right: 2px;display:none">'; $value .= '<button id="qty_button_' . $row->getId() . '" data-id="' . $row->getId() . '" onclick="vcUpdateInfor(' . $row->getId() . ',\'qty\')" style="display:none"><span><span>Update</span></span></button>'; $value .= '<img id="qty_waiting_' . $row->getId() . '" src="' . $this->getSkinUrl('vc_easyupdateproductinfor/images/ajax-loader.gif') . '" class="v-middle" style="display:none" />'; } else { $value = number_format($row->getQty(), 0); } return $value; }
/** * Added for Magento <= 1.4 compatibility * @return Varien_Object */ public function getBuyRequest() { $option = $this->getOptionByCode('info_buyRequest'); $buyRequest = new Varien_Object($option ? unserialize($option->getValue()) : null); // Overwrite standard buy request qty, because item qty could have changed since adding to quote $buyRequest->setOriginalQty($buyRequest->getQty())->setQty($this->getQty() * 1); return $buyRequest; }
public function prepareForCartAdvanced(Varien_Object $buyRequest, $product = null, $processMode = null) { if ($product) { $qty = $buyRequest->getQty(); $product->getFinalPrice($qty, $product); } return parent::prepareForCartAdvanced($buyRequest, $product, $processMode); }
public function render(Varien_Object $row) { $manage_stock = Mage::getStoreConfig("cataloginventory/item_options/manage_stock"); if (!in_array($row->getTypeId(), array('simple', 'virtual', 'downloadable'))) { return Mage::helper('advancedinventory')->__("-"); } if ($row->getManageStock() || $row->getUse_config_manage_stock() && $manage_stock) { if ($row->getMultistock_enabled()) { $html = (int) $row->getQty(); } else { $html = "<input class = 'keydown inventory_input' type = 'text' value = '" . (int) $row->getQty() . "' />"; } $enabled = $row->getMultistock_enabled() ? 'enabled' : 'disabled'; return "<span class = 'GlobalQty' id = 'GlobalQty_" . $row->getId() . "' multistock = '" . $enabled . "'>" . $html . "</span>"; } else { return Mage::helper('advancedinventory')->__("X"); } }
/** * Renders grid column * * @param Varien_Object $row * @return string */ public function render(Varien_Object $_row) { if (ITwebexperts_Payperrentals_Helper_Data::isReservationType($_row->getId())) { $data = intval(ITwebexperts_Payperrentals_Helper_Data::getAttributeCodeForId($_row->getId(), 'payperrentals_quantity')); } else { $data = intval($_row->getQty()); } return $data; }
/** * Validate Product Rule Condition * * @param Varien_Object $object * * @return bool */ public function validate(Varien_Object $object) { /** @var Mage_Catalog_Model_Product $product */ $product = $object->getProduct(); if (!$product instanceof Mage_Catalog_Model_Product) { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); return parent::validate($product); }
/** * Validate Product Rule Condition * * @param Varien_Object $object * * @return bool */ public function validate(Varien_Object $object) { $product = false; if ($object->getProduct() instanceof Mage_Catalog_Model_Product && $object->getData($this->getAttribute()) !== null) { $product = $object->getProduct(); } else { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); return parent::validate($product); }
public function render(Varien_Object $row) { $productId = intval($row->getEntityId()); $product = Mage::getModel('catalog/product')->load($productId); $printArr = Mage::getSingleton('core/session')->getPrintArr(); if (is_array($printArr) && count($printArr) > 0) { $qty = intval($printArr[$product->getId()]); } else { $qty = intval($row->getQty()); } return '<input type="text" name="product_' . $row->getEntityId() . '" value="' . $qty . '" class="input-text" style="text-align:center;" />'; }
/** * Validate Product Rule Condition * * @param Varien_Object $object * * @return bool */ public function validate(Varien_Object $object) { /** @var Mage_Catalog_Model_Product $product */ $product = $object->getProduct(); if (!$product instanceof Mage_Catalog_Model_Product) { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); $valid = parent::validate($product); if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) { $children = $object->getChildren(); $valid = $children && $this->validate($children[0]); } return $valid; }
/** * Validate Product Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $op = $this->getOperator(); $product = false; if ($object->getProduct() instanceof Mage_Catalog_Model_Product) { $product = $object->getProduct(); } else { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); if (!$product->getData($this->getAttribute()) && ($op != '==' || $op != '!=') && $this->getAttribute() != 'category_ids') { return false; } return parent::validate($product); }
public function estimate() { $product = $this->getProduct(); $addToCartInfo = (array) $product->getAddToCartInfo(); $addressInfo = (array) $this->getAddressInfo(); if (!$product instanceof Mage_Catalog_Model_Product || !$product->getId()) { Mage::throwException(Mage::helper('webdevlopers_productpageshipping')->__('Please specify a valid product')); } if (!isset($addressInfo['country_id'])) { Mage::throwException(Mage::helper('webdevlopers_productpageshipping')->__('Please specify a country')); } if (empty($addressInfo['cart'])) { $this->resetQuote(); } $shippingAddress = $this->getQuote()->getShippingAddress(); $shippingAddress->setCountryId($addressInfo['country_id']); if (isset($addressInfo['region_id'])) { $shippingAddress->setRegionId($addressInfo['region_id']); } if (isset($addressInfo['postcode'])) { $shippingAddress->setPostcode($addressInfo['postcode']); } if (isset($addressInfo['region'])) { $shippingAddress->setRegion($addressInfo['region']); } if (isset($addressInfo['city'])) { $shippingAddress->setCity($addressInfo['city']); } $shippingAddress->setCollectShippingRates(true); if (isset($addressInfo['coupon_code'])) { $this->getQuote()->setCouponCode($addressInfo['coupon_code']); } $request = new Varien_Object($addToCartInfo); if ($product->getStockItem()) { $minimumQty = $product->getStockItem()->getMinSaleQty(); if ($minimumQty > 0 && $request->getQty() < $minimumQty) { $request->setQty($minimumQty); } } $result = $this->getQuote()->addProduct($product, $request); if (is_string($result)) { Mage::throwException($result); } Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product)); $this->getQuote()->collectTotals(); $this->_result = $shippingAddress->getGroupedAllShippingRates(); return $this; }
/** * Use our own method to get buyRequest * @param Mage_Sales_Model_Quote_Item $salesItem * @return Varien_Object * */ public function getBuyRequest($salesItem, $option = false) { if ($option) { $option = $salesItem->getOptionByCode('info_buyRequest'); $buyRequest = new Varien_Object($option && $option->getValue() ? unserialize($option->getValue()) : null); $buyRequest->setOriginalQty($buyRequest->getQty())->setQty($salesItem->getQty() * 1); return $buyRequest; } $option = $salesItem->getProductOptionByCode('info_buyRequest'); if (!$option) { $option = array(); } $buyRequest = new Varien_Object($option); $buyRequest->setQty($salesItem->getQtyOrdered() * 1); return $buyRequest; }
/** * Trasfer data from an "item" with gifting options to a Gifting payload. * The "item" may be a quote item or quote address, as either may have * gift options data, retrievable in the same way. * * @param Varien_Object * @param IGfiting * @return IGifting */ public function giftingItemToGiftingPayload(Varien_Object $giftItem, IGifting $giftingPayload) { $giftPricing = $giftingPayload->getEmptyGiftPriceGroup(); $giftWrap = Mage::getModel('enterprise_giftwrapping/wrapping')->load($giftItem->getGwId()); if ($giftWrap->getId()) { // For quote items (which will have a quantity), gift wrapping price // on the item will be the price for a single item to be wrapped, // total will be for cost for all items to be wrapped (qty * amount). // For addresses (which will have no quantity), gift wrapping price // on the address will be the price for wrapping all items for that // address, so total is just amount (1 * amount). $giftQty = $giftItem->getQty() ?: 1; // Add pricing data for gift wrapping - does not include discounts // as Magento does not support applying discounts to gift wrapping // out-of-the-box. $giftPricing->setUnitPrice($giftWrap->getBasePrice())->setAmount($giftItem->getGwPrice() * $giftQty)->setTaxClass($giftWrap->getEb2cTaxClass()); $giftingPayload->setGiftItemId($giftWrap->getEb2cSku())->setGiftDescription($giftWrap->getDesign())->setGiftPricing($giftPricing); } return $giftingPayload; }
/** * Validate Product Rule Condition * * @param Varien_Object $object * * @return bool */ public function validate(Varien_Object $object) { /** @var Mage_Catalog_Model_Product $product */ $product = $object->getProduct(); if (!$product instanceof Mage_Catalog_Model_Product) { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); // Allows attributes to take custom option SKU into consideration if ($this->getAttribute() === self::QUOTE_ITEM_SKU) { $product->setData($this->getAttribute(), $object->getSku()); $valid = Mage_Rule_Model_Condition_Product_Abstract::validate($product); } else { $valid = parent::validate($object); } if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) { $children = $object->getChildren(); $valid = $children && $this->validate($children[0]); } return $valid; }
public function render(Varien_Object $row) { if (in_array($row->getTypeId(), array('simple', 'virtual', 'downloadable'))) { $localQty = Mage::getModel('advancedinventory/advancedinventory')->getLocalGlobalStockByProductId($row->getId()); $diff = $row->getQty() - $localQty->getTotalQuantityInStock(); if (!$localQty->getManageLocalStock()) { $html = "<span id='stock_difference_" . $row->getId() . "' style=''>-</span>"; } else { if ($diff == 0) { $html = "<span style='color:green'> == </span>"; } elseif ($diff > 0) { $html = "<span style='color:red'><b style='font-size:16px;'>> </b> (+ " . $diff . ")</span>"; } else { $html = "<span style='color:orange; '><b style='font-size:16px;'>< </b> (" . $diff . ")</span>"; } } return $html; } else { return "-"; } }
protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode) { $product = $this->getProduct($product); $servicePrice = (double) $buyRequest->getServicePrice(); $isStrictProcessMode = $this->_isStrictProcessMode($processMode); if ($buyRequest->getQty() > 1) { return Mage::helper('catalog')->__('The maximum qty of service product allowed in cart is 1.'); } if (!$isStrictProcessMode || $servicePrice > 0) { $maxPrice = Mage::helper('service_product')->getMaxPrice(); if ($maxPrice && $servicePrice > $maxPrice) { return Mage::helper('catalog')->__('Service price must not be greater than %d.', $maxPrice); } $products = parent::_prepareProduct($buyRequest, $product, $processMode); if (!isset($products[0])) { return Mage::helper('checkout')->__('Cannot process the item.'); } return $products; } return Mage::helper('catalog')->__('Please specify the product price.'); }
/** * Add product to current order quote * $product can be either product id or product model * $config can be either buyRequest config, or just qty * * @param int|Mage_Catalog_Model_Product $product * @param float|array|Varien_Object $config * @return Mage_Adminhtml_Model_Sales_Order_Create */ public function addProduct($product, $config = 1) { if (!is_array($config) && !$config instanceof Varien_Object) { $config = array('qty' => $config); } $config = new Varien_Object($config); /* $aChildQuoteItems = Mage::getModel("sales/quote_item") ->getCollection() ->addFieldToFilter("quote_id", 42); Mage::log("qry = ".$aChildQuoteItems->getSelect()); Mage::log("all items = ".serialize($aChildQuoteItems)); */ if (!$product instanceof Mage_Catalog_Model_Product) { $productId = $product; $product = Mage::getModel('catalog/product')->setStore($this->getSession()->getStore())->setStoreId($this->getSession()->getStoreId())->load($product); if (!$product->getId()) { Mage::throwException(Mage::helper('adminhtml')->__('Failed to add a product to cart by id "%s".', $productId)); } } $stockItem = $product->getStockItem(); if ($stockItem && $stockItem->getIsQtyDecimal()) { $product->setIsQtyDecimal(1); } else { $config->setQty((int) $config->getQty()); } $product->setCartQty($config->getQty()); $item = $this->getQuote()->addProductAdvanced($product, $config, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL); if (is_string($item)) { if ($product->getTypeId() != Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) { $item = $this->getQuote()->addProductAdvanced($product, $config, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_LITE); } if (is_string($item)) { Mage::throwException($item); } } if (isset($config['pck_option']) && $config['pck_option'] != '') { $pck_sku = Mage::getModel('catalog/product')->load($config['pck_id'])->getSku(); $item->setPckOption($config['pck_option']); $item->setPckSku($pck_sku); $item->setPckQty((int) $config->getQty()); } $item->checkData(); $this->setRecollect(true); return $this; }
/** * Returns formatted buy request - object, holding request received from * product view page with keys and options for configured product * * @return Varien_Object */ public function getBuyRequest() { $option = $this->getOptionByCode('info_buyRequest'); $initialData = $option ? unserialize($option->getValue()) : null; // There can be wrong data due to bug in Grouped products - it formed 'info_buyRequest' as Varien_Object if ($initialData instanceof Varien_Object) { $initialData = $initialData->getData(); } $buyRequest = new Varien_Object($initialData); $buyRequest->setOriginalQty($buyRequest->getQty())->setQty($this->getQty() * 1); return $buyRequest; }
public function changeattributecartAction() { $result = array(); $result['error'] = false; $id = (int) $this->getRequest()->getParam('id'); $result['item_id'] = $id; $params = $this->getRequest()->getParams(); if (!isset($params['options'])) { $params['options'] = array(); } $params['super_attribute'] = Zend_Json::decode($params['super_attribute']); try { $cart = Mage::getSingleton('checkout/cart'); $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { Mage::throwException($this->__('Quote item is not found.')); } $params['qty'] = $quoteItem->getQty(); if (method_exists($cart, 'updateItem')) { $item = $cart->updateItem($id, new Varien_Object($params)); } else { $request = new Varien_Object($params); $productId = $quoteItem->getProduct()->getId(); $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId); if ($product->getStockItem()) { $minimumQty = $product->getStockItem()->getMinSaleQty(); if ($minimumQty && $minimumQty > 0 && $request->getQty() < $minimumQty && !$cart->getQuote()->hasProductId($productId)) { $request->setQty($minimumQty); } } $item = $cart->getQuote()->addProduct($product, $request); if ($item->getParentItem()) { $item = $item->getParentItem(); } if ($item->getId() != $id) { $cart->getQuote()->removeItem($id); $items = $cart->getQuote()->getAllItems(); foreach ($items as $_item) { if ($_item->getProductId() == $productId && $_item->getId() != $item->getId()) { if ($item->compare($_item)) { $item->setQty($item->getQty() + $_item->getQty()); $this->removeItem($_item->getId()); break; } } } } else { $item->setQty($request->getQty()); } } if (is_string($item)) { Mage::throwException($item); } $cart->save(); Mage::getSingleton('checkout/session')->setCartWasUpdated(true); Mage::dispatchEvent('checkout_cart_update_item_complete', array('item' => $item, 'request' => $this->getRequest(), 'response' => $this->getResponse())); } catch (Mage_Core_Exception $e) { $result['error'] = true; $result['message'] = $e->getMessage(); } catch (Exception $e) { $result['error'] = true; $result['message'] = $e->getMessage(); Mage::logException($e); } if (!$result['error']) { if ($item_html = $this->getCartItem($item->getId())) { $result['item_html'] = $item_html; $result['new_item_id'] = $item->getId(); } if ($total = $this->getCartTolal()) { $result['total'] = $total; } } else { if ($item_html = $this->getCartItem($result['item_id'])) { $result['item_html'] = $item_html; } } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); }
/** * Get sales item (quote item, order item etc) price including tax based on row total and tax amount * * @param Varien_Object $item * @return float */ public function getPriceInclTax($item) { if ($item->getPriceInclTax()) { return $item->getPriceInclTax(); } $qty = $item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1); $taxAmount = $item->getTaxAmount() + $item->getDiscountTaxCompensation(); $price = floatval($qty) ? ($item->getRowTotal() + $taxAmount) / $qty : 0; return Mage::app()->getStore()->roundPrice($price); }
/** * Initialize product(s) for add to cart process * * @param Varien_Object $buyRequest * @return array|string */ public function prepareForCart(Varien_Object $buyRequest) { $product = $this->getProduct(); /* @var Mage_Catalog_Model_Product $product */ // try to add custom options $options = $this->_prepareOptionsForCart($buyRequest->getOptions()); if (is_string($options)) { return $options; } // try to found super product configuration // (if product was buying within grouped product) $superProductConfig = $buyRequest->getSuperProductConfig(); if (!empty($superProductConfig['product_id']) && !empty($superProductConfig['product_type'])) { $superProductId = (int) $superProductConfig['product_id']; if ($superProductId) { if (!($superProduct = Mage::registry('used_super_product_' . $superProductId))) { $superProduct = Mage::getModel('catalog/product')->load($superProductId); Mage::register('used_super_product_' . $superProductId, $superProduct); } if ($superProduct->getId()) { $assocProductIds = $superProduct->getTypeInstance()->getAssociatedProductIds(); if (in_array($product->getId(), $assocProductIds)) { $productType = $superProductConfig['product_type']; $product->addCustomOption('product_type', $productType, $superProduct); $buyRequest->setData('super_product_config', array('product_type' => $productType, 'product_id' => $superProduct->getId())); } } } } $product->addCustomOption('info_buyRequest', serialize($buyRequest->getData())); if ($options) { $optionIds = array_keys($options); $product->addCustomOption('option_ids', implode(',', $optionIds)); foreach ($options as $optionId => $optionValue) { $product->addCustomOption('option_' . $optionId, $optionValue); } } // set quantity in cart $product->setCartQty($buyRequest->getQty()); return array($product); }
/** * Validate Product Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $op = $this->getOperator(); $product = false; if ($object->getProduct() instanceof Mage_Catalog_Model_Product) { $product = $object->getProduct(); } else { $product = Mage::getModel('catalog/product')->load($object->getProductId()); } $product->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getBaseRowTotal()); //Validate with attribute is is_new if ($this->getAttribute() == 'is_new') { $result = true; if (!$product->getNewsFromDate() && !$product->getNewsToDate()) { $result = false; } else { $today = new DateTime(date('Y-m-d 00:00:00')); if ($from = $product->getNewsFromDate()) { $fromNewDate = new DateTime($from); if ($today < $fromNewDate) { $result = false; } } if ($to = $product->getNewsToDate()) { $toNewDate = new DateTime($to); if ($today > $toNewDate) { $result = false; } } } $value = $this->getValueParsed(); if ($value == 0) { $result = !$result; } return $result; } //validate with attribute is is_special if ($this->getAttribute() == 'is_special') { $result = true; if (!$product->getSpecialPrice()) { $result = false; } else { $today = new DateTime(date('Y-m-d 00:00:00')); if (!($from = $product->getSpecialFromDate())) { $fromNewDate = $today; } else { $fromNewDate = new DateTime($from); } if (!($to = $product->getSpecialToDate())) { $toNewDate = $today; } else { $toNewDate = new DateTime($to); } if ($today < $fromNewDate || $toNewDate < $today) { $result = false; } $value = $this->getValueParsed(); if ($value == 0) { $result = !$result; } return $result; } } //validate with attribute is qty if ($this->getAttribute() == 'qty') { $result = true; $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty(); $value = $this->getValueParsed(); switch ($op) { case '==': case '!=': $result = $qty == $value; break; case '>=': case '<': $result = $qty >= $value; break; case '<=': case '>': $result = $qty <= $value; break; } if ($op == '!=' || $op == '<' || $op == '>') { $result = !$result; } return $result; } //validate with attribute is qty if ($this->getAttribute() == 'out_of_stock') { $result = true; if ($product->isSaleable()) { $result = false; } if ($this->getValueParsed() == 0) { $result = !$result; } return $result; } //validate best seller if ($this->getAttribute() == 'best_seller') { $result = true; $value = $this->getValueParsed(); // Get Best Seller product $storeId = Mage::app()->getStore()->getId(); if (Mage::registry('bestSelletListId')) { $bestSellerId = Mage::registry('bestSelletListId'); } else { $products = Mage::getResourceModel('reports/product_collection')->addOrderedQty()->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('ordered_qty', 'desc')->setPageSize($value); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products); //Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products); $bestSellerId = array(); foreach ($products as $p) { $bestSellerId[] = $p->getId(); } if (!empty($bestSellerId)) { Mage::register('bestSelletListId', $bestSellerId); } } if (!count($bestSellerId)) { $result = false; } else { $childProducts = null; if ($product->getTypeId() == 'configurable') { $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null, $product); } elseif ($product->getTypeId() == 'grouped') { $childProducts = Mage::getModel('catalog/product_type_grouped')->getAssociatedProducts($product); } elseif ($product->getTypeId() == 'bundle') { $childProducts = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product); } else { if (!in_array($product->getId(), $bestSellerId)) { return false; } } $flag = 0; if (isset($childProducts)) { foreach ($childProducts as $c) { if (in_array($c->getId(), $bestSellerId)) { $flag = 1; break; } } } if ($flag == 0) { $result = false; } } return $result; } if (!$product->getData($this->getAttribute()) && ('!=' == $op || '>' == $op || '<' == $op || '!{}' == $op || '!()' == $op)) { return false; } return parent::validate($product); }
/** * Validate Product Rule Condition * * @param Varien_Object $object * @return bool */ public function validate(Varien_Object $object) { $product = Mage::getModel('catalog/product')->load($object->getProductId())->setQuoteItemQty($object->getQty())->setQuoteItemPrice($object->getPrice())->setQuoteItemRowTotal($object->getRowTotal()); return parent::validate($product); }
/** * Add product to current order quote * $product can be either product id or product model * $config can be either buyRequest config, or just qty * * @param int|Mage_Catalog_Model_Product $product * @param float|array|Varien_Object $config * @return Mage_Adminhtml_Model_Sales_Order_Create */ public function addProduct($product, $config = 1) { if (!is_array($config) && !$config instanceof Varien_Object) { $config = array('qty' => $config); } $config = new Varien_Object($config); if (!$product instanceof Mage_Catalog_Model_Product) { $productId = $product; $product = Mage::getModel('catalog/product')->setStore($this->getSession()->getStore())->setStoreId($this->getSession()->getStoreId())->load($product); if (!$product->getId()) { Mage::throwException(Mage::helper('adminhtml')->__('Failed to add a product to cart by id "%s".', $productId)); } } $stockItem = $product->getStockItem(); if ($stockItem && $stockItem->getIsQtyDecimal()) { $product->setIsQtyDecimal(1); } else { $config->setQty((int) $config->getQty()); } $product->setCartQty($config->getQty()); $item = $this->getQuote()->addProductAdvanced($product, $config, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL); if (is_string($item)) { if ($product->getTypeId() != Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE) { $item = $this->getQuote()->addProductAdvanced($product, $config, Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_LITE); } if (is_string($item)) { Mage::throwException($item); } } $item->checkData(); $this->setRecollect(true); return $this; }
/** * Retrieve include tax html formated content * * @param Varien_Object $item * @return string */ public function displayPriceInclTax(Varien_Object $item) { $qty = $item->getQtyOrdered() ? $item->getQtyOrdered() : ($item->getQty() ? $item->getQty() : 1); $baseTax = $item->getTaxBeforeDiscount() ? $item->getTaxBeforeDiscount() : ($item->getTaxAmount() ? $item->getTaxAmount() : 0); $tax = $item->getBaseTaxBeforeDiscount() ? $item->getBaseTaxBeforeDiscount() : ($item->getBaseTaxAmount() ? $item->getBaseTaxAmount() : 0); $basePriceTax = 0; $priceTax = 0; if (floatval($qty)) { $basePriceTax = $item->getBasePrice() + $baseTax / $qty; $priceTax = $item->getPrice() + $tax / $qty; } return $this->displayPrices($this->getOrder()->getStore()->roundPrice($basePriceTax), $this->getOrder()->getStore()->roundPrice($priceTax)); }
/** * Form XML for international shipment request * As integration guide it is important to follow appropriate sequence for tags e.g.: <FromLastName /> must be * after <FromFirstName /> * * @param Varien_Object $request * @return string */ protected function _formIntlShipmentRequest(Varien_Object $request) { $packageParams = $request->getPackageParams(); $height = $packageParams->getHeight(); $width = $packageParams->getWidth(); $length = $packageParams->getLength(); $girth = $packageParams->getGirth(); $packageWeight = $request->getPackageWeight(); if ($packageParams->getWeightUnits() != Zend_Measure_Weight::POUND) { $packageWeight = Mage::helper('usa')->convertMeasureWeight($request->getPackageWeight(), $packageParams->getWeightUnits(), Zend_Measure_Weight::POUND); } if ($packageParams->getDimensionUnits() != Zend_Measure_Length::INCH) { $length = round(Mage::helper('usa')->convertMeasureDimension($packageParams->getLength(), $packageParams->getDimensionUnits(), Zend_Measure_Length::INCH)); $width = round(Mage::helper('usa')->convertMeasureDimension($packageParams->getWidth(), $packageParams->getDimensionUnits(), Zend_Measure_Length::INCH)); $height = round(Mage::helper('usa')->convertMeasureDimension($packageParams->getHeight(), $packageParams->getDimensionUnits(), Zend_Measure_Length::INCH)); } if ($packageParams->getGirthDimensionUnits() != Zend_Measure_Length::INCH) { $girth = round(Mage::helper('usa')->convertMeasureDimension($packageParams->getGirth(), $packageParams->getGirthDimensionUnits(), Zend_Measure_Length::INCH)); } $container = $request->getPackagingType(); switch ($container) { case 'VARIABLE': $container = 'VARIABLE'; break; case 'FLAT RATE ENVELOPE': $container = 'FLATRATEENV'; break; case 'FLAT RATE BOX': $container = 'FLATRATEBOX'; break; case 'RECTANGULAR': $container = 'RECTANGULAR'; break; case 'NONRECTANGULAR': $container = 'NONRECTANGULAR'; break; default: $container = 'VARIABLE'; } $shippingMethod = $request->getShippingMethod(); list($fromZip5, $fromZip4) = $this->_parseZip($request->getShipperAddressPostalCode()); // the wrap node needs for remove xml declaration above $xmlWrap = new SimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><wrap/>'); $method = ''; $service = $this->getCode('service_to_code', $shippingMethod); if ($service == 'Priority') { $method = 'Priority'; $rootNode = 'PriorityMailIntlRequest'; $xml = $xmlWrap->addChild($rootNode); } else { if ($service == 'First Class') { $method = 'FirstClass'; $rootNode = 'FirstClassMailIntlRequest'; $xml = $xmlWrap->addChild($rootNode); } else { $method = 'Express'; $rootNode = 'ExpressMailIntlRequest'; $xml = $xmlWrap->addChild($rootNode); } } $xml->addAttribute('USERID', $this->getConfigData('userid')); $xml->addAttribute('PASSWORD', $this->getConfigData('password')); $xml->addChild('Option'); $xml->addChild('Revision', self::DEFAULT_REVISION); $xml->addChild('ImageParameters'); $xml->addChild('FromFirstName', $request->getShipperContactPersonFirstName()); $xml->addChild('FromLastName', $request->getShipperContactPersonLastName()); $xml->addChild('FromFirm', $request->getShipperContactCompanyName()); $xml->addChild('FromAddress1', $request->getShipperAddressStreet2()); $xml->addChild('FromAddress2', $request->getShipperAddressStreet1()); $xml->addChild('FromCity', $request->getShipperAddressCity()); $xml->addChild('FromState', $request->getShipperAddressStateOrProvinceCode()); $xml->addChild('FromZip5', $fromZip5); $xml->addChild('FromZip4', $fromZip4); $xml->addChild('FromPhone', $request->getShipperContactPhoneNumber()); if ($method != 'FirstClass') { if ($request->getReferenceData()) { $referenceData = $request->getReferenceData() . ' P' . $request->getPackageId(); } else { $referenceData = $request->getOrderShipment()->getOrder()->getIncrementId() . ' P' . $request->getPackageId(); } $xml->addChild('FromCustomsReference', 'Order #' . $referenceData); } $xml->addChild('ToFirstName', $request->getRecipientContactPersonFirstName()); $xml->addChild('ToLastName', $request->getRecipientContactPersonLastName()); $xml->addChild('ToFirm', $request->getRecipientContactCompanyName()); $xml->addChild('ToAddress1', $request->getRecipientAddressStreet1()); $xml->addChild('ToAddress2', $request->getRecipientAddressStreet2()); $xml->addChild('ToCity', $request->getRecipientAddressCity()); $xml->addChild('ToProvince', $request->getRecipientAddressStateOrProvinceCode()); $xml->addChild('ToCountry', $this->_getCountryName($request->getRecipientAddressCountryCode())); $xml->addChild('ToPostalCode', $request->getRecipientAddressPostalCode()); $xml->addChild('ToPOBoxFlag', 'N'); $xml->addChild('ToPhone', $request->getRecipientContactPhoneNumber()); $xml->addChild('ToFax'); $xml->addChild('ToEmail'); if ($method != 'FirstClass') { $xml->addChild('NonDeliveryOption', 'Return'); } if ($method == 'FirstClass') { if (stripos($shippingMethod, 'Letter') !== false) { $xml->addChild('FirstClassMailType', 'LETTER'); } else { if (stripos($shippingMethod, 'Flat') !== false) { $xml->addChild('FirstClassMailType', 'FLAT'); } else { $xml->addChild('FirstClassMailType', 'PARCEL'); } } } if ($method != 'FirstClass') { $xml->addChild('Container', $container); } $shippingContents = $xml->addChild('ShippingContents'); $packageItems = $request->getPackageItems(); // get countries of manufacture $countriesOfManufacture = array(); $productIds = array(); foreach ($packageItems as $itemShipment) { $item = new Varien_Object(); $item->setData($itemShipment); $productIds[] = $item->getProductId(); } $productCollection = Mage::getResourceModel('catalog/product_collection')->addStoreFilter($request->getStoreId())->addFieldToFilter('entity_id', array('in' => $productIds))->addAttributeToSelect('country_of_manufacture'); foreach ($productCollection as $product) { $countriesOfManufacture[$product->getId()] = $product->getCountryOfManufacture(); } $packagePoundsWeight = $packageOuncesWeight = 0; // for ItemDetail foreach ($packageItems as $itemShipment) { $item = new Varien_Object(); $item->setData($itemShipment); $itemWeight = $item->getWeight() * $item->getQty(); if ($packageParams->getWeightUnits() != Zend_Measure_Weight::POUND) { $itemWeight = Mage::helper('usa')->convertMeasureWeight($itemWeight, $packageParams->getWeightUnits(), Zend_Measure_Weight::POUND); } if (!empty($countriesOfManufacture[$item->getProductId()])) { $countryOfManufacture = $this->_getCountryName($countriesOfManufacture[$item->getProductId()]); } else { $countryOfManufacture = ''; } $itemDetail = $shippingContents->addChild('ItemDetail'); $itemDetail->addChild('Description', $item->getName()); $ceiledQty = ceil($item->getQty()); if ($ceiledQty < 1) { $ceiledQty = 1; } $individualItemWeight = $itemWeight / $ceiledQty; $itemDetail->addChild('Quantity', $ceiledQty); $itemDetail->addChild('Value', $item->getCustomsValue() * $item->getQty()); list($individualPoundsWeight, $individualOuncesWeight) = $this->_convertPoundOunces($individualItemWeight); $itemDetail->addChild('NetPounds', $individualPoundsWeight); $itemDetail->addChild('NetOunces', $individualOuncesWeight); $itemDetail->addChild('HSTariffNumber', 0); $itemDetail->addChild('CountryOfOrigin', $countryOfManufacture); list($itemPoundsWeight, $itemOuncesWeight) = $this->_convertPoundOunces($itemWeight); $packagePoundsWeight += $itemPoundsWeight; $packageOuncesWeight += $itemOuncesWeight; } $additionalPackagePoundsWeight = floor($packageOuncesWeight / self::OUNCES_POUND); $packagePoundsWeight += $additionalPackagePoundsWeight; $packageOuncesWeight -= $additionalPackagePoundsWeight * self::OUNCES_POUND; if ($packagePoundsWeight + $packageOuncesWeight / self::OUNCES_POUND < $packageWeight) { list($packagePoundsWeight, $packageOuncesWeight) = $this->_convertPoundOunces($packageWeight); } $xml->addChild('GrossPounds', $packagePoundsWeight); $xml->addChild('GrossOunces', $packageOuncesWeight); if ($packageParams->getContentType() == 'OTHER' && $packageParams->getContentTypeOther() != null) { $xml->addChild('ContentType', $packageParams->getContentType()); $xml->addChild('ContentTypeOther ', $packageParams->getContentTypeOther()); } else { $xml->addChild('ContentType', $packageParams->getContentType()); } $xml->addChild('Agreement', 'y'); $xml->addChild('ImageType', 'PDF'); $xml->addChild('ImageLayout', 'ALLINONEFILE'); if ($method == 'FirstClass') { $xml->addChild('Container', $container); } // set size if ($packageParams->getSize()) { $xml->addChild('Size', $packageParams->getSize()); } // set dimensions $xml->addChild('Length', $length); $xml->addChild('Width', $width); $xml->addChild('Height', $height); if ($girth) { $xml->addChild('Girth', $girth); } $xml = $xmlWrap->{$rootNode}->asXML(); return $xml; }
/** * Get the base price of the item including tax , excluding weee * * @param Varien_Object $item * @return float */ public function getBasePriceInclTax($item) { $qty = $item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1); return $qty > 0 ? $this->getBaseSubtotalInclTax($item) / $qty : 0; }
/** * Form array with appropriate structure for shipment request * * @param Varien_Object $request * @return array */ protected function _formShipmentRequest(Varien_Object $request) { if ($request->getReferenceData()) { $referenceData = $request->getReferenceData() . $request->getPackageId(); } else { $referenceData = 'Order #' . $request->getOrderShipment()->getOrder()->getIncrementId() . ' P' . $request->getPackageId(); } $packageParams = $request->getPackageParams(); $customsValue = $packageParams->getCustomsValue(); $height = $packageParams->getHeight(); $width = $packageParams->getWidth(); $length = $packageParams->getLength(); $weightUnits = $packageParams->getWeightUnits() == Zend_Measure_Weight::POUND ? 'LB' : 'KG'; $dimensionsUnits = $packageParams->getDimensionUnits() == Zend_Measure_Length::INCH ? 'IN' : 'CM'; $unitPrice = 0; $itemsQty = 0; $itemsDesc = array(); $countriesOfManufacture = array(); $productIds = array(); $packageItems = $request->getPackageItems(); foreach ($packageItems as $itemShipment) { $item = new Varien_Object(); $item->setData($itemShipment); $unitPrice += $item->getPrice(); $itemsQty += $item->getQty(); $itemsDesc[] = $item->getName(); $productIds[] = $item->getProductId(); } // get countries of manufacture $productCollection = Mage::getResourceModel('catalog/product_collection')->addStoreFilter($request->getStoreId())->addFieldToFilter('entity_id', array('in' => $productIds))->addAttributeToSelect('country_of_manufacture'); foreach ($productCollection as $product) { $countriesOfManufacture[] = $product->getCountryOfManufacture(); } $paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER'; $requestClient = array('RequestedShipment' => array('ShipTimestamp' => time(), 'DropoffType' => $this->getConfigData('dropoff'), 'PackagingType' => $request->getPackagingType(), 'ServiceType' => $request->getShippingMethod(), 'Shipper' => array('Contact' => array('PersonName' => $request->getShipperContactPersonName(), 'CompanyName' => $request->getShipperContactCompanyName(), 'PhoneNumber' => $request->getShipperContactPhoneNumber()), 'Address' => array('StreetLines' => array($request->getShipperAddressStreet1(), $request->getShipperAddressStreet2()), 'City' => $request->getShipperAddressCity(), 'StateOrProvinceCode' => $request->getShipperAddressStateOrProvinceCode(), 'PostalCode' => $request->getShipperAddressPostalCode(), 'CountryCode' => $request->getShipperAddressCountryCode())), 'Recipient' => array('Contact' => array('PersonName' => $request->getRecipientContactPersonName(), 'CompanyName' => $request->getRecipientContactCompanyName(), 'PhoneNumber' => $request->getRecipientContactPhoneNumber()), 'Address' => array('StreetLines' => array($request->getRecipientAddressStreet1(), $request->getRecipientAddressStreet2()), 'City' => $request->getRecipientAddressCity(), 'StateOrProvinceCode' => $request->getRecipientAddressStateOrProvinceCode(), 'PostalCode' => $request->getRecipientAddressPostalCode(), 'CountryCode' => $request->getRecipientAddressCountryCode(), 'Residential' => (bool) $this->getConfigData('residence_delivery'))), 'ShippingChargesPayment' => array('PaymentType' => $paymentType, 'Payor' => array('AccountNumber' => $this->getConfigData('account'), 'CountryCode' => Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $request->getStoreId()))), 'LabelSpecification' => array('LabelFormatType' => 'COMMON2D', 'ImageType' => 'PNG', 'LabelStockType' => 'PAPER_8.5X11_TOP_HALF_LABEL'), 'RateRequestTypes' => array('ACCOUNT'), 'PackageCount' => 1, 'RequestedPackageLineItems' => array('SequenceNumber' => '1', 'Weight' => array('Units' => $weightUnits, 'Value' => $request->getPackageWeight()), 'CustomerReferences' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => $referenceData), 'SpecialServicesRequested' => array('SpecialServiceTypes' => 'SIGNATURE_OPTION', 'SignatureOptionDetail' => array('OptionType' => $packageParams->getDeliveryConfirmation()))))); // for international shipping if ($request->getShipperAddressCountryCode() != $request->getRecipientAddressCountryCode()) { $requestClient['RequestedShipment']['CustomsClearanceDetail'] = array('CustomsValue' => array('Currency' => $request->getBaseCurrencyCode(), 'Amount' => $customsValue), 'DutiesPayment' => array('PaymentType' => $paymentType, 'Payor' => array('AccountNumber' => $this->getConfigData('account'), 'CountryCode' => Mage::getStoreConfig(Mage_Shipping_Model_Shipping::XML_PATH_STORE_COUNTRY_ID, $request->getStoreId()))), 'Commodities' => array('Weight' => array('Units' => $weightUnits, 'Value' => $request->getPackageWeight()), 'NumberOfPieces' => 1, 'CountryOfManufacture' => implode(',', array_unique($countriesOfManufacture)), 'Description' => implode(', ', $itemsDesc), 'Quantity' => ceil($itemsQty), 'QuantityUnits' => 'pcs', 'UnitPrice' => array('Currency' => $request->getBaseCurrencyCode(), 'Amount' => $unitPrice), 'CustomsValue' => array('Currency' => $request->getBaseCurrencyCode(), 'Amount' => $customsValue))); } if ($request->getMasterTrackingId()) { $requestClient['RequestedShipment']['MasterTrackingId'] = $request->getMasterTrackingId(); } // set dimensions if ($length || $width || $height) { $requestClient['RequestedShipment']['RequestedPackageLineItems']['Dimensions'] = array(); $dimenssions =& $requestClient['RequestedShipment']['RequestedPackageLineItems']['Dimensions']; $dimenssions['Length'] = $length; $dimenssions['Width'] = $width; $dimenssions['Height'] = $height; $dimenssions['Units'] = $dimensionsUnits; } return $this->_getAuthDetails() + $requestClient; }
/** * Draw packages block * * @param Zend_Pdf_Page $page * @return Mage_Sales_Model_Order_Pdf_Shipment_Packaging */ protected function _drawPackageBlock(Zend_Pdf_Page $page) { if ($this->getPackageShippingBlock()) { $packaging = $this->getPackageShippingBlock(); } else { $packaging = Mage::getBlockSingleton('adminhtml/sales_order_shipment_packaging'); } $packages = $packaging->getPackages(); $packageNum = 1; foreach ($packages as $packageId => $package) { $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->drawRectangle(25, $this->y + 15, 190, $this->y - 35); $page->drawRectangle(190, $this->y + 15, 350, $this->y - 35); $page->drawRectangle(350, $this->y + 15, 570, $this->y - 35); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle(520, $this->y + 15, 570, $this->y - 5); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $packageText = Mage::helper('sales')->__('Package') . ' ' . $packageNum; $page->drawText($packageText, 525, $this->y, 'UTF-8'); $packageNum++; $package = new Varien_Object($package); $params = new Varien_Object($package->getParams()); $dimensionUnits = Mage::helper('usa')->getMeasureDimensionName($params->getDimensionUnits()); $typeText = Mage::helper('sales')->__('Type') . ' : ' . $packaging->getContainerTypeByCode($params->getContainer()); $page->drawText($typeText, 35, $this->y, 'UTF-8'); if ($params->getLength() != null) { $lengthText = $params->getLength() . ' ' . $dimensionUnits; } else { $lengthText = '--'; } $lengthText = Mage::helper('sales')->__('Length') . ' : ' . $lengthText; $page->drawText($lengthText, 200, $this->y, 'UTF-8'); if ($params->getDeliveryConfirmation() != null) { $confirmationText = Mage::helper('sales')->__('Signature Confirmation') . ' : ' . $packaging->getDeliveryConfirmationTypeByCode($params->getDeliveryConfirmation()); $page->drawText($confirmationText, 355, $this->y, 'UTF-8'); } $this->y = $this->y - 10; if ($packaging->displayCustomsValue() != null) { $customsValueText = Mage::helper('sales')->__('Customs Value') . ' : ' . $packaging->displayPrice($params->getCustomsValue()); $page->drawText($customsValueText, 35, $this->y, 'UTF-8'); } if ($params->getWidth() != null) { $widthText = $params->getWidth() . ' ' . $dimensionUnits; } else { $widthText = '--'; } $widthText = Mage::helper('sales')->__('Width') . ' : ' . $widthText; $page->drawText($widthText, 200, $this->y, 'UTF-8'); if ($params->getContentType() != null) { if ($params->getContentType() == 'OTHER') { $contentsValue = $params->getContentTypeOther(); } else { $contentsValue = $packaging->getContentTypeByCode($params->getContentType()); } $contentsText = Mage::helper('sales')->__('Contents') . ' : ' . $contentsValue; $page->drawText($contentsText, 355, $this->y, 'UTF-8'); } $this->y = $this->y - 10; $weightText = Mage::helper('sales')->__('Total Weight') . ' : ' . $params->getWeight() . ' ' . Mage::helper('usa')->getMeasureWeightName($params->getWeightUnits()); $page->drawText($weightText, 35, $this->y, 'UTF-8'); if ($params->getHeight() != null) { $heightText = $params->getHeight() . ' ' . $dimensionUnits; } else { $heightText = '--'; } $heightText = Mage::helper('sales')->__('Height') . ' : ' . $heightText; $page->drawText($heightText, 200, $this->y, 'UTF-8'); $this->y = $this->y - 10; if ($params->getSize()) { $sizeText = Mage::helper('sales')->__('Size') . ' : ' . ucfirst(strtolower($params->getSize())); $page->drawText($sizeText, 35, $this->y, 'UTF-8'); } if ($params->getGirth() != null) { $dimensionGirthUnits = Mage::helper('usa')->getMeasureDimensionName($params->getGirthDimensionUnits()); $girthText = Mage::helper('sales')->__('Girth') . ' : ' . $params->getGirth() . ' ' . $dimensionGirthUnits; $page->drawText($girthText, 200, $this->y, 'UTF-8'); } $this->y = $this->y - 5; $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle(25, $this->y, 570, $this->y - 30 - count($package->getItems()) * 12); $this->y = $this->y - 10; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $page->drawText(Mage::helper('sales')->__('Items in the Package'), 30, $this->y, 'UTF-8'); $txtIndent = 5; $itemCollsNumber = $packaging->displayCustomsValue() ? 5 : 4; $itemCollsX[0] = 30; // coordinate for Product name $itemCollsX[1] = 250; // coordinate for Product name $itemCollsXEnd = 565; $itemCollsXStep = round(($itemCollsXEnd - $itemCollsX[1]) / ($itemCollsNumber - 1)); // calculate coordinates for all other cells (Weight, Customs Value, Qty Ordered, Qty) for ($i = 2; $i <= $itemCollsNumber; $i++) { $itemCollsX[$i] = $itemCollsX[$i - 1] + $itemCollsXStep; } $i = 0; $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsXEnd, $this->y - 15); $this->y = $this->y - 12; $i = 0; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $page->drawText(Mage::helper('sales')->__('Product'), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Weight'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); if ($packaging->displayCustomsValue()) { $page->drawText(Mage::helper('sales')->__('Customs Value'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); } $page->drawText(Mage::helper('sales')->__('Qty Ordered'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Qty'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); $i = 0; foreach ($package->getItems() as $itemId => $item) { $item = new Varien_Object($item); $i = 0; $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15); $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsXEnd, $this->y - 15); $this->y = $this->y - 12; $i = 0; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $page->drawText($item->getName(), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8'); $page->drawText($item->getWeight(), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); if ($packaging->displayCustomsValue()) { $page->drawText($packaging->displayPrice($item->getCustomsValue()), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); } $page->drawText($packaging->getQtyOrderedItem($item->getOrderItemId()), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); $page->drawText($item->getQty() * 1, $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'); } $this->y = $this->y - 30; } return $this; }