Esempio n. 1
0
 /**
  * Update attribute values for entity list per store
  *
  * @param array $entityIds
  * @param array $attrData
  * @param int $storeId
  * @return $this
  * @throws \Exception
  */
 public function updateAttributes($entityIds, $attrData, $storeId)
 {
     $object = new \Magento\Framework\DataObject();
     $object->setStoreId($storeId);
     $this->getConnection()->beginTransaction();
     try {
         foreach ($attrData as $attrCode => $value) {
             $attribute = $this->getAttribute($attrCode);
             if (!$attribute->getAttributeId()) {
                 continue;
             }
             $i = 0;
             foreach ($entityIds as $entityId) {
                 $i++;
                 $object->setId($entityId);
                 $object->setEntityId($entityId);
                 // collect data for save
                 $this->_saveAttributeValue($object, $attribute, $value);
                 // save collected data every 1000 rows
                 if ($i % 1000 == 0) {
                     $this->_processAttributeValues();
                 }
             }
             $this->_processAttributeValues();
         }
         $this->getConnection()->commit();
     } catch (\Exception $e) {
         $this->getConnection()->rollBack();
         throw $e;
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * After save process
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
 {
     parent::_afterSave($object);
     $condition = ['option_id = ?' => $object->getId(), 'store_id = ? OR store_id = 0' => $object->getStoreId()];
     $connection = $this->getConnection();
     $connection->delete($this->getTable('catalog_product_bundle_option_value'), $condition);
     $data = new \Magento\Framework\DataObject();
     $data->setOptionId($object->getId())->setStoreId($object->getStoreId())->setTitle($object->getTitle());
     $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());
     /**
      * also saving default value if this store view scope
      */
     if ($object->getStoreId()) {
         $data->setStoreId(0);
         $data->setTitle($object->getDefaultTitle());
         $connection->insert($this->getTable('catalog_product_bundle_option_value'), $data->getData());
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Retrieve Product data objects
  *
  * @param int|array $productIds
  * @param int $storeId
  * @param int $entityId
  * @param int &$lastEntityId
  * @return array
  */
 protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
 {
     $products = [];
     $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
     $connection = $this->getConnection();
     if ($productIds !== null) {
         if (!is_array($productIds)) {
             $productIds = [$productIds];
         }
     }
     $bind = ['website_id' => (int) $websiteId, 'entity_id' => (int) $entityId];
     $select = $connection->select()->useStraightJoin(true)->from(['e' => $this->getTable('catalog_product_entity')], ['entity_id'])->join(['w' => $this->getTable('catalog_product_website')], 'e.entity_id = w.product_id AND w.website_id = :website_id', [])->where('e.entity_id > :entity_id')->order('e.entity_id')->limit($this->_productLimit);
     if ($productIds !== null) {
         $select->where('e.entity_id IN(?)', $productIds);
     }
     $rowSet = $connection->fetchAll($select, $bind);
     foreach ($rowSet as $row) {
         $product = new \Magento\Framework\DataObject($row);
         $product->setId($row['entity_id']);
         $product->setEntityId($row['entity_id']);
         $product->setCategoryIds([]);
         $product->setStoreId($storeId);
         $products[$product->getId()] = $product;
         $lastEntityId = $product->getId();
     }
     unset($rowSet);
     if ($products) {
         $select = $connection->select()->from($this->getTable('catalog_category_product'), ['product_id', 'category_id'])->where('product_id IN(?)', array_keys($products));
         $categories = $connection->fetchAll($select);
         foreach ($categories as $category) {
             $productId = $category['product_id'];
             $categoryIds = $products[$productId]->getCategoryIds();
             $categoryIds[] = $category['category_id'];
             $products[$productId]->setCategoryIds($categoryIds);
         }
         foreach (['name', 'url_key', 'url_path'] as $attributeCode) {
             $attributes = $this->_getProductAttribute($attributeCode, array_keys($products), $storeId);
             foreach ($attributes as $productId => $attributeValue) {
                 $products[$productId]->setData($attributeCode, $attributeValue);
             }
         }
     }
     return $products;
 }
Esempio n. 4
0
 /**
  * Prepare and set request in property of current instance
  *
  * @param \Magento\Framework\DataObject $request
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function setRequest(\Magento\Framework\DataObject $request)
 {
     $this->_request = $request;
     $this->setStore($request->getStoreId());
     $requestObject = new \Magento\Framework\DataObject();
     $requestObject->setIsGenerateLabelReturn($request->getIsGenerateLabelReturn());
     $requestObject->setStoreId($request->getStoreId());
     if ($request->getLimitMethod()) {
         $requestObject->setService($request->getLimitMethod());
     }
     $requestObject = $this->_addParams($requestObject);
     if ($request->getDestPostcode()) {
         $requestObject->setDestPostal($request->getDestPostcode());
     }
     $requestObject->setOrigCountry($this->_getDefaultValue($request->getOrigCountry(), Shipment::XML_PATH_STORE_COUNTRY_ID))->setOrigCountryId($this->_getDefaultValue($request->getOrigCountryId(), Shipment::XML_PATH_STORE_COUNTRY_ID));
     $shippingWeight = $request->getPackageWeight();
     $requestObject->setValue(round($request->getPackageValue(), 2))->setValueWithDiscount($request->getPackageValueWithDiscount())->setCustomsValue($request->getPackageCustomsValue())->setDestStreet($this->string->substr(str_replace("\n", '', $request->getDestStreet()), 0, 35))->setDestStreetLine2($request->getDestStreetLine2())->setDestCity($request->getDestCity())->setOrigCompanyName($request->getOrigCompanyName())->setOrigCity($request->getOrigCity())->setOrigPhoneNumber($request->getOrigPhoneNumber())->setOrigPersonName($request->getOrigPersonName())->setOrigEmail($this->_scopeConfig->getValue('trans_email/ident_general/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $requestObject->getStoreId()))->setOrigCity($request->getOrigCity())->setOrigPostal($request->getOrigPostal())->setOrigStreetLine2($request->getOrigStreetLine2())->setDestPhoneNumber($request->getDestPhoneNumber())->setDestPersonName($request->getDestPersonName())->setDestCompanyName($request->getDestCompanyName());
     $originStreet2 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS2, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $requestObject->getStoreId());
     $requestObject->setOrigStreet($request->getOrigStreet() ? $request->getOrigStreet() : $originStreet2);
     if (is_numeric($request->getOrigState())) {
         $requestObject->setOrigState($this->_regionFactory->create()->load($request->getOrigState())->getCode());
     } else {
         $requestObject->setOrigState($request->getOrigState());
     }
     if ($request->getDestCountryId()) {
         $destCountry = $request->getDestCountryId();
     } else {
         $destCountry = self::USA_COUNTRY_ID;
     }
     // for DHL, Puerto Rico state for US will assume as Puerto Rico country
     // for Puerto Rico, dhl will ship as international
     if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
         $destCountry = self::PUERTORICO_COUNTRY_ID;
     }
     $requestObject->setDestCountryId($destCountry)->setDestState($request->getDestRegionCode())->setWeight($shippingWeight)->setFreeMethodWeight($request->getFreeMethodWeight())->setOrderShipment($request->getOrderShipment());
     if ($request->getPackageId()) {
         $requestObject->setPackageId($request->getPackageId());
     }
     $requestObject->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
     $this->setRawRequest($requestObject);
     return $this;
 }