本文整理汇总了PHP中Mage_Sales_Model_Quote::addProduct方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Quote::addProduct方法的具体用法?PHP Mage_Sales_Model_Quote::addProduct怎么用?PHP Mage_Sales_Model_Quote::addProduct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Quote
的用法示例。
在下文中一共展示了Mage_Sales_Model_Quote::addProduct方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initializeQuoteItems
private function initializeQuoteItems()
{
foreach ($this->proxyOrder->getItems() as $item) {
$this->clearQuoteItemsCache();
/** @var $quoteItemBuilder Ess_M2ePro_Model_Magento_Quote_Item */
$quoteItemBuilder = Mage::getModel('M2ePro/Magento_Quote_Item');
$quoteItemBuilder->init($this->quote, $item);
$product = $quoteItemBuilder->getProduct();
$request = $quoteItemBuilder->getRequest();
// ----------------------------
$productOriginalPrice = (double) $product->getPrice();
$price = $item->getBasePrice();
$product->setPrice($price);
$product->setSpecialPrice($price);
// ----------------------------
// see Mage_Sales_Model_Observer::substractQtyFromQuotes
$this->quote->setItemsCount($this->quote->getItemsCount() + 1);
$this->quote->setItemsQty((double) $this->quote->getItemsQty() + $request->getQty());
$result = $this->quote->addProduct($product, $request);
if (is_string($result)) {
throw new Exception($result);
}
$quoteItem = $this->quote->getItemByProduct($product);
if ($quoteItem !== false) {
$weight = $product->getTypeInstance()->getWeight();
if ($product->isConfigurable()) {
// hack: for child product weight was not load
$simpleProductId = $product->getCustomOption('simple_product')->getProductId();
$weight = Mage::getResourceModel('catalog/product')->getAttributeRawValue($simpleProductId, 'weight', 0);
}
$quoteItem->setStoreId($this->quote->getStoreId());
$quoteItem->setOriginalCustomPrice($item->getPrice());
$quoteItem->setOriginalPrice($productOriginalPrice);
$quoteItem->setBaseOriginalPrice($productOriginalPrice);
$quoteItem->setWeight($weight);
$quoteItem->setNoDiscount(1);
$giftMessageId = $quoteItemBuilder->getGiftMessageId();
if (!empty($giftMessageId)) {
$quoteItem->setGiftMessageId($giftMessageId);
}
$quoteItem->setAdditionalData($quoteItemBuilder->getAdditionalData($quoteItem));
}
}
}
示例2: initializeQuoteItems
/**
* Initialize quote items objects
*
* @throws Exception
*/
private function initializeQuoteItems()
{
foreach ($this->proxyOrder->getItems() as $item) {
$this->clearQuoteItemsCache();
/** @var $quoteItemBuilder Ess_M2ePro_Model_Magento_Quote_Item */
$quoteItemBuilder = Mage::getModel('M2ePro/Magento_Quote_Item');
$quoteItemBuilder->init($this->quote, $item);
$product = $quoteItemBuilder->getProduct();
$request = $quoteItemBuilder->getRequest();
// see Mage_Sales_Model_Observer::substractQtyFromQuotes
$this->quote->setItemsCount($this->quote->getItemsCount() + 1);
$this->quote->setItemsQty((double) $this->quote->getItemsQty() + $request->getQty());
$result = $this->quote->addProduct($product, $request);
if (is_string($result)) {
throw new Exception($result);
}
$quoteItem = $this->quote->getItemByProduct($product);
if ($quoteItem !== false) {
$quoteItem->setOriginalCustomPrice($item->getPrice());
$quoteItem->setNoDiscount(1);
$quoteItem->setGiftMessageId($quoteItemBuilder->getGiftMessageId());
$quoteItem->setAdditionalData($quoteItemBuilder->getAdditionalData($quoteItem));
}
}
}
示例3: testCollectTotalsWithVirtual
/**
* @magentoDataFixture Mage/Catalog/_files/product_virtual.php
* @magentoDataFixture Mage/Sales/_files/quote.php
*/
public function testCollectTotalsWithVirtual()
{
$quote = new Mage_Sales_Model_Quote();
$quote->load('test01', 'reserved_order_id');
$product = new Mage_Catalog_Model_Product();
$product->load(21);
$quote->addProduct($product);
$quote->collectTotals();
$this->assertEquals(2, $quote->getItemsQty());
$this->assertEquals(1, $quote->getVirtualItemsQty());
$this->assertEquals(20, $quote->getGrandTotal());
$this->assertEquals(20, $quote->getBaseGrandTotal());
}
示例4: initializeQuoteItems
/**
* Initialize quote items objects
*
* @throws Exception
*/
private function initializeQuoteItems()
{
foreach ($this->proxyOrder->getItems() as $item) {
/** @var $quoteItemBuilder Ess_M2ePro_Model_Magento_Quote_Item */
$quoteItemBuilder = Mage::getModel('M2ePro/Magento_Quote_Item');
$quoteItemBuilder->setQuoteBuilder($this)->setProxyItem($item);
$product = $quoteItemBuilder->getProduct();
$request = $quoteItemBuilder->getRequest();
$this->quote->setItemsCount($this->quote->getItemsCount() + 1);
$this->quote->setItemsQty((double) $this->quote->getItemsQty() + $request->getQty());
$result = $this->quote->addProduct($product, $request);
if (is_string($result)) {
throw new Exception($result);
}
$quoteItem = $this->quote->getItemByProduct($product);
if ($quoteItem !== false) {
$quoteItem->setOriginalCustomPrice($quoteItemBuilder->getChannelCurrencyPrice());
$quoteItem->setNoDiscount(1);
$quoteItem->setGiftMessageId($quoteItemBuilder->getGiftMessageId());
$quoteItem->setAdditionalData($quoteItemBuilder->getAdditionalData($quoteItem));
}
}
}
示例5: _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']));
//.........这里部分代码省略.........
示例6: createResource
/**
* Create a resource model
*
* @param Mage_Sales_Model_Quote $quote
* @param array $data
*
* @return Mage_Sales_Model_Quote_Item
*/
public function createResource(Mage_Sales_Model_Quote $quote, array $data)
{
// Store current state
$actionType = $this->getActionType();
$operation = $this->getOperation();
// Change state
$this->setActionType(self::ACTION_TYPE_ENTITY);
$this->setOperation(self::OPERATION_CREATE);
// Filter raw incoming data
$data = $this->getFilter()->in($data);
// Map data keys
$data = $this->mapAttributes($data);
// Validate we have a SKU
if (!isset($data['sku'])) {
$this->_critical('Missing SKU', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
// Load product based on SKU
/** @var Mage_Catalog_Model_Product $product */
$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load(Mage::getResourceModel('catalog/product')->getIdBySku($data['sku']));
// If there is no product with that SKU, throw an error
if (!$product->getId()) {
$this->_critical('Invalid SKU ' . $data['sku'], Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
// If the SKU is not enabled, throw an error ("isInStock" is a badly named method)
if (!$product->isInStock()) {
$this->_critical('Invalid SKU ' . $data['sku'], Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
// If the SKU is not visible for the current website, throw an error
if (!$product->isVisibleInSiteVisibility()) {
$this->_critical('Invalid SKU ' . $data['sku'], Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
if (!Mage::app()->isSingleStoreMode()) {
// If the SKU is not available for the current website, throw an error
if (!is_array($product->getWebsiteIds()) || !in_array(Mage::app()->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
$this->_critical('Invalid SKU ' . $data['sku'], Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
}
// Ensure we have a quantity
if (!isset($data['qty'])) {
$data['qty'] = 1;
}
$data['qty'] = floatval($data['qty']);
// Ensure we have a min quantity if required
if (!$quote->hasProductId($product->getId()) && $product->getStockItem()) {
$minimumQty = floatval($product->getStockItem()->getMinSaleQty());
if ($minimumQty > 0.0 && $data['qty'] < $minimumQty) {
$data['qty'] = $minimumQty;
}
}
// Add product to quote
try {
$product->setSkipCheckRequiredOption(true);
$resource = $quote->addProduct($product, new Varien_Object($data));
// This is to work around a bug in Mage_Sales_Model_Quote::addProductAdvanced
// The method incorrectly returns $item when it SHOULD return $parentItem
if ($resource instanceof Mage_Sales_Model_Quote_Item && $resource->getParentItem()) {
$resource = $resource->getParentItem();
}
} catch (Exception $e) {
$resource = $e->getMessage();
}
// Check for errors
if (is_string($resource)) {
$this->_critical($resource, Mage_Api2_Model_Server::HTTP_BAD_REQUEST);
}
// Restore old state
$this->setActionType($actionType);
$this->setOperation($operation);
// Return updated resource
return $resource;
}
示例7: addNewItems
/**
* Apply newly added products to quote
*
* @param Mage_Sales_Model_Quote $quote
* @param $data
* @return $this
*/
public function addNewItems(Mage_Sales_Model_Quote $quote, $data)
{
foreach ($data as $productId => $params) {
$product = Mage::getModel('catalog/product')->setStoreId($quote->getStoreId())->load($productId);
if (!$product || !$product->getId()) {
continue;
}
// if (!$quote->getItemByProduct($product))
// {
if (!isset($params['product'])) {
$params['product'] = $product->getId();
}
$newQuoteItem = $quote->addProduct($product, new Varien_Object($params));
/** @var Mage_Sales_Model_Quote_Item $item */
//$item = $quote->getItemByProduct($product);
// } else {
// $item = $quote->getItemByProduct($product);
// if (isset($params['qty'])) {
// $qty = $item->getQty();
// $item->setQty($params['qty']);
// }
// $item->save();
// }
}
if (Mage::registry('orderspro_order')) {
Mage::helper('mageworx_orderspro/edit')->addPendingChanges(Mage::registry('orderspro_order')->getId(), array('product_to_add' => array()));
}
return $this;
}
示例8: _setQuoteVirtualItem
/**
* @param Mage_Sales_Model_Quote $quote
*
* @return Mage_Sales_Model_Quote
*/
protected function _setQuoteVirtualItem(Mage_Sales_Model_Quote $quote)
{
if (!count($this->_virtualObjectStack)) {
return $quote;
}
$quote->setIsSuperMode(true);
foreach ($this->_virtualObjectStack as $obj) {
/* @var $obj Varien_Object */
$amountWithTax = $obj->getUnitAmountWithTax();
/* @var $merged Mage_Catalog_Model_Product */
$merged = $this->_getCouponHelper()->createProductFromShopgateCoupon($obj);
/* @var $quoteItem Mage_Sales_Model_Quote_Item */
$quoteItem = $quote->addProduct($merged, $obj->getQty());
$quoteItem->setCustomPrice($amountWithTax);
$quoteItem->setOriginalPrice($amountWithTax);
$quoteItem->setOriginalCustomPrice($amountWithTax);
$quoteItem->setNoDiscount(true);
$quoteItem->setRowWeight(0);
$quoteItem->setWeeeTaxApplied(serialize(array()));
}
return $quote;
}
示例9: initFromOrderItem
/**
* Initialize creation data from existing order Item
*
* @param Mage_Sales_Model_Order_Item $orderItem
* @param int $qty
* @return Mage_Sales_Model_Quote_Item | string
*/
protected function initFromOrderItem(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order_Item $orderItem, $qty, $storeId)
{
if (!$orderItem->getId()) {
return $this;
}
$product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($orderItem->getProductId());
if ($product->getId()) {
$product->setSkipCheckRequiredOption(true);
$buyRequest = $orderItem->getBuyRequest();
if (is_numeric($qty)) {
$buyRequest->setQty($qty);
}
$item = $quote->addProduct($product, $buyRequest);
if (is_string($item)) {
return $item;
}
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;
}