コード例 #1
0
ファイル: Helper.php プロジェクト: ktplKunj/TestMagento
 /**
  * @param string $email
  * @return bool|\Magento\Customer\Model\Customer
  */
 public function getCustomerByEmail($email)
 {
     /** @var \Magento\Customer\Model\Customer $customer */
     $customer = $this->customerFactory->create();
     $customer->setWebsiteId($this->storeManager->getWebsiteId());
     $customer->loadByEmail($email);
     if ($customer->getId()) {
         return $customer;
     }
     return false;
 }
コード例 #2
0
 /**
  * @return array
  */
 protected function getDefaultCustomerProfile()
 {
     if (!$this->customerDataProfile) {
         $this->customerDataProfile = ['website_id' => $this->storeManager->getWebsiteId(), 'group_id' => $this->storeManager->getGroupId(), 'disable_auto_group_change' => '0', 'prefix', 'firstname' => '', 'middlename' => '', 'lastname' => '', 'suffix' => '', 'email' => '', 'dob' => '', 'taxvat' => '', 'gender' => '', 'confirmation' => false, 'sendemail' => false];
     }
     return $this->customerDataProfile;
 }
コード例 #3
0
ファイル: Product.php プロジェクト: ktplKunj/TestMagento
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log("Installing {$this->productType} products:");
     $product = $this->productFactory->create();
     foreach ($this->fixtures as $file) {
         /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             $attributeSetId = $this->catalogConfig->getAttributeSetId(4, $row['attribute_set']);
             $this->converter->setAttributeSetId($attributeSetId);
             $data = $this->converter->convertRow($row);
             $product->unsetData();
             $product->setData($data);
             $product->setTypeId($this->productType)->setAttributeSetId($attributeSetId)->setWebsiteIds([$this->storeManager->getWebsiteId()])->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setStockData(['is_in_stock' => 1, 'manage_stock' => 0])->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
             if (empty($data['visibility'])) {
                 $product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
             }
             $this->prepareProduct($product, $data);
             $product->save();
             $this->gallery->install($product);
             $this->logger->logInline('.');
         }
     }
 }
コード例 #4
0
ファイル: Review.php プロジェクト: ktplKunj/TestMagento
 /**
  * @param array $row
  * @return \Magento\Review\Model\Review
  */
 protected function prepareReview($row)
 {
     /** @var $review \Magento\Review\Model\Review */
     $review = $this->reviewFactory->create();
     $review->setEntityId($review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE))->setEntityPkValue($this->getProductIdBySku($row['sku']))->setNickname($row['reviewer'])->setTitle($row['title'])->setDetail($row['review'])->setStatusId(\Magento\Review\Model\Review::STATUS_APPROVED)->setStoreId($this->storeManager->getStoreId())->setStores([$this->storeManager->getStoreId()]);
     return $review;
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Tablerate:');
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */
     $connection = $this->resource->getConnection('core');
     $fixtureFile = 'OfflineShipping/tablerate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     $regions = $this->loadDirectoryRegions();
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0;
         try {
             $connection->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsiteId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]);
         } catch (\Zend_Db_Statement_Exception $e) {
             if ($e->getCode() == self::ERROR_CODE_DUPLICATE_ENTRY) {
                 // In case if Sample data was already installed we just skip duplicated records installation
                 continue;
             } else {
                 throw $e;
             }
         }
         $this->logger->logInline('.');
     }
     $this->configWriter->save('carriers/tablerate/active', 1);
     $this->configWriter->save('carriers/tablerate/condition_name', 'package_value');
     $this->cacheTypeList->cleanType('config');
 }
コード例 #6
0
 /**
  * @param array $giftRegistryData
  * @return array
  */
 protected function generateData(array $giftRegistryData)
 {
     $giftRegistryData['sku'] = explode("\n", $giftRegistryData['sku']);
     $customer = $this->customerFactory->create();
     $customer->setWebsiteId($this->storeManager->getWebsiteId())->loadByEmail($giftRegistryData['customer_email']);
     $address = $customer->getDefaultBillingAddress()->getData();
     return ['customer_id' => $customer->getId(), 'type_id' => 1, 'title' => $giftRegistryData['title'], 'message' => $giftRegistryData['message'], 'is_public' => 1, 'is_active' => 1, 'event_country' => $address['country_id'], 'event_country_region' => $address['region_id'], 'event_country_region_text' => '', 'event_date' => date('Y-m-d'), 'address' => ['firstname' => $address['firstname'], 'lastname' => $address['lastname'], 'company' => '', 'street' => $address['street'], 'city' => $address['city'], 'region_id' => $address['region_id'], 'region' => $address['region'], 'postcode' => $address['postcode'], 'country_id' => $address['country_id'], 'telephone' => $address['telephone'], 'fax' => ''], 'items' => $this->productSkuToId($giftRegistryData['sku'])];
 }
