本文整理汇总了PHP中Varien_Object::setQty方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Object::setQty方法的具体用法?PHP Varien_Object::setQty怎么用?PHP Varien_Object::setQty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Object
的用法示例。
在下文中一共展示了Varien_Object::setQty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: inventoryPush
/**
* 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;
}
示例2: testPrepareCartObserverQty
/**
*
* @loadFixture testPrepareCart
* @dataProvider provider__testPrepareCartObserverQty
* The main goul of this test is to check if the error will be araised if items are added one by one
*
*/
public function testPrepareCartObserverQty($dealId, $qty, $productId, $expectedPrice, $infoBuyRequest, $count, $uid)
{
$deal = Mage::getModel('collpur/deal')->load($dealId);
/* set deal id in request */
Mage::app()->getRequest()->setParam('deal_id', $dealId);
Mage::app()->getRequest()->setParam('product', $productId);
$observer = new Varien_Object();
$buyRequest = new Varien_Object();
$product = Mage::getModel('catalog/product')->load($productId);
$buyRequest->setQty($qty);
$observer->setBuyRequest($buyRequest);
$observer->setProduct($product);
/* set quote id and replace existing one in session */
$quote = $this->getModelMock('sales/quote');
$quoteItemsCollection = array();
for ($i = 0; $i < $count; $i++) {
$item = $this->getModelMock('sales/quote_item');
$optionByCode = new Varien_Object();
$optionByCode->setValue($infoBuyRequest);
$item->expects($this->any())->method('getOptionByCode')->will($this->returnValue($optionByCode));
$item->expects($this->any())->method('getQty')->will($this->returnValue(1));
$quoteItemsCollection[] = $item;
}
$quote->expects($this->any())->method('getId')->will($this->returnValue(1));
$quote->expects($this->any())->method('getItemsCollection')->will($this->returnValue($quoteItemsCollection));
Mage::getSingleton('checkout/session')->replaceQuote($quote);
if ($uid == '002') {
$this->setExpectedException('Mage_Checkout_Exception');
}
Mage::getModel('collpur/observer')->prepareCart($observer);
}
示例3: _getProductRequest
/**
* Get request for product add to cart procedure
*
* @param mixed $requestInfo
* @return Varien_Object
*/
protected function _getProductRequest($requestInfo)
{
if ($requestInfo instanceof Varien_Object) {
$request = $requestInfo;
} elseif (is_numeric($requestInfo)) {
$request = new Varien_Object();
$request->setQty($requestInfo);
} else {
$request = new Varien_Object($requestInfo);
}
if (!$request->hasQty()) {
$request->setQty(1);
}
return $request;
}
示例4: estimate
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;
}
示例5: getBuyRequest
/**
* 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;
}
示例6: addMaintenanceToSerialized
/**
* Called from payperrentals/inventory helper after_booked event of getBooked()
*
* Observer that adds maintenance quantity when using specific maintenance dates to
* the serialized inventory field of the product
*
* @param Varien_Event_Observer $observer
*/
function addMaintenanceToSerialized(Varien_Event_Observer $observer)
{
$booked = $observer->getResult()->getBooked();
$reservedCollection = $observer->getReservedCollection();
/** @var $maintenanceColl ITwebexperts_Maintenance_Model_Mysql4_Items_Collection */
foreach ($booked as $productid => $booking) {
$maintenanceColl = Mage::getModel('simaintenance/items')->getCollection();
$maintenanceColl->addFieldToFilter('product_id', $productid);
foreach ($maintenanceColl as $maintenanceItem) {
if (is_null($maintenanceItem->getStartDate()) || $maintenanceItem->getSpecificDates()) {
continue;
}
$start = strtotime($maintenanceItem->getStartDate());
$end = strtotime($maintenanceItem->getEndDate());
$usetimes = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productid, 'payperrentals_use_times', Mage::app()->getStore()->getStoreId());
if (date('H:i:s', $start) != '00:00:00' || date('H:i:s', $end) != '23:59:00' && date('H:i:s', $end) != '23:58:59' || $usetimes == 1) {
$configHelper = Mage::helper('payperrentals/config');
$timeIncrement = $configHelper->getTimeIncrement() * 60;
} else {
$timeIncrement = 3600 * 24;
}
while ($start < $end) {
$dateFormatted = date('Y-m-d H:i', $start);
if (!isset($booking[$dateFormatted])) {
$vObject = new Varien_Object();
$vObject->setQty($maintenanceItem->getQuantity());
$vObject->setOrders(array('m'));
$booking[$dateFormatted] = $vObject;
} else {
$vObject = $booking[$dateFormatted];
$vObject->setQty($vObject->getQty() + $maintenanceItem->getQuantity());
$orderArr = $vObject->getOrders();
$orderArr = array_merge($orderArr, array('m'));
$vObject->setOrders($orderArr);
}
$booked[$productid][$dateFormatted] = $vObject;
$start += $timeIncrement;
}
}
}
$observer->getResult()->setBooked($booked);
}
示例7: initFromOrderItem
/**
* Initialize creation data from existing order Item
*
* @param Mage_Sales_Model_Order_Item $orderItem
* @return Mage_Sales_Model_Quote_Item | string
*/
public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = 1)
{
if (!$orderItem->getId()) {
return $this;
}
$product = Mage::getModel('catalog/product')->setStoreId($this->getSession()->getStoreId())->load($orderItem->getProductId());
if ($product->getId()) {
$info = $orderItem->getProductOptionByCode('info_buyRequest');
$info = new Varien_Object($info);
$product->setSkipCheckRequiredOption(true);
$info->setQty($orderItem->getQtyOrdered());
$item = $this->getQuote()->addProduct($product, $info);
if (is_string($item)) {
return $item;
}
//$item->setQty($qty);
if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
$item->addOption(new Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions))));
}
Mage::dispatchEvent('sales_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item));
return $item;
}
return $this;
}
示例8: addProductAdvanced
public function addProductAdvanced(Mage_Catalog_Model_Product $product, $request = null, $processMode = null)
{
if ($request === null) {
$request = 1;
}
if (is_numeric($request)) {
$request = new Varien_Object(array('qty' => $request));
}
if (!$request instanceof Varien_Object) {
Mage::throwException(Mage::helper('sales')->__('Invalid request for adding product to quote.'));
}
switch ($product->getTypeId()) {
case 'simple':
case 'virtual':
case 'downloadable':
case 'configurable':
case 'bundle':
$qty = $request->getQty();
if ($qty > 1) {
$request->setQty(1);
for ($i = 1; $i < $qty; $i++) {
$lineProduct = clone $product;
$lineRequest = clone $request;
$this->addProductAdvanced($lineProduct, $lineRequest, $processMode);
}
}
break;
case 'grouped':
$superGroup = $request->getSuperGroup();
foreach ($superGroup as $productId => $qty) {
if ($qty > 1) {
for ($i = 1; $i < $qty; $i++) {
$customSuperGroup = $request->getSuperGroup();
foreach ($customSuperGroup as $customProductId => $customQty) {
$customSuperGroup[$customProductId] = $customProductId === $productId ? 1 : 0;
}
$lineProduct = clone $product;
$lineRequest = clone $request;
$lineRequest->setSuperGroup($customSuperGroup);
$this->addProductAdvanced($lineProduct, $lineRequest, $processMode);
}
}
$superGroup[$productId] = $qty > 0 ? 1 : 0;
}
$request->setSuperGroup($superGroup);
break;
}
$cartCandidates = $product->getTypeInstance(true)->prepareForCartAdvanced($request, $product, $processMode);
/**
* Error message
*/
if (is_string($cartCandidates)) {
return $cartCandidates;
}
/**
* If prepare process return one object
*/
if (!is_array($cartCandidates)) {
$cartCandidates = array($cartCandidates);
}
$parentItem = null;
$errors = array();
$items = array();
foreach ($cartCandidates as $candidate) {
// Child items can be sticked together only within their parent
$stickWithinParent = $candidate->getParentProductId() ? $parentItem : null;
$candidate->setStickWithinParent($stickWithinParent);
$item = $this->_addCatalogProduct($candidate, $candidate->getCartQty());
if ($request->getResetCount() && !$stickWithinParent && $item->getId() === $request->getId()) {
$item->setData('qty', 0);
}
$items[] = $item;
/**
* As parent item we should always use the item of first added product
*/
if (!$parentItem) {
$parentItem = $item;
}
if ($parentItem && $candidate->getParentProductId()) {
$item->setParentItem($parentItem);
}
/**
* We specify qty after we know about parent (for stock)
*/
$item->addQty($candidate->getCartQty());
// collect errors instead of throwing first one
if ($item->getHasError()) {
$message = $item->getMessage();
if (!in_array($message, $errors)) {
// filter duplicate messages
$errors[] = $message;
}
}
}
if (!empty($errors)) {
Mage::throwException(implode("\n", $errors));
}
Mage::dispatchEvent('sales_quote_product_add_after', array('items' => $items));
return $item;
}
示例9: updateAttQtyAction
public function updateAttQtyAction()
{
$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) {
$success_param = array();
if ($quoteItem) {
if ($quoteItem->getProduct()->getTypeInstance(true)->getSpecifyOptionMessage() == $e->getMessage()) {
$all_params = $params['super_attribute'];
$productCollection = $quoteItem->getProduct()->getTypeInstance(true)->getUsedProductCollection($quoteItem->getProduct());
foreach ($all_params as $attribute_id => $value) {
$tmp_params = $success_param;
$tmp_params[$attribute_id] = $value;
$productObject = $quoteItem->getProduct()->getTypeInstance(true)->getProductByAttributes($tmp_params, $quoteItem->getProduct());
if ($productObject && $productObject->getId()) {
$success_param[$attribute_id] = $value;
$productCollection->addAttributeToFilter($attribute_id, $value);
} else {
$result['update_attribute'] = $attribute_id;
$attribute_data = array();
$attribute = null;
$product = Mage::getModel('catalog/product')->load($quoteItem->getProduct()->getId());
$product->getTypeInstance(true)->getUsedProductAttributeIds($product);
$usedAttributes = $product->getData('_cache_instance_used_attributes');
foreach ($usedAttributes as $key => $_arrtibute) {
if ($key == $attribute_id) {
$attribute = $_arrtibute;
break;
}
}
foreach ($productCollection as $_product) {
$_product = Mage::getModel('catalog/product')->load($_product->getId());
if ($_product->isSaleable()) {
$_key = $_product->getData($attribute->getProductAttribute()->getAttributeCode());
foreach ($attribute->getPrices() as $_v) {
if ($_v['value_index'] == $_key) {
$attribute_data[$_key] = $_v['label'];
break;
}
}
}
}
$result['attribute_data'] = $attribute_data;
break;
}
}
}
}
//.........这里部分代码省略.........
示例10: _addProductsToQuote
protected function _addProductsToQuote($productInCardList, $paramsArray)
{
$productInCardList = $this->_concatenateProductsInQuote($productInCardList);
foreach ($productInCardList as $productItem) {
$product = Mage::getModel('catalog/product')->load($productItem['id']);
if (!$product->getId()) {
throw new LogicException('Product does not exist. Probably it was deleted.');
}
if ($product->getStatus() === Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
throw new LogicException('Product is disabled.');
}
$productTypeId = $product->getTypeId();
if ($productTypeId == Ess_M2ePro_Model_MagentoProduct::TYPE_GROUPED) {
// Grouped product converted to assigned simple
if (!isset($productItem['options'])) {
throw new LogicException('The item does not have options. At the current version, Order Import for grouped product supports only multi variation listing.');
}
$product = $this->_getRelatedProductFromGroupedForEbayData($product, $productItem);
if (is_null($product)) {
throw new LogicException('There is no associated products found for grouped product.');
} else {
$productTypeId = $product->getTypeId();
}
}
$productItem['price'] = $this->_getConvertedPrice($productItem['price']);
$request = new Varien_Object();
$request->setQty($productItem['qty']);
switch ($productTypeId) {
case Ess_M2ePro_Model_MagentoProduct::TYPE_SIMPLE:
$haveRequiredOptionsInstant = $product->getTypeInstance(true)->hasRequiredOptions($product);
$haveRequiredOptions = $product->hasRequiredOptions();
if ($haveRequiredOptions && !$product->getRequiredOptions()) {
$haveRequiredOptions = false;
// important: possible incorect behavior
}
if ($haveRequiredOptionsInstant || $haveRequiredOptions || $this->_checkSimpleProductHasRequiredCustomOptions($product)) {
$customOptionsData = array();
if (isset($productItem['options']) && count($productItem['options'])) {
// Have multivariation data for simple product
// Use to set Custom Options data
$customOptionsData = $this->_getCustomOptionsForEbayData($productItem);
$this->_addNotifyMessage('Product has <b>Required Options</b>. Selected Options Values are taken from eBay Multi Variation Data');
} else {
// No multivariation data, set first required option
$customOptionsData = $this->_getRandomCustomOptions($productItem);
$this->_addNotifyMessage('Product has <b>Required Options</b>. First option value is selected.');
}
$request->setOptions($customOptionsData['options']);
// Dec price for percent change (after apply percent price inc = need price)
$productItem['price'] = $productItem['price'] / (1 + $customOptionsData['price_change_percent'] / 100);
// Change for custom options price. price_change_fixed low that 0 when option inc price, more 0 - when inc
$productItem['price'] += $customOptionsData['price_change_fixed'] / (1 + $customOptionsData['price_change_percent'] / 100);
}
// end of $haveRequriedOptions
break;
case Ess_M2ePro_Model_MagentoProduct::TYPE_CONFIGURABLE:
if (!isset($productItem['options'])) {
throw new LogicException('The item does not have options. At the current version, Order Import for configurable product supports only multi variation listing.');
}
$configurableOptions = $this->_getConfigurableAttributeForEbayData($productItem);
// Set selected attributes
$request->setSuperAttribute($configurableOptions['options']);
// Each option value can change total price value, remove
// this changes for equal: order price = eBay sold price
$productItem['price'] += $configurableOptions['price_change'];
break;
case Ess_M2ePro_Model_MagentoProduct::TYPE_BUNDLE:
if (!isset($productItem['options'])) {
throw new LogicException('The item does not have options. At the current version, Order Import for bundle product supports only multi variation listing.');
}
$bundleOptions = $this->_getBundleOptionsForEbayData($productItem);
$request->setBundleOption($bundleOptions['options']);
// $bundleQty = array();
// foreach ($bundleOptions['options'] as $optionId => $optionValue) {
// $bundleQty[$optionId] = $productItem['qty'];
// }
// $request->setBundleOptionQty($bundleQty);
// $request->setQty(1);
$this->_addNotifyMessage('Price for Bundle item is taken from Magento store.');
break;
default:
throw new LogicException('At the current version, Order Import does not support product type: ' . $productTypeId . '');
}
$product->setPrice($productItem['price']);
$product->setSpecialPrice($productItem['price']);
$this->_initProductTaxClassId($product, $paramsArray['taxPercent']);
$result = $this->_quote->addProduct($product, $request);
if (is_string($result)) {
throw new Exception($result);
}
// TODO: ugly hack
//if ($productTypeId == Ess_M2ePro_Model_MagentoProduct::TYPE_BUNDLE ||
// Ess_M2ePro_Model_MagentoProduct::TYPE_CONFIGURABLE ||
// Ess_M2ePro_Model_MagentoProduct::TYPE_GROUPED) {
foreach ($paramsArray['products'] as $tempProduct) {
if ($tempProduct['id'] == $product->getId()) {
$tempQuoteItem = $this->_quote->getItemByProduct($product);
if ($tempQuoteItem !== false) {
$tempQuoteItem->setNoDiscount(1);
$tempQuoteItem->setOriginalCustomPrice($this->_getConvertedPrice($tempProduct['price']));
//.........这里部分代码省略.........
示例11: getBuyRequest
/**
* 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->getProductOptionByCode('info_buyRequest');
if (!$option) {
$option = array();
}
$buyRequest = new Varien_Object($option);
$buyRequest->setQty($this->getQtyOrdered() * 1);
return $buyRequest;
}
示例12: changeattributecartAction
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));
}
示例13: _getSimpleShopgateCoupons
/**
* @param ShopgateCartBase $order
* @throws ShopgateLibraryException
*/
protected function _getSimpleShopgateCoupons(ShopgateCartBase $order)
{
if ($order instanceof ShopgateOrder) {
foreach ($order->getItems() as $item) {
/** @var ShopgateOrderItem $item */
if (!$item->isSgCoupon()) {
continue;
}
if ($this->useTaxClasses) {
$itemAmount = $item->getUnitAmount();
} else {
$itemAmount = $item->getUnitAmountWithTax();
}
$obj = new Varien_Object();
$obj->setName($item->getName());
$obj->setItemNumber($item->getItemNumber());
$obj->setUnitAmountWithTax($itemAmount);
$obj->setQty($item->getQuantity());
$this->_virtualObjectStack[] = $obj;
}
}
}
示例14: addProduct
/**
* Add product to current order quote
*
* $config can be integer qty (older behaviour, when no product configuration was possible)
* or it can be array of options (newer behaviour).
*
* In case of older behaviour same product ids are not added, but quote item qty is increased.
* In case of newer behaviour same product ids with different configs are added as separate quote items.
*
* @param mixed $product
* @param array|float|int|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 = is_array($config) ? new Varien_Object($config) : $config;
$qty = (double) $config->getQty();
$separateSameProducts = true;
} else {
$qty = (double) $config;
$config = new Varien_Object();
$config->setQty($qty);
$separateSameProducts = false;
}
if (!$product instanceof Mage_Catalog_Model_Product) {
$productId = $product;
$product = Mage::getModel('catalog/product')->setStore($this->getStore())->setStoreId($this->getStore()->getId())->load($product);
if (!$product->getId()) {
Mage::throwException(Mage::helper('adminhtml')->__('Failed to add a product to cart by id "%s".', $productId));
}
}
if ($product->getStockItem()) {
if (!$product->getStockItem()->getIsQtyDecimal()) {
$qty = (int) $qty;
} else {
$product->setIsQtyDecimal(1);
}
}
$qty = $qty > 0 ? $qty : 1;
$item = null;
if (!$separateSameProducts) {
$item = $this->getQuote()->getItemByProduct($product);
}
if ($item) {
$item->setQty($item->getQty() + $qty);
} else {
$item = $this->getQuote()->addProduct($product, $config);
if (is_string($item)) {
Mage::throwException($item);
}
$item->checkData();
}
$this->setRecollect(true);
return $this;
}
示例15: orderAction
/**
* Convert quote to order
*
* @return $this
*/
public function orderAction()
{
$quoteId = $this->getRequest()->getParam('quote_id');
try {
$this->_initQuote('quote_id');
$r4qQuote = Mage::registry('current_quote');
if (!$r4qQuote->getId()) {
throw new Exception($this->__('Wrong Quote ID'));
}
$orderSession = Mage::getSingleton('adminhtml/session_quote');
$orderSession->clear();
$orderCreateModel = Mage::getSingleton('adminhtml/sales_order_create');
$importData = array();
$customerModel = Mage::getModel('customer/customer');
$websites = Mage::app()->getWebsites();
foreach ($websites as $website) {
$customerModel->setWebsiteId($website->getId());
$customerModel->loadByEmail($r4qQuote->getCustomerEmail());
if ($customerModel->getId()) {
break;
}
}
//here needs to check if on import carries the entity_id. Thats why it might needs so the billing address has the same data as the rfq address
$billingAddressArray = $r4qQuote->getBillingAddress()->getData();
unset($billingAddressArray['address_id']);
$shippingAddressArray = $r4qQuote->getShippingAddress()->getData();
unset($shippingAddressArray['address_id']);
if ($customerModel->getId()) {
$orderSession->setCustomerId($customerModel->getId());
$importData['order'] = array('account' => array('email' => $r4qQuote->getCustomerEmail()), 'billing_address' => $billingAddressArray);
} else {
$orderSession->setCustomerId(0);
if ($r4qQuote->getCustomerEmail()) {
$importData['order'] = array('account' => array('email' => $r4qQuote->getCustomerEmail()), 'billing_address' => $billingAddressArray);
$importData['account'] = array('email' => $r4qQuote->getCustomerEmail());
}
}
if ($r4qQuote->getQuoteCurrencyCode()) {
$orderSession->setCurrencyId($r4qQuote->getQuoteCurrencyCode());
}
$orderSession->setStoreId($r4qQuote->getStoreId());
if ($r4qQuote->getShippingAddress()->getShippingMethod()) {
$orderSession->setShippingMethod($r4qQuote->getShippingAddress()->getShippingMethod());
}
// import order data
$orderCreateModel->importPostData($importData);
if ($r4qQuote->getBillingAddress()) {
$orderCreateModel->setBillingAddress($billingAddressArray);
}
if ($r4qQuote->getShippingAddress()) {
$orderCreateModel->setShippingAddress($shippingAddressArray);
}
if (!$r4qQuote->getR4qShippingAsBilling() || $r4qQuote->getR4qShippingAsBilling() == '0') {
//$orderCreateModel->setShippingAddress($r4qQuote->getBillingAddress());
$orderCreateModel->setShippingAsBilling(0);
}
// add items
foreach ($r4qQuote->getAllItems() as $item) {
if ($item->getParentItem()) {
continue;
}
$product = $item->getProduct();
if ($product) {
$product = Mage::getModel('catalog/product')->setStoreId($r4qQuote->getStoreId())->load($product->getId());
$info = $item->getOptionByCode('info_buyRequest');
if ($info) {
$infoBuyRequest = new Varien_Object(unserialize($info->getValue()));
} else {
$infoBuyRequest = new Varien_Object(array('qty' => 1));
}
if (isset($infoBuyRequest['start_date'])) {
$infoBuyRequest['start_date'] = date('Y-m-d', strtotime($infoBuyRequest['start_date']));
}
if (isset($infoBuyRequest['end_date'])) {
$infoBuyRequest['end_date'] = date('Y-m-d', strtotime($infoBuyRequest['end_date']));
}
if (Mage::helper('request4quote')->isOpenendedInstalled()) {
$infoBuyRequest[ITwebexperts_Openendedinvoices_Helper_Data::BILLING_PERIOD_CUSTOM_PRICE] = $item->getR4qPriceProposal();
}
$infoBuyRequest->setQty($item->getQty());
$infoBuyRequest->setStockId($item->getStockId());
if ($infoBuyRequest->getSelPay() && $infoBuyRequest->getSelPay() == 'recurring') {
$infoBuyRequest->setData(ITwebexperts_Request4quote_Model_Quote::PRICE_PROPOSAL_OPTION, 0);
} else {
$infoBuyRequest->setData(ITwebexperts_Request4quote_Model_Quote::PRICE_PROPOSAL_OPTION, $item->getR4qPriceProposal());
}
$infoBuyRequest->setData(ITwebexperts_Request4quote_Model_Quote::QUOTE_ID_OPTION, $r4qQuote->getId());
$orderCreateModel->addProduct($product, $infoBuyRequest->getData());
}
}
if ($r4qQuote->getCouponCode()) {
$orderCreateModel->applyCoupon($r4qQuote->getCouponCode());
}
$orderCreateModel->saveQuote();
$this->_redirect('adminhtml/sales_order_create/index');
//.........这里部分代码省略.........