Example #1
0
 /**
  * {@inheritdoc}
  */
 public function render(\Magento\Framework\DataObject $row)
 {
     if (!$row->getData($this->getColumn()->getIndex())) {
         return null;
     }
     return '<a title="' . __('Edit Store View') . '"
         href="' . $this->getUrl('adminhtml/*/editStore', ['store_id' => $row->getStoreId()]) . '">' . $this->escapeHtml($row->getData($this->getColumn()->getIndex())) . '</a>';
 }
Example #2
0
 /**
  * Render review type
  *
  * @param \Magento\Framework\DataObject $row
  * @return \Magento\Framework\Phrase
  */
 public function render(\Magento\Framework\DataObject $row)
 {
     if ($row->getCustomerId()) {
         return __('Customer');
     }
     if ($row->getStoreId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID) {
         return __('Administrator');
     }
     return __('Guest');
 }
Example #3
0
 /**
  * Before save
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 public function beforeSave($object)
 {
     if ($object->getId()) {
         return $this;
     }
     if (!$object->hasStoreId()) {
         $object->setStoreId($this->_storeManager->getStore()->getId());
     }
     if (!$object->hasData('created_in')) {
         $object->setData('created_in', $this->_storeManager->getStore($object->getStoreId())->getName());
     }
     return $this;
 }
Example #4
0
 /**
  * Check customer scope, email and confirmation key before saving
  *
  * @param \Magento\Framework\DataObject $customer
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _beforeSave(\Magento\Framework\DataObject $customer)
 {
     /** @var \Magento\Customer\Model\Customer $customer */
     if ($customer->getStoreId() === null) {
         $customer->setStoreId($this->storeManager->getStore()->getId());
     }
     $customer->getGroupId();
     parent::_beforeSave($customer);
     if (!$customer->getEmail()) {
         throw new ValidatorException(__('Please enter a customer email.'));
     }
     $connection = $this->getConnection();
     $bind = ['email' => $customer->getEmail()];
     $select = $connection->select()->from($this->getEntityTable(), [$this->getEntityIdField()])->where('email = :email');
     if ($customer->getSharingConfig()->isWebsiteScope()) {
         $bind['website_id'] = (int) $customer->getWebsiteId();
         $select->where('website_id = :website_id');
     }
     if ($customer->getId()) {
         $bind['entity_id'] = (int) $customer->getId();
         $select->where('entity_id != :entity_id');
     }
     $result = $connection->fetchOne($select, $bind);
     if ($result) {
         throw new AlreadyExistsException(__('A customer with the same email already exists in an associated website.'));
     }
     // set confirmation key logic
     if ($customer->getForceConfirmed() || $customer->getPasswordHash() == '') {
         $customer->setConfirmation(null);
     } elseif (!$customer->getId() && $customer->isConfirmationRequired()) {
         $customer->setConfirmation($customer->getRandomConfirmationKey());
     }
     // remove customer confirmation key from database, if empty
     if (!$customer->getConfirmation()) {
         $customer->setConfirmation(null);
     }
     $this->_validate($customer);
     return $this;
 }
 /**
  * Form XML for international shipment request
  * As integration guide it is important to follow appropriate sequence for tags e.g.: <FromLastName /> must be
  * after <FromFirstName />
  *
  * @param \Magento\Framework\DataObject $request
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _formIntlShipmentRequest(\Magento\Framework\DataObject $request)
 {
     $packageParams = $request->getPackageParams();
     $height = $packageParams->getHeight();
     $width = $packageParams->getWidth();
     $length = $packageParams->getLength();
     $girth = $packageParams->getGirth();
     $packageWeight = $request->getPackageWeight();
     if ($packageParams->getWeightUnits() != \Zend_Measure_Weight::POUND) {
         $packageWeight = $this->_carrierHelper->convertMeasureWeight($request->getPackageWeight(), $packageParams->getWeightUnits(), \Zend_Measure_Weight::POUND);
     }
     if ($packageParams->getDimensionUnits() != \Zend_Measure_Length::INCH) {
         $length = round($this->_carrierHelper->convertMeasureDimension($packageParams->getLength(), $packageParams->getDimensionUnits(), \Zend_Measure_Length::INCH));
         $width = round($this->_carrierHelper->convertMeasureDimension($packageParams->getWidth(), $packageParams->getDimensionUnits(), \Zend_Measure_Length::INCH));
         $height = round($this->_carrierHelper->convertMeasureDimension($packageParams->getHeight(), $packageParams->getDimensionUnits(), \Zend_Measure_Length::INCH));
     }
     if ($packageParams->getGirthDimensionUnits() != \Zend_Measure_Length::INCH) {
         $girth = round($this->_carrierHelper->convertMeasureDimension($packageParams->getGirth(), $packageParams->getGirthDimensionUnits(), \Zend_Measure_Length::INCH));
     }
     $container = $request->getPackagingType();
     switch ($container) {
         case 'VARIABLE':
             $container = 'VARIABLE';
             break;
         case 'FLAT RATE ENVELOPE':
             $container = 'FLATRATEENV';
             break;
         case 'FLAT RATE BOX':
             $container = 'FLATRATEBOX';
             break;
         case 'RECTANGULAR':
             $container = 'RECTANGULAR';
             break;
         case 'NONRECTANGULAR':
             $container = 'NONRECTANGULAR';
             break;
         default:
             $container = 'VARIABLE';
     }
     $shippingMethod = $request->getShippingMethod();
     list($fromZip5, $fromZip4) = $this->_parseZip($request->getShipperAddressPostalCode());
     // the wrap node needs for remove xml declaration above
     $xmlWrap = $this->_xmlElFactory->create(['data' => '<?xml version = "1.0" encoding = "UTF-8"?><wrap/>']);
     $method = '';
     $service = $this->getCode('service_to_code', $shippingMethod);
     if ($service == 'Priority') {
         $method = 'Priority';
         $rootNode = 'PriorityMailIntlRequest';
         $xml = $xmlWrap->addChild($rootNode);
     } else {
         if ($service == 'First Class') {
             $method = 'FirstClass';
             $rootNode = 'FirstClassMailIntlRequest';
             $xml = $xmlWrap->addChild($rootNode);
         } else {
             $method = 'Express';
             $rootNode = 'ExpressMailIntlRequest';
             $xml = $xmlWrap->addChild($rootNode);
         }
     }
     $xml->addAttribute('USERID', $this->getConfigData('userid'));
     $xml->addAttribute('PASSWORD', $this->getConfigData('password'));
     $xml->addChild('Option');
     $xml->addChild('Revision', self::DEFAULT_REVISION);
     $xml->addChild('ImageParameters');
     $xml->addChild('FromFirstName', $request->getShipperContactPersonFirstName());
     $xml->addChild('FromLastName', $request->getShipperContactPersonLastName());
     $xml->addChild('FromFirm', $request->getShipperContactCompanyName());
     $xml->addChild('FromAddress1', $request->getShipperAddressStreet2());
     $xml->addChild('FromAddress2', $request->getShipperAddressStreet1());
     $xml->addChild('FromCity', $request->getShipperAddressCity());
     $xml->addChild('FromState', $request->getShipperAddressStateOrProvinceCode());
     $xml->addChild('FromZip5', $fromZip5);
     $xml->addChild('FromZip4', $fromZip4);
     $xml->addChild('FromPhone', $request->getShipperContactPhoneNumber());
     if ($method != 'FirstClass') {
         if ($request->getReferenceData()) {
             $referenceData = $request->getReferenceData() . ' P' . $request->getPackageId();
         } else {
             $referenceData = $request->getOrderShipment()->getOrder()->getIncrementId() . ' P' . $request->getPackageId();
         }
         $xml->addChild('FromCustomsReference', 'Order #' . $referenceData);
     }
     $xml->addChild('ToFirstName', $request->getRecipientContactPersonFirstName());
     $xml->addChild('ToLastName', $request->getRecipientContactPersonLastName());
     $xml->addChild('ToFirm', $request->getRecipientContactCompanyName());
     $xml->addChild('ToAddress1', $request->getRecipientAddressStreet1());
     $xml->addChild('ToAddress2', $request->getRecipientAddressStreet2());
     $xml->addChild('ToCity', $request->getRecipientAddressCity());
     $xml->addChild('ToProvince', $request->getRecipientAddressStateOrProvinceCode());
     $xml->addChild('ToCountry', $this->_getCountryName($request->getRecipientAddressCountryCode()));
     $xml->addChild('ToPostalCode', $request->getRecipientAddressPostalCode());
     $xml->addChild('ToPOBoxFlag', 'N');
     $xml->addChild('ToPhone', $request->getRecipientContactPhoneNumber());
     $xml->addChild('ToFax');
     $xml->addChild('ToEmail');
     if ($method != 'FirstClass') {
         $xml->addChild('NonDeliveryOption', 'Return');
     }
     if ($method == 'FirstClass') {
         if (stripos($shippingMethod, 'Letter') !== false) {
             $xml->addChild('FirstClassMailType', 'LETTER');
         } else {
             if (stripos($shippingMethod, 'Flat') !== false) {
                 $xml->addChild('FirstClassMailType', 'FLAT');
             } else {
                 $xml->addChild('FirstClassMailType', 'PARCEL');
             }
         }
     }
     if ($method != 'FirstClass') {
         $xml->addChild('Container', $container);
     }
     $shippingContents = $xml->addChild('ShippingContents');
     $packageItems = $request->getPackageItems();
     // get countries of manufacture
     $countriesOfManufacture = [];
     $productIds = [];
     foreach ($packageItems as $itemShipment) {
         $item = new \Magento\Framework\DataObject();
         $item->setData($itemShipment);
         $productIds[] = $item->getProductId();
     }
     $productCollection = $this->_productCollectionFactory->create()->addStoreFilter($request->getStoreId())->addFieldToFilter('entity_id', ['in' => $productIds])->addAttributeToSelect('country_of_manufacture');
     foreach ($productCollection as $product) {
         $countriesOfManufacture[$product->getId()] = $product->getCountryOfManufacture();
     }
     $packagePoundsWeight = $packageOuncesWeight = 0;
     // for ItemDetail
     foreach ($packageItems as $itemShipment) {
         $item = new \Magento\Framework\DataObject();
         $item->setData($itemShipment);
         $itemWeight = $item->getWeight() * $item->getQty();
         if ($packageParams->getWeightUnits() != \Zend_Measure_Weight::POUND) {
             $itemWeight = $this->_carrierHelper->convertMeasureWeight($itemWeight, $packageParams->getWeightUnits(), \Zend_Measure_Weight::POUND);
         }
         if (!empty($countriesOfManufacture[$item->getProductId()])) {
             $countryOfManufacture = $this->_getCountryName($countriesOfManufacture[$item->getProductId()]);
         } else {
             $countryOfManufacture = '';
         }
         $itemDetail = $shippingContents->addChild('ItemDetail');
         $itemDetail->addChild('Description', $item->getName());
         $ceiledQty = ceil($item->getQty());
         if ($ceiledQty < 1) {
             $ceiledQty = 1;
         }
         $individualItemWeight = $itemWeight / $ceiledQty;
         $itemDetail->addChild('Quantity', $ceiledQty);
         $itemDetail->addChild('Value', $item->getCustomsValue() * $item->getQty());
         list($individualPoundsWeight, $individualOuncesWeight) = $this->_convertPoundOunces($individualItemWeight);
         $itemDetail->addChild('NetPounds', $individualPoundsWeight);
         $itemDetail->addChild('NetOunces', $individualOuncesWeight);
         $itemDetail->addChild('HSTariffNumber', 0);
         $itemDetail->addChild('CountryOfOrigin', $countryOfManufacture);
         list($itemPoundsWeight, $itemOuncesWeight) = $this->_convertPoundOunces($itemWeight);
         $packagePoundsWeight += $itemPoundsWeight;
         $packageOuncesWeight += $itemOuncesWeight;
     }
     $additionalPackagePoundsWeight = floor($packageOuncesWeight / self::OUNCES_POUND);
     $packagePoundsWeight += $additionalPackagePoundsWeight;
     $packageOuncesWeight -= $additionalPackagePoundsWeight * self::OUNCES_POUND;
     if ($packagePoundsWeight + $packageOuncesWeight / self::OUNCES_POUND < $packageWeight) {
         list($packagePoundsWeight, $packageOuncesWeight) = $this->_convertPoundOunces($packageWeight);
     }
     $xml->addChild('GrossPounds', $packagePoundsWeight);
     $xml->addChild('GrossOunces', $packageOuncesWeight);
     if ($packageParams->getContentType() == 'OTHER' && $packageParams->getContentTypeOther() != null) {
         $xml->addChild('ContentType', $packageParams->getContentType());
         $xml->addChild('ContentTypeOther ', $packageParams->getContentTypeOther());
     } else {
         $xml->addChild('ContentType', $packageParams->getContentType());
     }
     $xml->addChild('Agreement', 'y');
     $xml->addChild('ImageType', 'PDF');
     $xml->addChild('ImageLayout', 'ALLINONEFILE');
     if ($method == 'FirstClass') {
         $xml->addChild('Container', $container);
     }
     // set size
     if ($packageParams->getSize()) {
         $xml->addChild('Size', $packageParams->getSize());
     }
     // set dimensions
     $xml->addChild('Length', $length);
     $xml->addChild('Width', $width);
     $xml->addChild('Height', $height);
     if ($girth) {
         $xml->addChild('Girth', $girth);
     }
     $xml = $xmlWrap->{$rootNode}->asXML();
     return $xml;
 }
Example #6
0
 /**
  * Form array with appropriate structure for shipment request
  *
  * @param \Magento\Framework\DataObject $request
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _formShipmentRequest(\Magento\Framework\DataObject $request)
 {
     if ($request->getReferenceData()) {
         $referenceData = $request->getReferenceData() . $request->getPackageId();
     } else {
         $referenceData = 'Order #' . $request->getOrderShipment()->getOrder()->getIncrementId() . ' P' . $request->getPackageId();
     }
     $packageParams = $request->getPackageParams();
     $customsValue = $packageParams->getCustomsValue();
     $height = $packageParams->getHeight();
     $width = $packageParams->getWidth();
     $length = $packageParams->getLength();
     $weightUnits = $packageParams->getWeightUnits() == \Zend_Measure_Weight::POUND ? 'LB' : 'KG';
     $dimensionsUnits = $packageParams->getDimensionUnits() == \Zend_Measure_Length::INCH ? 'IN' : 'CM';
     $unitPrice = 0;
     $itemsQty = 0;
     $itemsDesc = [];
     $countriesOfManufacture = [];
     $productIds = [];
     $packageItems = $request->getPackageItems();
     foreach ($packageItems as $itemShipment) {
         $item = new \Magento\Framework\DataObject();
         $item->setData($itemShipment);
         $unitPrice += $item->getPrice();
         $itemsQty += $item->getQty();
         $itemsDesc[] = $item->getName();
         $productIds[] = $item->getProductId();
     }
     // get countries of manufacture
     $productCollection = $this->_productCollectionFactory->create()->addStoreFilter($request->getStoreId())->addFieldToFilter('entity_id', ['in' => $productIds])->addAttributeToSelect('country_of_manufacture');
     foreach ($productCollection as $product) {
         $countriesOfManufacture[] = $product->getCountryOfManufacture();
     }
     $paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER';
     $optionType = $request->getShippingMethod() == self::RATE_REQUEST_SMARTPOST ? 'SERVICE_DEFAULT' : $packageParams->getDeliveryConfirmation();
     $requestClient = ['RequestedShipment' => ['ShipTimestamp' => time(), 'DropoffType' => $this->getConfigData('dropoff'), 'PackagingType' => $request->getPackagingType(), 'ServiceType' => $request->getShippingMethod(), 'Shipper' => ['Contact' => ['PersonName' => $request->getShipperContactPersonName(), 'CompanyName' => $request->getShipperContactCompanyName(), 'PhoneNumber' => $request->getShipperContactPhoneNumber()], 'Address' => ['StreetLines' => [$request->getShipperAddressStreet()], 'City' => $request->getShipperAddressCity(), 'StateOrProvinceCode' => $request->getShipperAddressStateOrProvinceCode(), 'PostalCode' => $request->getShipperAddressPostalCode(), 'CountryCode' => $request->getShipperAddressCountryCode()]], 'Recipient' => ['Contact' => ['PersonName' => $request->getRecipientContactPersonName(), 'CompanyName' => $request->getRecipientContactCompanyName(), 'PhoneNumber' => $request->getRecipientContactPhoneNumber()], 'Address' => ['StreetLines' => [$request->getRecipientAddressStreet()], 'City' => $request->getRecipientAddressCity(), 'StateOrProvinceCode' => $request->getRecipientAddressStateOrProvinceCode(), 'PostalCode' => $request->getRecipientAddressPostalCode(), 'CountryCode' => $request->getRecipientAddressCountryCode(), 'Residential' => (bool) $this->getConfigData('residence_delivery')]], 'ShippingChargesPayment' => ['PaymentType' => $paymentType, 'Payor' => ['AccountNumber' => $this->getConfigData('account'), 'CountryCode' => $this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId())]], 'LabelSpecification' => ['LabelFormatType' => 'COMMON2D', 'ImageType' => 'PNG', 'LabelStockType' => 'PAPER_8.5X11_TOP_HALF_LABEL'], 'RateRequestTypes' => ['ACCOUNT'], 'PackageCount' => 1, 'RequestedPackageLineItems' => ['SequenceNumber' => '1', 'Weight' => ['Units' => $weightUnits, 'Value' => $request->getPackageWeight()], 'CustomerReferences' => ['CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => $referenceData], 'SpecialServicesRequested' => ['SpecialServiceTypes' => 'SIGNATURE_OPTION', 'SignatureOptionDetail' => ['OptionType' => $optionType]]]]];
     // for international shipping
     if ($request->getShipperAddressCountryCode() != $request->getRecipientAddressCountryCode()) {
         $requestClient['RequestedShipment']['CustomsClearanceDetail'] = ['CustomsValue' => ['Currency' => $request->getBaseCurrencyCode(), 'Amount' => $customsValue], 'DutiesPayment' => ['PaymentType' => $paymentType, 'Payor' => ['AccountNumber' => $this->getConfigData('account'), 'CountryCode' => $this->_scopeConfig->getValue(\Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $request->getStoreId())]], 'Commodities' => ['Weight' => ['Units' => $weightUnits, 'Value' => $request->getPackageWeight()], 'NumberOfPieces' => 1, 'CountryOfManufacture' => implode(',', array_unique($countriesOfManufacture)), 'Description' => implode(', ', $itemsDesc), 'Quantity' => ceil($itemsQty), 'QuantityUnits' => 'pcs', 'UnitPrice' => ['Currency' => $request->getBaseCurrencyCode(), 'Amount' => $unitPrice], 'CustomsValue' => ['Currency' => $request->getBaseCurrencyCode(), 'Amount' => $customsValue]]];
     }
     if ($request->getMasterTrackingId()) {
         $requestClient['RequestedShipment']['MasterTrackingId'] = $request->getMasterTrackingId();
     }
     if ($request->getShippingMethod() == self::RATE_REQUEST_SMARTPOST) {
         $requestClient['RequestedShipment']['SmartPostDetail'] = ['Indicia' => (double) $request->getPackageWeight() >= 1 ? 'PARCEL_SELECT' : 'PRESORTED_STANDARD', 'HubId' => $this->getConfigData('smartpost_hubid')];
     }
     // set dimensions
     if ($length || $width || $height) {
         $requestClient['RequestedShipment']['RequestedPackageLineItems']['Dimensions'] = [];
         $dimenssions =& $requestClient['RequestedShipment']['RequestedPackageLineItems']['Dimensions'];
         $dimenssions['Length'] = $length;
         $dimenssions['Width'] = $width;
         $dimenssions['Height'] = $height;
         $dimenssions['Units'] = $dimensionsUnits;
     }
     return $this->_getAuthDetails() + $requestClient;
 }
 /**
  * Delete entity attribute values
  *
  * @param \Magento\Framework\DataObject $object
  * @param string $table
  * @param array $info
  * @return $this
  */
 protected function _deleteAttributes($object, $table, $info)
 {
     $connection = $this->getConnection();
     $entityIdField = $this->getEntityIdField();
     $globalValues = [];
     $websiteAttributes = [];
     $storeAttributes = [];
     /**
      * Separate attributes by scope
      */
     foreach ($info as $itemData) {
         $attribute = $this->getAttribute($itemData['attribute_id']);
         if ($attribute->isScopeStore()) {
             $storeAttributes[] = (int) $itemData['attribute_id'];
         } elseif ($attribute->isScopeWebsite()) {
             $websiteAttributes[] = (int) $itemData['attribute_id'];
         } elseif ($itemData['value_id'] !== null) {
             $globalValues[] = (int) $itemData['value_id'];
         }
     }
     /**
      * Delete global scope attributes
      */
     if (!empty($globalValues)) {
         $connection->delete($table, ['value_id IN (?)' => $globalValues]);
     }
     $condition = [$entityIdField . ' = ?' => $object->getId()];
     /**
      * Delete website scope attributes
      */
     if (!empty($websiteAttributes)) {
         $storeIds = $object->getWebsiteStoreIds();
         if (!empty($storeIds)) {
             $delCondition = $condition;
             $delCondition['attribute_id IN(?)'] = $websiteAttributes;
             $delCondition['store_id IN(?)'] = $storeIds;
             $connection->delete($table, $delCondition);
         }
     }
     /**
      * Delete store scope attributes
      */
     if (!empty($storeAttributes)) {
         $delCondition = $condition;
         $delCondition['attribute_id IN(?)'] = $storeAttributes;
         $delCondition['store_id = ?'] = (int) $object->getStoreId();
         $connection->delete($table, $delCondition);
     }
     return $this;
 }
