本文整理汇总了PHP中Magento\CatalogInventory\Api\StockConfigurationInterface类的典型用法代码示例。如果您正苦于以下问题:PHP StockConfigurationInterface类的具体用法?PHP StockConfigurationInterface怎么用?PHP StockConfigurationInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StockConfigurationInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Return creditmemo items qty to stock
*
* @param EventObserver $observer
* @return void
*/
public function execute(EventObserver $observer)
{
/* @var $creditmemo \Magento\Sales\Model\Order\Creditmemo */
$creditmemo = $observer->getEvent()->getCreditmemo();
$itemsToUpdate = [];
foreach ($creditmemo->getAllItems() as $item) {
$qty = $item->getQty();
if ($item->getBackToStock() && $qty || $this->stockConfiguration->isAutoReturnEnabled()) {
$productId = $item->getProductId();
$parentItemId = $item->getOrderItem()->getParentItemId();
/* @var $parentItem \Magento\Sales\Model\Order\Creditmemo\Item */
$parentItem = $parentItemId ? $creditmemo->getItemByOrderId($parentItemId) : false;
$qty = $parentItem ? $parentItem->getQty() * $qty : $qty;
if (isset($itemsToUpdate[$productId])) {
$itemsToUpdate[$productId] += $qty;
} else {
$itemsToUpdate[$productId] = $qty;
}
}
}
if (!empty($itemsToUpdate)) {
$this->stockManagement->revertProductsSale($itemsToUpdate, $creditmemo->getStore()->getWebsiteId());
$updatedItemIds = array_keys($itemsToUpdate);
$this->stockIndexerProcessor->reindexList($updatedItemIds);
$this->priceIndexer->reindexList($updatedItemIds);
}
}
示例2: loadInventoryData
/**
* Load inventory data for a list of product ids and a given store.
*
* @param integer $storeId Store id.
* @param array $productIds Product ids list.
*
* @return array
*/
public function loadInventoryData($storeId, $productIds)
{
$websiteId = $this->getWebsiteId($storeId);
$stockId = $this->getStockId($websiteId);
$select = $this->getConnection()->select()->from(['ciss' => $this->getTable('cataloginventory_stock_status')], ['product_id', 'stock_status', 'qty'])->where('ciss.stock_id = ?', $stockId)->where('ciss.website_id = ?', $this->stockConfiguration->getDefaultScopeId())->where('ciss.product_id IN(?)', $productIds);
return $this->getConnection()->fetchAll($select);
}
示例3: aroundRegisterProductsSale
/**
* Update stock item on the stock and distribute qty by lots.
*
* @param \Magento\CatalogInventory\Model\StockManagement $subject
* @param \Closure $proceed
* @param array $items
* @param int $websiteId is not used
* @throws \Magento\Framework\Exception\LocalizedException
* @return null
*/
public function aroundRegisterProductsSale(\Magento\CatalogInventory\Model\StockManagement $subject, \Closure $proceed, array $items, $websiteId)
{
/* This code is moved from original 'registerProductsSale' method. */
/* replace websiteId by stockId */
$stockId = $this->_manStock->getCurrentStockId();
$def = $this->_manTrans->begin();
$lockedItems = $this->_resourceStock->lockProductsStock(array_keys($items), $stockId);
$fullSaveItems = $registeredItems = [];
foreach ($lockedItems as $lockedItemRecord) {
$productId = $lockedItemRecord['product_id'];
$orderedQty = $items[$productId];
/** @var \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem */
$stockItem = $this->_providerStockRegistry->getStockItem($productId, $stockId);
$stockItemId = $stockItem->getItemId();
$canSubtractQty = $stockItemId && $this->_canSubtractQty($stockItem);
if (!$canSubtractQty || !$this->_configStock->isQty($lockedItemRecord['type_id'])) {
continue;
}
if (!$stockItem->hasAdminArea() && !$this->_stockState->checkQty($productId, $orderedQty)) {
$this->_manTrans->rollback($def);
throw new \Magento\Framework\Exception\LocalizedException(__('Not all of your products are available in the requested quantity.'));
}
if ($this->_canSubtractQty($stockItem)) {
$stockItem->setQty($stockItem->getQty() - $orderedQty);
}
$registeredItems[$productId] = $orderedQty;
if (!$this->_stockState->verifyStock($productId) || $this->_stockState->verifyNotification($productId)) {
$fullSaveItems[] = $stockItem;
}
}
$this->_resourceStock->correctItemsQty($registeredItems, $stockId, '-');
$this->_manTrans->commit($def);
return $fullSaveItems;
}
示例4: modifyData
/**
* {@inheritdoc}
*/
public function modifyData(array $data)
{
$fieldCode = 'quantity_and_stock_status';
$model = $this->locator->getProduct();
$modelId = $model->getId();
/** @var StockItemInterface $stockItem */
$stockItem = $this->stockRegistry->getStockItem($modelId, $model->getStore()->getWebsiteId());
$stockData = $modelId ? $this->getData($stockItem) : [];
if (!empty($stockData)) {
$data[$modelId][self::DATA_SOURCE_DEFAULT][self::STOCK_DATA_FIELDS] = $stockData;
}
if (isset($stockData['is_in_stock'])) {
$data[$modelId][self::DATA_SOURCE_DEFAULT][$fieldCode]['is_in_stock'] = (int) $stockData['is_in_stock'];
}
if (!empty($this->stockConfiguration->getDefaultConfigValue(StockItemInterface::MIN_SALE_QTY))) {
$minSaleQtyData = null;
$defaultConfigValue = $this->stockConfiguration->getDefaultConfigValue(StockItemInterface::MIN_SALE_QTY);
if (strpos($defaultConfigValue, 'a:') === 0) {
// Set data source for dynamicRows Minimum Qty Allowed in Shopping Cart
$minSaleQtyValue = unserialize($defaultConfigValue);
foreach ($minSaleQtyValue as $group => $qty) {
$minSaleQtyData[] = [StockItemInterface::CUSTOMER_GROUP_ID => $group, StockItemInterface::MIN_SALE_QTY => $qty];
}
} else {
$minSaleQtyData = $defaultConfigValue;
}
$path = $modelId . '/' . self::DATA_SOURCE_DEFAULT . '/stock_data/min_qty_allowed_in_shopping_cart';
$data = $this->arrayManager->set($path, $data, $minSaleQtyData);
}
return $data;
}
示例5: testAssignStatusToProduct
public function testAssignStatusToProduct()
{
$websiteId = 1;
$status = 'test';
$stockStatusMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockStatusInterface')->disableOriginalConstructor()->getMock();
$stockStatusMock->expects($this->any())->method('getStockStatus')->willReturn($status);
$this->stockRegistryProviderMock->expects($this->any())->method('getStockStatus')->willReturn($stockStatusMock);
$this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn($websiteId);
$productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['setIsSalable', 'getId'])->getMock();
$productMock->expects($this->once())->method('setIsSalable')->with($status);
$this->assertNull($this->stock->assignStatusToProduct($productMock));
}
示例6: _assignProducts
/**
* Add products to items and item options
*
* @return $this
*/
protected function _assignProducts()
{
\Magento\Framework\Profiler::start('WISHLIST:' . __METHOD__, ['group' => 'WISHLIST', 'method' => __METHOD__]);
$productIds = [];
$this->_productIds = array_merge($this->_productIds, array_keys($productIds));
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
$productCollection = $this->_productCollectionFactory->create();
if ($this->_productVisible) {
$productCollection->setVisibility($this->_productVisibility->getVisibleInSiteIds());
}
$productCollection->addPriceData()->addTaxPercents()->addIdFilter($this->_productIds)->addAttributeToSelect('*')->addOptionsToResult()->addUrlRewrite();
if ($this->_productSalable) {
$productCollection = $this->_adminhtmlSales->applySalableProductTypesFilter($productCollection);
}
$this->_eventManager->dispatch('wishlist_item_collection_products_after_load', ['product_collection' => $productCollection]);
$checkInStock = $this->_productInStock && !$this->stockConfiguration->isShowOutOfStock();
foreach ($this as $item) {
$product = $productCollection->getItemById($item->getProductId());
if ($product) {
if ($checkInStock && !$product->isInStock()) {
$this->removeItemByKey($item->getId());
} else {
$product->setCustomOptions([]);
$item->setProduct($product);
$item->setProductName($product->getName());
$item->setName($product->getName());
$item->setPrice($product->getPrice());
}
} else {
$item->isDeleted(true);
}
}
\Magento\Framework\Profiler::stop('WISHLIST:' . __METHOD__);
return $this;
}
示例7: testGenerateSimpleProducts
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGenerateSimpleProducts()
{
$productsData = [6 => ['image' => 'image.jpg', 'name' => 'config-red', 'configurable_attribute' => '{"new_attr":"6"}', 'sku' => 'config-red', 'quantity_and_stock_status' => ['qty' => ''], 'weight' => '333']];
$stockData = ['manage_stock' => '0', 'use_config_enable_qty_increments' => '1', 'use_config_qty_increments' => '1', 'use_config_manage_stock' => 0, 'is_decimal_divided' => 0];
$parentProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getNewVariationsAttributeSetId', 'getStockData', 'getQuantityAndStockStatus', 'getWebsiteIds'])->disableOriginalConstructor()->getMock();
$newSimpleProductMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'save', 'getId', 'setStoreId', 'setTypeId', 'setAttributeSetId', 'getTypeInstance', 'getStoreId', 'addData', 'setWebsiteIds', 'setStatus', 'setVisibility'])->disableOriginalConstructor()->getMock();
$productTypeMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type')->setMethods(['getSetAttributes'])->disableOriginalConstructor()->getMock();
$editableAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->setMethods(['getIsUnique', 'getAttributeCode', 'getFrontend', 'getIsVisible'])->disableOriginalConstructor()->getMock();
$frontendAttributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend')->setMethods(['getInputType'])->disableOriginalConstructor()->getMock();
$parentProductMock->expects($this->once())->method('getNewVariationsAttributeSetId')->willReturn('new_attr_set_id');
$this->productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
$newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('setAttributeSetId')->with('new_attr_set_id')->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('getTypeInstance')->willReturn($productTypeMock);
$productTypeMock->expects($this->once())->method('getSetAttributes')->with($newSimpleProductMock)->willReturn([$editableAttributeMock]);
$editableAttributeMock->expects($this->once())->method('getIsUnique')->willReturn(false);
$editableAttributeMock->expects($this->once())->method('getAttributeCode')->willReturn('some_code');
$editableAttributeMock->expects($this->any())->method('getFrontend')->willReturn($frontendAttributeMock);
$frontendAttributeMock->expects($this->any())->method('getInputType')->willReturn('input_type');
$editableAttributeMock->expects($this->any())->method('getIsVisible')->willReturn(false);
$parentProductMock->expects($this->once())->method('getStockData')->willReturn($stockData);
$parentProductMock->expects($this->once())->method('getQuantityAndStockStatus')->willReturn(['is_in_stock' => 1]);
$newSimpleProductMock->expects($this->once())->method('getStoreId')->willReturn('store_id');
$this->stockConfiguration->expects($this->once())->method('getManageStock')->with('store_id')->willReturn(1);
$newSimpleProductMock->expects($this->once())->method('addData')->willReturnSelf();
$parentProductMock->expects($this->once())->method('getWebsiteIds')->willReturn('website_id');
$newSimpleProductMock->expects($this->once())->method('setWebsiteIds')->with('website_id')->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('setVisibility')->with(1)->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('save')->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('getId')->willReturn('product_id');
$this->assertEquals(['product_id'], $this->model->generateSimpleProducts($parentProductMock, $productsData));
}
示例8: testGetDefaultConfigValue
/**
* Run test getDefaultConfigValue method
*
* @return void
*/
public function testGetDefaultConfigValue()
{
$field = 'filed-name';
$this->stockConfigurationMock->expects($this->once())->method('getDefaultConfigValue')->will($this->returnValue('return-value'));
$result = $this->inventory->getDefaultConfigValue($field);
$this->assertEquals('return-value', $result);
}
示例9: useNotifyStockQtyFilter
/**
* Add Notify Stock Qty Condition to collection
*
* @param null|int $storeId
* @return $this
*/
public function useNotifyStockQtyFilter($storeId = null)
{
$this->joinInventoryItem(['qty']);
$notifyStockExpr = $this->getConnection()->getCheckSql($this->_getInventoryItemField('use_config_notify_stock_qty') . ' = 1', (int) $this->stockConfiguration->getNotifyStockQty($storeId), $this->_getInventoryItemField('notify_stock_qty'));
$this->getSelect()->where($this->_getInventoryItemField('qty') . ' < ?', $notifyStockExpr);
return $this;
}
示例10: getProductStockStatusBySku
/**
* @param string $productSku
* @param null $websiteId
* @return int
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getProductStockStatusBySku($productSku, $websiteId = null)
{
//if (!$websiteId) {
$websiteId = $this->stockConfiguration->getDefaultWebsiteId();
//}
$productId = $this->resolveProductId($productSku);
return $this->getProductStockStatus($productId, $websiteId);
}
示例11: checkQuoteItemQty
/**
* @param int $productId
* @param float $itemQty
* @param float $qtyToCheck
* @param float $origQty
* @param int $scopeId
* @return int
*/
public function checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $scopeId = null)
{
if ($scopeId === null) {
$scopeId = $this->stockConfiguration->getDefaultScopeId();
}
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
return $this->stockStateProvider->checkQuoteItemQty($stockItem, $itemQty, $qtyToCheck, $origQty);
}
示例12: testReindexEntity
/**
* @magentoDataFixture Magento/Store/_files/website.php
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function testReindexEntity()
{
/** @var \Magento\Catalog\Model\ProductRepository $productRepository */
$productRepository = $this->getObject(\Magento\Catalog\Model\ProductRepository::class);
/** @var \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository */
$websiteRepository = $this->getObject(\Magento\Store\Api\WebsiteRepositoryInterface::class);
$product = $productRepository->get('simple');
$testWebsite = $websiteRepository->get('test');
$product->setWebsiteIds([1, $testWebsite->getId()])->save();
/** @var \Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory $criteriaFactory */
$criteriaFactory = $this->getObject(\Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory::class);
/** @var \Magento\CatalogInventory\Api\StockStatusRepositoryInterface $stockStatusRepository */
$stockStatusRepository = $this->getObject(\Magento\CatalogInventory\Api\StockStatusRepositoryInterface::class);
$criteria = $criteriaFactory->create();
$criteria->setProductsFilter([$product->getId()]);
$criteria->addFilter('website', 'website_id', $this->stockConfiguration->getDefaultScopeId());
$items = $stockStatusRepository->getList($criteria)->getItems();
$this->assertEquals($product->getId(), $items[$product->getId()]->getProductId());
}
示例13: testSetMinQty
/**
* @param bool $useConfigMinQty
* @param float $minQty
* @dataProvider setMinQtyDataProvider
*/
public function testSetMinQty($useConfigMinQty, $minQty)
{
$this->setDataArrayValue('use_config_min_qty', $useConfigMinQty);
if ($useConfigMinQty) {
$this->stockConfiguration->expects($this->any())->method('getMinQty')->will($this->returnValue($minQty));
} else {
$this->setDataArrayValue('min_qty', $minQty);
}
$this->assertSame($minQty, $this->item->getMinQty());
}
示例14: filter
/**
* Filter stock data
*
* @param array $stockData
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function filter(array $stockData)
{
if (!isset($stockData['use_config_manage_stock'])) {
$stockData['use_config_manage_stock'] = 0;
}
if ($stockData['use_config_manage_stock'] == 1 && !isset($stockData['manage_stock'])) {
$stockData['manage_stock'] = $this->stockConfiguration->getManageStock();
}
if (isset($stockData['qty']) && (double) $stockData['qty'] > self::MAX_QTY_VALUE) {
$stockData['qty'] = self::MAX_QTY_VALUE;
}
if (isset($stockData['min_qty']) && (int) $stockData['min_qty'] < 0) {
$stockData['min_qty'] = 0;
}
if (!isset($stockData['is_decimal_divided']) || $stockData['is_qty_decimal'] == 0) {
$stockData['is_decimal_divided'] = 0;
}
return $stockData;
}
示例15: _initConfig
/**
* Load some inventory configuration settings
*
* @return void
*/
protected function _initConfig()
{
if (!$this->_isConfig) {
$configMap = ['_isConfigManageStock' => \Magento\CatalogInventory\Model\Configuration::XML_PATH_MANAGE_STOCK, '_isConfigBackorders' => \Magento\CatalogInventory\Model\Configuration::XML_PATH_BACKORDERS, '_configMinQty' => \Magento\CatalogInventory\Model\Configuration::XML_PATH_MIN_QTY, '_configNotifyStockQty' => \Magento\CatalogInventory\Model\Configuration::XML_PATH_NOTIFY_STOCK_QTY];
foreach ($configMap as $field => $const) {
$this->{$field} = (int) $this->_scopeConfig->getValue($const, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
$this->_isConfig = true;
$this->_configTypeIds = array_keys($this->stockConfiguration->getIsQtyTypeIds(true));
}
}