当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::getSku方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product::getSku方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getSku方法的具体用法?PHP Product::getSku怎么用?PHP Product::getSku使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::getSku方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepareProducts

 /**
  * @return array
  */
 protected function prepareProducts($price)
 {
     $this->product->load(1);
     $productSecond = clone $this->product;
     $productSecond->setId(null)->setUrlKey(null)->setSku(uniqid($this->product->getSku() . '-'))->setName(uniqid($this->product->getName() . '-'))->setWebsiteIds([1]);
     $productSecond->save();
     $productSecond->setPrice($price)->save();
     $productThird = clone $this->product;
     $productThird->setId(null)->setUrlKey(null)->setSku(uniqid($this->product->getSku() . '-'))->setName(uniqid($this->product->getName() . '-'))->setWebsiteIds([1])->save();
     $productThird->setPrice($price)->save();
     return [$productSecond->getId(), $productThird->getId()];
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:BatchIndexTest.php

示例2: testDuplicateSkuGeneration

 /**
  * @magentoAppArea adminhtml
  */
 public function testDuplicateSkuGeneration()
 {
     $this->_model->load(1);
     $this->assertEquals('simple', $this->_model->getSku());
     /** @var \Magento\Catalog\Model\Product\Copier $copier */
     $copier = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\Product\\Copier');
     $duplicate = $copier->copy($this->_model);
     $this->assertEquals('simple-3', $duplicate->getSku());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:ProductTest.php

示例3: assertProductInfo

 /**
  * @param \Magento\Catalog\Model\Product $product
  */
 private function assertProductInfo($product)
 {
     $data = [1 => ['sku' => 'simple', 'name' => 'Simple Product', 'price' => '10', 'qty' => '1', 'position' => '1'], 21 => ['sku' => 'virtual-product', 'name' => 'Virtual Product', 'price' => '10', 'qty' => '2', 'position' => '2']];
     $productId = $product->getId();
     $this->assertEquals($data[$productId]['sku'], $product->getSku());
     $this->assertEquals($data[$productId]['name'], $product->getName());
     $this->assertEquals($data[$productId]['price'], $product->getPrice());
     $this->assertEquals($data[$productId]['qty'], $product->getQty());
     $this->assertEquals($data[$productId]['position'], $product->getPosition());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:GroupedTest.php

示例4: getProductPage

 /**
  * Load specific layout handles by product type id
  *
  * @param CatalogProduct $product
  * @return \Magento\Framework\View\Result\Page
  */
 protected function getProductPage($product)
 {
     /** @var \Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
     if ($product->getPageLayout()) {
         $resultPage->getConfig()->setPageLayout($product->getPageLayout());
     }
     $urlSafeSku = rawurlencode($product->getSku());
     $resultPage->addPageLayoutHandles(['id' => $product->getId(), 'sku' => $urlSafeSku, 'type' => $product->getTypeId()]);
     $resultPage->addUpdate($product->getCustomLayoutUpdate());
     return $resultPage;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:ListAction.php

示例5: validate

 /**
  * Validate SKU
  *
  * @param Product $object
  * @return bool
  * @throws \Magento\Framework\Exception\LocalizedException
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function validate($object)
 {
     $attrCode = $this->getAttribute()->getAttributeCode();
     $value = $object->getData($attrCode);
     if ($this->getAttribute()->getIsRequired() && strlen($value) === 0) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be set', $attrCode));
     }
     if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {
         throw new \Magento\Framework\Exception\LocalizedException(__('SKU length should be %1 characters maximum.', self::SKU_MAX_LENGTH));
     }
     return true;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:20,代码来源:Sku.php

示例6: testProductsUpdate

 /**
  * @magentoDbIsolation disabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Catalog/_files/price_row_fixture.php
  */
 public function testProductsUpdate()
 {
     /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\Product');
     /** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $linkManagment */
     $linkManagment = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Api\\CategoryLinkManagementInterface');
     $this->_product = $product->load(1);
     $linkManagment->assignProductToCategories($this->_product->getSku(), [9]);
     $this->_processor->reindexList([$this->_product->getId()]);
     $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory');
     $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Block\\Product\\ListProduct');
     $category = $categoryFactory->create()->load(9);
     $layer = $listProduct->getLayer();
     $layer->setCurrentCategory($category);
     $productCollection = $layer->getProductCollection();
     $this->assertEquals(1, $productCollection->count());
     /** @var $product \Magento\Catalog\Model\Product */
     foreach ($productCollection as $product) {
         $this->assertEquals($this->_product->getId(), $product->getId());
         $this->assertEquals($this->_product->getPrice(), $product->getPrice());
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:27,代码来源:RowsTest.php

示例7: _initProductLayout

 /**
  * Load specific layout handles by product type id
  *
  * @param CatalogProduct $product
  * @return void
  */
 protected function _initProductLayout($product)
 {
     $this->_view->getPage()->initLayout();
     if ($product->getPageLayout()) {
         /** @var \Magento\Framework\View\Page\Config $pageConfig */
         $pageConfig = $this->_objectManager->get('Magento\\Framework\\View\\Page\\Config');
         $pageConfig->setPageLayout($product->getPageLayout());
     }
     $update = $this->_view->getLayout()->getUpdate();
     $this->_view->addPageLayoutHandles(array('id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()));
     $this->_view->loadLayoutUpdates();
     $update->addUpdate($product->getCustomLayoutUpdate());
     $this->_view->generateLayoutXml();
     $this->_view->generateLayoutBlocks();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:ListAction.php

示例8: _initProductLayout

 /**
  * Load specific layout handles by product type id
  *
  * @param CatalogProduct $product
  * @return void
  */
 protected function _initProductLayout($product)
 {
     $update = $this->_view->getLayout()->getUpdate();
     $update->addHandle('default');
     $this->_view->addPageLayoutHandles(array('id' => $product->getId(), 'sku' => $product->getSku(), 'type' => $product->getTypeId()));
     if ($product->getPageLayout()) {
         $this->_objectManager->get('Magento\\Theme\\Helper\\Layout')->applyHandle($product->getPageLayout());
     }
     $this->_view->loadLayoutUpdates();
     if ($product->getPageLayout()) {
         $this->_objectManager->get('Magento\\Theme\\Helper\\Layout')->applyTemplate($product->getPageLayout());
     }
     $update->addUpdate($product->getCustomLayoutUpdate());
     $this->_view->generateLayoutXml();
     $this->_view->generateLayoutBlocks();
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:22,代码来源:ListAction.php

示例9: beforeInitializeLinks

 /**
  * Initialize grouped product links
  *
  * @param \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $subject
  * @param \Magento\Catalog\Model\Product $product
  * @param array $links
  *
  * @return \Magento\Catalog\Model\Product
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function beforeInitializeLinks(\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $subject, \Magento\Catalog\Model\Product $product, array $links)
 {
     if ($product->getTypeId() === TypeGrouped::TYPE_CODE && !$product->getGroupedReadonly()) {
         $links = isset($links[self::TYPE_NAME]) ? $links[self::TYPE_NAME] : $product->getGroupedLinkData();
         if (!is_array($links)) {
             $links = [];
         }
         if ($product->getGroupedLinkData()) {
             $links = array_merge($links, $product->getGroupedLinkData());
         }
         $newLinks = [];
         $existingLinks = $product->getProductLinks();
         foreach ($links as $linkRaw) {
             /** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
             $productLink = $this->productLinkFactory->create();
             if (!isset($linkRaw['id'])) {
                 continue;
             }
             $productId = $linkRaw['id'];
             if (!isset($linkRaw['qty'])) {
                 $linkRaw['qty'] = 0;
             }
             $linkedProduct = $this->productRepository->getById($productId);
             $productLink->setSku($product->getSku())->setLinkType(self::TYPE_NAME)->setLinkedProductSku($linkedProduct->getSku())->setLinkedProductType($linkedProduct->getTypeId())->setPosition($linkRaw['position'])->getExtensionAttributes()->setQty($linkRaw['qty']);
             if (isset($linkRaw['custom_attributes'])) {
                 $productLinkExtension = $productLink->getExtensionAttributes();
                 if ($productLinkExtension === null) {
                     $productLinkExtension = $this->productLinkExtensionFactory->create();
                 }
                 foreach ($linkRaw['custom_attributes'] as $option) {
                     $name = $option['attribute_code'];
                     $value = $option['value'];
                     $setterName = 'set' . ucfirst($name);
                     // Check if setter exists
                     if (method_exists($productLinkExtension, $setterName)) {
                         call_user_func([$productLinkExtension, $setterName], $value);
                     }
                 }
                 $productLink->setExtensionAttributes($productLinkExtension);
             }
             $newLinks[] = $productLink;
         }
         $existingLinks = $this->removeUnExistingLinks($existingLinks, $newLinks);
         $product->setProductLinks(array_merge($existingLinks, $newLinks));
     }
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:58,代码来源:Grouped.php

示例10: prepareOptions

 /**
  * @param array $options
  * @param \Magento\Catalog\Model\Product $product
  * @return \Magento\Catalog\Api\Data\ProductCustomOptionInterface[]
  */
 protected function prepareOptions($options, $product)
 {
     $preparedOptions = [];
     if (!$this->customOptionFactory) {
         $this->customOptionFactory = $this->objectManager->create('Magento\\Catalog\\Api\\Data\\ProductCustomOptionInterfaceFactory');
     }
     foreach ($options as $option) {
         $option = $this->customOptionFactory->create(['data' => $option]);
         $option->setProductSku($product->getSku());
         $preparedOptions[] = $option;
     }
     return $preparedOptions;
 }
开发者ID:dragonsword007008,项目名称:magento2,代码行数:18,代码来源:PriceTest.php

示例11: processDynamicOptionsData

 /**
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 protected function processDynamicOptionsData(\Magento\Catalog\Model\Product $product)
 {
     if ((int) $product->getPriceType() !== \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
         return;
     }
     if ($product->getOptionsReadonly()) {
         return;
     }
     $product->setCanSaveCustomOptions(true);
     $customOptions = $product->getProductOptions();
     if (!$customOptions) {
         return;
     }
     foreach (array_keys($customOptions) as $key) {
         $customOptions[$key]['is_delete'] = 1;
     }
     $newOptions = $product->getOptions();
     foreach ($customOptions as $customOptionData) {
         if ((bool) $customOptionData['is_delete']) {
             continue;
         }
         $customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
         $customOption->setProductSku($product->getSku());
         $customOption->setOptionId(null);
         $newOptions[] = $customOption;
     }
     $product->setOptions($newOptions);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:32,代码来源:Bundle.php

示例12: createDataFromModel

 /**
  * @param OptionModel $option
  * @param Product $product
  * @return Option
  */
 public function createDataFromModel(OptionModel $option, Product $product)
 {
     $this->builder->populateWithArray($option->getData())->setId($option->getId())->setTitle(is_null($option->getTitle()) ? $option->getDefaultTitle() : $option->getTitle())->setSku($product->getSku());
     return $this->builder->create();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:10,代码来源:OptionConverter.php

示例13: getTaxPrice

 /**
  * Get product price with all tax settings processing
  *
  * @param   \Magento\Catalog\Model\Product $product
  * @param   float $price inputted product price
  * @param   bool $includingTax return price include tax flag
  * @param   null|\Magento\Customer\Model\Address\AbstractAddress $shippingAddress
  * @param   null|\Magento\Customer\Model\Address\AbstractAddress $billingAddress
  * @param   null|int $ctc customer tax class
  * @param   null|string|bool|int|\Magento\Store\Model\Store $store
  * @param   bool $priceIncludesTax flag what price parameter contain tax
  * @param   bool $roundPrice
  * @return  float
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getTaxPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true)
 {
     if (!$price) {
         return $price;
     }
     $store = $this->_storeManager->getStore($store);
     if ($this->_taxConfig->needPriceConversion($store)) {
         if ($priceIncludesTax === null) {
             $priceIncludesTax = $this->_taxConfig->priceIncludesTax($store);
         }
         $shippingAddressDataObject = null;
         if ($shippingAddress === null) {
             $shippingAddressDataObject = $this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxShippingAddress());
         } elseif ($shippingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
             $shippingAddressDataObject = $shippingAddress->getDataModel();
         }
         $billingAddressDataObject = null;
         if ($billingAddress === null) {
             $billingAddressDataObject = $this->convertDefaultTaxAddress($this->_customerSession->getDefaultTaxBillingAddress());
         } elseif ($billingAddress instanceof \Magento\Customer\Model\Address\AbstractAddress) {
             $billingAddressDataObject = $billingAddress->getDataModel();
         }
         $taxClassKey = $this->_taxClassKeyFactory->create();
         $taxClassKey->setType(TaxClassKeyInterface::TYPE_ID)->setValue($product->getTaxClassId());
         if ($ctc === null && $this->_customerSession->getCustomerGroupId() != null) {
             $ctc = $this->customerGroupRepository->getById($this->_customerSession->getCustomerGroupId())->getTaxClassId();
         }
         $customerTaxClassKey = $this->_taxClassKeyFactory->create();
         $customerTaxClassKey->setType(TaxClassKeyInterface::TYPE_ID)->setValue($ctc);
         $item = $this->_quoteDetailsItemFactory->create();
         $item->setQuantity(1)->setCode($product->getSku())->setShortDescription($product->getShortDescription())->setTaxClassKey($taxClassKey)->setIsTaxIncluded($priceIncludesTax)->setType('product')->setUnitPrice($price);
         $quoteDetails = $this->_quoteDetailsFactory->create();
         $quoteDetails->setShippingAddress($shippingAddressDataObject)->setBillingAddress($billingAddressDataObject)->setCustomerTaxClassKey($customerTaxClassKey)->setItems([$item])->setCustomerId($this->_customerSession->getCustomerId());
         $storeId = null;
         if ($store) {
             $storeId = $store->getId();
         }
         $taxDetails = $this->_taxCalculationService->calculateTax($quoteDetails, $storeId, $roundPrice);
         $items = $taxDetails->getItems();
         $taxDetailsItem = array_shift($items);
         if ($includingTax !== null) {
             if ($includingTax) {
                 $price = $taxDetailsItem->getPriceInclTax();
             } else {
                 $price = $taxDetailsItem->getPrice();
             }
         } else {
             switch ($this->_taxConfig->getPriceDisplayType($store)) {
                 case Config::DISPLAY_TYPE_EXCLUDING_TAX:
                 case Config::DISPLAY_TYPE_BOTH:
                     $price = $taxDetailsItem->getPrice();
                     break;
                 case Config::DISPLAY_TYPE_INCLUDING_TAX:
                     $price = $taxDetailsItem->getPriceInclTax();
                     break;
                 default:
                     break;
             }
         }
     }
     if ($roundPrice) {
         return $this->priceCurrency->round($price);
     } else {
         return $price;
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:83,代码来源:Data.php

示例14: convert

 /**
  * {@inheritdoc}
  */
 public function convert(\Magento\Catalog\Model\Product $product)
 {
     return [ProductLink::TYPE => $product->getTypeId(), ProductLink::SKU => $product->getSku(), ProductLink::POSITION => $product->getPosition()];
 }
开发者ID:aiesh,项目名称:magento2,代码行数:7,代码来源:DefaultConverter.php

示例15: storeImage

 /**
  * Save image information to DB.
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $images
  * @return void
  */
 protected function storeImage($product, $images)
 {
     $baseImage = '';
     $i = 1;
     $mediaAttribute = $this->eavConfig->getAttribute('catalog_product', 'media_gallery');
     foreach ($images as $image) {
         if (empty($image)) {
             $this->errors[] = $product->getSku();
             continue;
         }
         if (strpos($image, '_main') !== false) {
             $baseImage = $image;
         }
         $id = $this->galleryResource->insertGallery(['attribute_id' => $mediaAttribute->getAttributeId(), 'entity_id' => $product->getId(), 'value' => $image]);
         $this->galleryResource->insertGalleryValueInStore(['value_id' => $id, 'store_id' => \Magento\Store\Model\Store::DEFAULT_STORE_ID, 'entity_id' => $product->getId(), 'label' => 'Image', 'position' => $i, 'disables' => 0]);
         $this->galleryResource->bindValueToEntity($id, $product->getId());
         $i++;
     }
     if (empty($baseImage)) {
         $baseImage = $images[0];
     }
     if ($baseImage) {
         $imageAttribute = $product->getResource()->getAttribute('image');
         $smallImageAttribute = $product->getResource()->getAttribute('small_image');
         $thumbnailAttribute = $product->getResource()->getAttribute('thumbnail');
         $adapter = $product->getResource()->getConnection();
         foreach ([$imageAttribute, $smallImageAttribute, $thumbnailAttribute] as $attribute) {
             $table = $imageAttribute->getBackend()->getTable();
             /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter*/
             $data = [$attribute->getBackend()->getEntityIdField() => $product->getId(), 'attribute_id' => $attribute->getId(), 'value' => $baseImage];
             $adapter->insertOnDuplicate($table, $data, ['value']);
         }
     }
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:41,代码来源:Gallery.php


注:本文中的Magento\Catalog\Model\Product::getSku方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。