Example #8
0
 /**
  * Set new increment id to object
  *
  * @param \Magento\Framework\DataObject $object
  * @return $this
  */
 public function setNewIncrementId(\Magento\Framework\DataObject $object)
 {
     if ($object->getIncrementId()) {
         return $this;
     }
     $incrementId = $this->getEntityType()->fetchNewIncrementId($object->getStoreId());
     if ($incrementId !== false) {
         $object->setIncrementId($incrementId);
     }
     return $this;
 }
Example #9
0
 /**
  * Adds new product to wishlist.
  * Returns new item or string on error.
  *
  * @param int|\Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\DataObject|array|string|null $buyRequest
  * @param bool $forciblySetQty
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return Item|string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function addNewItem($product, $buyRequest = null, $forciblySetQty = false)
 {
     /*
      * Always load product, to ensure:
      * a) we have new instance and do not interfere with other products in wishlist
      * b) product has full set of attributes
      */
     if ($product instanceof \Magento\Catalog\Model\Product) {
         $productId = $product->getId();
         // Maybe force some store by wishlist internal properties
         $storeId = $product->hasWishlistStoreId() ? $product->getWishlistStoreId() : $product->getStoreId();
     } else {
         $productId = (int) $product;
         if (isset($buyRequest) && $buyRequest->getStoreId()) {
             $storeId = $buyRequest->getStoreId();
         } else {
             $storeId = $this->_storeManager->getStore()->getId();
         }
     }
     try {
         $product = $this->productRepository->getById($productId, false, $storeId);
     } catch (NoSuchEntityException $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Cannot specify product.'));
     }
     if ($buyRequest instanceof \Magento\Framework\DataObject) {
         $_buyRequest = $buyRequest;
     } elseif (is_string($buyRequest)) {
         $_buyRequest = new \Magento\Framework\DataObject(unserialize($buyRequest));
     } elseif (is_array($buyRequest)) {
         $_buyRequest = new \Magento\Framework\DataObject($buyRequest);
     } else {
         $_buyRequest = new \Magento\Framework\DataObject();
     }
     /* @var $product \Magento\Catalog\Model\Product */
     $cartCandidates = $product->getTypeInstance()->processConfiguration($_buyRequest, clone $product);
     /**
      * Error message
      */
     if (is_string($cartCandidates)) {
         return $cartCandidates;
     }
     /**
      * If prepare process return one object
      */
     if (!is_array($cartCandidates)) {
         $cartCandidates = [$cartCandidates];
     }
     $errors = [];
     $items = [];
     foreach ($cartCandidates as $candidate) {
         if ($candidate->getParentProductId()) {
             continue;
         }
         $candidate->setWishlistStoreId($storeId);
         $qty = $candidate->getQty() ? $candidate->getQty() : 1;
         // No null values as qty. Convert zero to 1.
         $item = $this->_addCatalogProduct($candidate, $qty, $forciblySetQty);
         $items[] = $item;
         // Collect errors instead of throwing first one
         if ($item->getHasError()) {
             $errors[] = $item->getMessage();
         }
     }
     $this->_eventManager->dispatch('wishlist_product_add_after', ['items' => $items]);
     return $item;
 }
 /**
  * Add information about product ids to visitor/customer
  *
  * @param \Magento\Framework\DataObject|\Magento\Reports\Model\Product\Index\AbstractIndex $object
  * @param int[] $productIds
  * @return $this
  */
 public function registerIds(\Magento\Framework\DataObject $object, $productIds)
 {
     $row = ['visitor_id' => $object->getVisitorId(), 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId()];
     $data = [];
     foreach ($productIds as $productId) {
         $productId = (int) $productId;
         if ($productId) {
             $row['product_id'] = $productId;
             $data[] = $row;
         }
     }
     $matchFields = ['product_id', 'store_id'];
     foreach ($data as $row) {
         $this->_resourceHelper->mergeVisitorProductIndex($this->getMainTable(), $row, $matchFields);
     }
     return $this;
 }
 /**
  * Add information about product ids to visitor/customer
  *
  * @param \Magento\Framework\DataObject|\Magento\Reports\Model\Product\Index\AbstractIndex $object
  * @param int[] $productIds
  * @return $this
  */
 public function registerIds(\Magento\Framework\DataObject $object, $productIds)
 {
     $row = ['visitor_id' => $object->getVisitorId(), 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId()];
     $addedAt = (new \DateTime())->getTimestamp();
     $data = [];
     foreach ($productIds as $productId) {
         $productId = (int) $productId;
         if ($productId) {
             $row['product_id'] = $productId;
             $row['added_at'] = $this->dateTime->formatDate($addedAt);
             $data[] = $row;
         }
         $addedAt -= $addedAt > 0 ? 1 : 0;
     }
     $matchFields = ['product_id', 'store_id'];
     foreach ($data as $row) {
         $this->_resourceHelper->mergeVisitorProductIndex($this->getMainTable(), $row, $matchFields);
     }
     return $this;
 }