コード例 #7
0
ファイル: Category.php プロジェクト: ktplKunj/TestMagento
 /**
  * Get category tree
  *
  * @param int|null $rootNode
  * @param bool $reload
  * @return \Magento\Framework\Data\Tree\Node
  */
 protected function getTree($rootNode = null, $reload = false)
 {
     if (!$this->categoryTree || $reload) {
         if ($rootNode === null) {
             $rootNode = $this->storeManager->getStore()->getRootCategoryId();
         }
         $tree = $this->resourceCategoryTreeFactory->create();
         $node = $tree->loadNode($rootNode)->loadChildren();
         $tree->addCollectionData(null, false, $rootNode);
         $this->categoryTree = $node;
     }
     return $this->categoryTree;
 }
コード例 #8
0
ファイル: Attribute.php プロジェクト: ktplKunj/TestMagento
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing catalog attributes:');
     $attributeCount = 0;
     foreach ($this->moduleList->getNames() as $moduleName) {
         $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/attributes.csv';
         $fileName = $this->fixtureHelper->getPath($fileName);
         if (!$fileName) {
             continue;
         }
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $data) {
             $data['attribute_set'] = explode("\n", $data['attribute_set']);
             /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attribute */
             $attribute = $this->eavConfig->getAttribute('catalog_product', $data['attribute_code']);
             if (!$attribute) {
                 $attribute = $this->attributeFactory->create();
             }
             $frontendLabel = explode("\n", $data['frontend_label']);
             if (count($frontendLabel) > 1) {
                 $data['frontend_label'] = [];
                 $data['frontend_label'][\Magento\Store\Model\Store::DEFAULT_STORE_ID] = $frontendLabel[0];
                 $data['frontend_label'][$this->storeManager->getStoreId()] = $frontendLabel[1];
             }
             $data['option'] = $this->getOption($attribute, $data);
             $data['source_model'] = $this->productHelper->getAttributeSourceModelByInputType($data['frontend_input']);
             $data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType($data['frontend_input']);
             $data += ['is_filterable' => 0, 'is_filterable_in_search' => 0, 'apply_to' => []];
             $data['backend_type'] = $attribute->getBackendTypeByInput($data['frontend_input']);
             $attribute->addData($data);
             $attribute->setIsUserDefined(1);
             $attribute->setEntityTypeId($this->getEntityTypeId());
             $attribute->save();
             $attributeId = $attribute->getId();
             if (is_array($data['attribute_set'])) {
                 foreach ($data['attribute_set'] as $setName) {
                     $setName = trim($setName);
                     $attributeCount++;
                     $attributeSet = $this->processAttributeSet($setName);
                     $attributeGroupId = $attributeSet->getDefaultGroupId();
                     $attribute = $this->attributeFactory->create();
                     $attribute->setId($attributeId)->setAttributeGroupId($attributeGroupId)->setAttributeSetId($attributeSet->getId())->setEntityTypeId($this->getEntityTypeId())->setSortOrder($attributeCount + 999)->save();
                 }
             }
             $this->logger->logInline('.');
         }
     }
     $this->eavConfig->clear();
 }
コード例 #9
0
ファイル: Tablerate.php プロジェクト: ktplKunj/TestMagento
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing Tablerate:');
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */
     $adapter = $this->resource->getConnection('core_write');
     $fixtureFile = 'OfflineShipping/tablerate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     $regions = $this->loadDirectoryRegions();
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0;
         $adapter->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsiteId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]);
         $this->logger->logInline('.');
     }
     $this->configWriter->save('carriers/tablerate/active', 1);
     $this->configWriter->save('carriers/tablerate/condition_name', 'package_value');
     $this->cacheTypeList->cleanType('config');
 }
コード例 #10
0
 /**
  * @param array $orderData
  * @return void
  */
 public function createOrder($orderData)
 {
     $this->setPhraseRenderer();
     if (!empty($orderData)) {
         $orderCreateModel = $this->processQuote($orderData);
         if (!empty($orderData['payment'])) {
             $orderCreateModel->setPaymentData($orderData['payment']);
             $orderCreateModel->getQuote()->getPayment()->addData($orderData['payment']);
         }
         $customer = $this->customerRepository->get($orderData['order']['account']['email'], $this->storeManager->getWebsiteId());
         $orderCreateModel->getQuote()->setCustomer($customer);
         $orderCreateModel->getSession()->setCustomerId($customer->getId());
         $order = $orderCreateModel->importPostData($orderData['order'])->createOrder();
         $orderItem = $this->getOrderItemForTransaction($order);
         $this->invoiceOrder($orderItem);
         $this->shipOrder($orderItem);
         if ($orderData['refund'] === "yes") {
             $this->refundOrder($orderItem);
         }
         $registryItems = ['rule_data', 'currently_saved_addresses', 'current_invoice', 'current_shipment'];
         $this->unsetRegistryData($registryItems);
     }
 }