本文整理汇总了PHP中Magento\Quote\Model\Quote类的典型用法代码示例。如果您正苦于以下问题:PHP Quote类的具体用法?PHP Quote怎么用?PHP Quote使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Quote类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->markTestIncomplete();
$this->messageManager = $this->getMockForAbstractClass('Magento\\Framework\\Message\\ManagerInterface');
$this->config = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false);
$this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
$this->quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
$this->quote->expects($this->any())->method('hasItems')->will($this->returnValue(true));
$this->redirect = $this->getMockForAbstractClass('Magento\\Framework\\App\\Response\\RedirectInterface');
$this->response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
$this->customerData = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
$this->checkout = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout', [], [], '', false);
$this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
$this->customerSession->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($this->customerData));
$this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
$this->checkoutFactory = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout\\Factory', [], [], '', false);
$this->checkoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->checkout));
$this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
$this->session = $this->getMock('Magento\\Framework\\Session\\Generic', [], [], '', false);
$objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
$this->objectManagerCallback = function ($className) {
if ($className == 'Magento\\Paypal\\Model\\Config') {
return $this->config;
}
return $this->getMock($className, [], [], '', false);
};
$objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) {
return call_user_func($this->objectManagerCallback, $className);
}));
$objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) {
return call_user_func($this->objectManagerCallback, $className);
}));
$helper = new ObjectManagerHelper($this);
$this->model = $helper->getObject('\\Magento\\\\Paypal\\Controller\\Express\\' . $this->name, ['messageManager' => $this->messageManager, 'response' => $this->response, 'redirect' => $this->redirect, 'request' => $this->request, 'customerSession' => $this->customerSession, 'checkoutSession' => $this->checkoutSession, 'checkoutFactory' => $this->checkoutFactory, 'paypalSession' => $this->session, 'objectManager' => $objectManager]);
}
示例2: populateQuoteAddress
/**
* @param \Magento\Quote\Model\Quote $quote
* @param array $details
* @return $this
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function populateQuoteAddress($quote, $details)
{
// import shipping address
$exportedShippingAddress = isset($details['shippingAddress']) ? $details['shippingAddress'] : null;
if (!$quote->getIsVirtual()) {
$shippingAddress = $quote->getShippingAddress();
if ($exportedShippingAddress) {
$this->importAddressData($shippingAddress, $exportedShippingAddress);
}
// PayPal doesn't provide detailed shipping info: prefix, suffix
$shippingAddress->setLastname($details['lastName']);
$shippingAddress->setFirstname($details['firstName']);
$shippingAddress->setEmail($details['email']);
$shippingAddress->setCollectShippingRates(true);
}
$exportedBillingAddress = isset($details['billingAddress']) ? $details['billingAddress'] : null;
$billingAddress = $quote->getBillingAddress();
if ($exportedBillingAddress) {
$this->importBillingAddressData($billingAddress, $exportedBillingAddress);
$billingAddress->setFirstname($details['firstName']);
$billingAddress->setLastname($details['lastName']);
$billingAddress->setEmail($details['email']);
} elseif ($billingAddress->getEmail() == null) {
$this->importAddressData($billingAddress, $exportedShippingAddress);
$billingAddress->setFirstname($details['firstName']);
$billingAddress->setLastname($details['lastName']);
$billingAddress->setEmail($details['email']);
}
return $this;
}
示例3: isFreeShipping
/**
* {@inheritDoc}
*/
public function isFreeShipping(\Magento\Quote\Model\Quote $quote, $items)
{
/** @var \Magento\Quote\Api\Data\CartItemInterface[] $items */
if (!count($items)) {
return false;
}
$addressFreeShipping = true;
$store = $this->storeManager->getStore($quote->getStoreId());
$this->calculator->init($store->getWebsiteId(), $quote->getCustomerGroupId(), $quote->getCouponCode());
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
foreach ($items as $item) {
if ($item->getNoDiscount()) {
$addressFreeShipping = false;
$item->setFreeShipping(false);
continue;
}
/** Child item discount we calculate for parent */
if ($item->getParentItemId()) {
continue;
}
$this->calculator->processFreeShipping($item);
$itemFreeShipping = (bool) $item->getFreeShipping();
$addressFreeShipping = $addressFreeShipping && $itemFreeShipping;
/** Parent free shipping we apply to all children*/
$this->applyToChildren($item, $itemFreeShipping);
}
return $addressFreeShipping;
}
示例4: aroundAddItem
public function aroundAddItem(\Magento\Quote\Model\Quote $subject, \Closure $proceed, \Magento\Quote\Model\Quote\Item $item)
{
$product = $item->getProduct();
$attribute = $product->getResource()->getAttribute('enable_subscription');
$value = null;
if ($attribute) {
$value = $attribute->getFrontend()->getValue($product);
}
$flag = 0;
foreach ($subject->getAllVisibleItems() as $item) {
$itemAttrValue = null;
$itemProduct = $item->getProduct();
$itemAttr = $itemProduct->getResource()->getAttribute('enable_subscription');
if ($itemAttr) {
if ($itemAttr->getFrontend()->getValue($itemProduct)) {
$flag = 1;
}
}
}
if ($value && $subject->hasItems() || $flag) {
throw new \Magento\Framework\Exception\LocalizedException(__('Nominal item can be purchased standalone only.'));
}
$proceed($item);
return $subject;
}
示例5: addQuote
/**
* Push quote contents to given tracker
*
* @param \Magento\Quote\Model\Quote $quote
* @param \Henhed\Piwik\Model\Tracker $tracker
* @return \Henhed\Piwik\Helper\Tracker
*/
public function addQuote(Quote $quote, TrackerModel $tracker)
{
foreach ($quote->getAllVisibleItems() as $item) {
$this->addQuoteItem($item, $tracker);
}
$this->addQuoteTotal($quote, $tracker);
return $this;
}
示例6: aroundCollect
/**
* If module is enabled, don't run collect totals for shipping
*
* Tax calculation for shipping is handled in this class
* @see \ClassyLlama\AvaTax\Model\Tax\Sales\Total\Quote\Tax::collect()
* Since this extension doesn't support applying discounts *after* tax, we don't need to run a separate collect
* process.
*
* @param \Magento\Tax\Model\Sales\Total\Quote\Shipping $subject
* @param \Closure $proceed
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment
* @param \Magento\Quote\Model\Quote\Address\Total $total
* @return mixed
*/
public function aroundCollect(\Magento\Tax\Model\Sales\Total\Quote\Shipping $subject, \Closure $proceed, \Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
{
$storeId = $quote->getStoreId();
// If quote is virtual, getShipping will return billing address, so no need to check if quote is virtual
$address = $shippingAssignment->getShipping()->getAddress();
if (!$this->config->isModuleEnabled($storeId) || $this->config->getTaxMode($storeId) == Config::TAX_MODE_NO_ESTIMATE_OR_SUBMIT || !$this->config->isAddressTaxable($address, $storeId)) {
return $proceed($quote, $shippingAssignment, $total);
}
}
示例7: isApplicable
/**
* Check whether payment method is applicable to quote
*
* @param PaymentMethodChecksInterface $paymentMethod
* @param \Magento\Quote\Model\Quote $quote
* @return bool
*/
public function isApplicable(PaymentMethodChecksInterface $paymentMethod, Quote $quote)
{
$total = $quote->getBaseGrandTotal();
$minTotal = $paymentMethod->getConfigData(self::MIN_ORDER_TOTAL);
$maxTotal = $paymentMethod->getConfigData(self::MAX_ORDER_TOTAL);
if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) {
return false;
}
return true;
}
示例8: _getQuoteItemIdByProductId
/**
* Gets \Magento\Quote\Model\Quote\Item from \Magento\Quote\Model\Quote by product id
*
* @param \Magento\Quote\Model\Quote $quote
* @param mixed $productId
* @return \Magento\Quote\Model\Quote\Item|null
*/
private function _getQuoteItemIdByProductId(\Magento\Quote\Model\Quote $quote, $productId)
{
/** @var $quoteItems \Magento\Quote\Model\Quote\Item[] */
$quoteItems = $quote->getAllItems();
foreach ($quoteItems as $quoteItem) {
if ($productId == $quoteItem->getProductId()) {
return $quoteItem;
}
}
return null;
}
示例9: processShippingAssignment
/**
* @param \Magento\Quote\Model\Quote $quote
* @return void
* @throws InputException
*/
private function processShippingAssignment($quote)
{
// Shipping Assignments processing
$extensionAttributes = $quote->getExtensionAttributes();
if (!$quote->isVirtual() && $extensionAttributes && $extensionAttributes->getShippingAssignments()) {
$shippingAssignments = $extensionAttributes->getShippingAssignments();
if (count($shippingAssignments) > 1) {
throw new InputException(__("Only 1 shipping assignment can be set"));
}
$this->shippingAssignmentPersister->save($quote, $shippingAssignments[0]);
}
}
示例10: fetch
/**
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Quote\Model\Quote\Address\Total $total
* @return array
*/
public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
{
$enabled = $this->helperData->isModuleEnabled();
$minimumOrderAmount = $this->helperData->getMinimumOrderAmount();
$subtotal = $quote->getSubtotal();
$fee = $quote->getFee();
if ($enabled && $minimumOrderAmount <= $subtotal && $fee) {
return ['code' => 'fee', 'title' => 'Custom Fee', 'value' => $fee];
} else {
return array();
}
}
示例11: fetch
/**
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Quote\Model\Quote\Address\Total $total
* @return array
*/
public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
{
$enabled = $this->helperData->isModuleEnabled();
$minimumOrderAmount = $this->helperData->getMinimumOrderAmount();
$subtotal = $quote->getSubtotal();
$fee = $quote->getFee();
$result = [];
if ($enabled && $minimumOrderAmount <= $subtotal && $fee) {
$result = ['code' => 'fee', 'title' => $this->helperData->getFeeLabel(), 'value' => $fee];
}
return $result;
}
示例12: disabledQuoteAddressValidation
/**
* Make sure addresses will be saved without validation errors
*
* @param Quote $quote
* @return void
*/
protected function disabledQuoteAddressValidation(Quote $quote)
{
$billingAddress = $quote->getBillingAddress();
$billingAddress->setShouldIgnoreValidation(true);
if (!$quote->getIsVirtual()) {
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setShouldIgnoreValidation(true);
if (!$billingAddress->getEmail()) {
$billingAddress->setSameAsBilling(1);
}
}
}
示例13: init
/**
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Framework\DataObject $config
* @return \Magento\Quote\Model\Quote\Item|string
*/
public function init(\Magento\Quote\Model\Quote $quote, \Magento\Catalog\Model\Product $product, \Magento\Framework\DataObject $config)
{
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $quote->getStore()->getWebsiteId());
if ($stockItem->getIsQtyDecimal()) {
$product->setIsQtyDecimal(1);
} else {
$config->setQty((int) $config->getQty());
}
$product->setCartQty($config->getQty());
$item = $quote->addProduct($product, $config, \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL);
return $item;
}
示例14: getAvailableMethods
/**
* @param \Magento\Quote\Model\Quote $quote
* @return \Magento\Payment\Model\MethodInterface[]
*/
public function getAvailableMethods(\Magento\Quote\Model\Quote $quote = null)
{
$store = $quote ? $quote->getStoreId() : null;
$methods = [];
$specification = $this->methodSpecificationFactory->create([AbstractMethod::CHECK_ZERO_TOTAL]);
foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
if ($this->_canUseMethod($method, $quote) && $specification->isApplicable($method, $quote)) {
$method->setInfoInstance($quote->getPayment());
$methods[] = $method;
}
}
return $methods;
}
示例15: prepare
public function prepare()
{
$this->contextMock = $this->getMock('Magento\\Framework\\View\\Element\\Template\\Context', [], [], '', false);
$this->checkoutSessionMock = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
$this->orderFactoryMock = $this->getMock('Magento\\Sales\\Model\\OrderFactory', ['getQuote'], [], '', false);
$this->hssHelperMock = $this->getMock('Magento\\Paypal\\Helper\\Hss', [], [], '', false);
$this->paymentDataMock = $this->getMock('Magento\\Payment\\Helper\\Data', [], [], '', false);
$this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getPayment', '__wakeup'], [], '', false);
$this->paymentMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Payment', [], [], '', false);
$this->checkoutSessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($this->quoteMock));
$this->quoteMock->expects($this->any())->method('getPayment')->will($this->returnValue($this->paymentMock));
$this->hssHelperMock->expects($this->any())->method('getHssMethods')->will($this->returnValue([]));
}