Example #12
0
 /**
  * @param DataObject|null $object
  * @return string
  */
 private function getLoadAllAttributesCacheSuffix(DataObject $object = null)
 {
     $attributeSetId = 0;
     $storeId = 0;
     if (null !== $object) {
         $attributeSetId = $object->getAttributeSetId() ?: $attributeSetId;
         $storeId = $object->getStoreId() ?: $storeId;
     }
     $suffix = $storeId . '-' . $attributeSetId;
     return $suffix;
 }
Example #13
0
 /**
  * Get codes of all entity type attributes
  *
  * @param  mixed $entityType
  * @param  \Magento\Framework\DataObject $object
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getEntityAttributeCodes($entityType, $object = null)
 {
     $entityType = $this->getEntityType($entityType);
     $attributeSetId = 0;
     $storeId = 0;
     if ($object instanceof \Magento\Framework\DataObject) {
         $attributeSetId = $object->getAttributeSetId() ?: $attributeSetId;
         $storeId = $object->getStoreId() ?: $storeId;
     }
     $cacheKey = self::ATTRIBUTES_CODES_CACHE_ID . $entityType->getId() . '-' . $storeId . '-' . $attributeSetId;
     if (isset($this->_attributeCodes[$cacheKey])) {
         return $this->_attributeCodes[$cacheKey];
     }
     if ($this->isCacheEnabled() && ($attributes = $this->_cache->load($cacheKey))) {
         $this->_attributeCodes[$cacheKey] = unserialize($attributes);
         return $this->_attributeCodes[$cacheKey];
     }
     if ($attributeSetId) {
         $attributesInfo = $this->_universalFactory->create($entityType->getEntityAttributeCollection())->setEntityTypeFilter($entityType)->setAttributeSetFilter($attributeSetId)->addStoreLabel($storeId)->getData();
         $attributes = [];
         foreach ($attributesInfo as $attributeData) {
             $attributes[] = $attributeData['attribute_code'];
             $this->_createAttribute($entityType, $attributeData);
         }
     } else {
         $this->_initAttributes($entityType);
         $attributes = array_keys($this->_attributeData[$entityType->getEntityTypeCode()]);
     }
     $this->_attributeCodes[$cacheKey] = $attributes;
     if ($this->isCacheEnabled()) {
         $this->_cache->save(serialize($attributes), $cacheKey, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]);
     }
     return $attributes;
 }
Example #14
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;
 }