/** * Submit the generated XML file to Amazon. */ public function submit() { /** @var Edgecom_MarketplaceWebService_Helper_Data $helper */ $helper = Mage::helper('edgecom_marketplacewebservice'); $awsAccessKeyId = $helper->getAwsAccessKeyId(); $secretKey = $helper->getSecretKey(); $applicationName = $helper->getApplicationName(); $applicationVersion = $helper->getApplicationVersion(); $service = new MarketplaceWebService_Client($awsAccessKeyId, $secretKey, array('ServiceURL' => 'https://mws.amazonservices.com', 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3), $applicationName, $applicationVersion); $merchantId = $helper->getSellerId(); $marketplaceIdArray = array('Id' => array($helper->getMarketplaceId())); $request = new MarketplaceWebService_Model_SubmitFeedRequest(); $request->setMerchant($merchantId); $request->setMarketplaceIdList($marketplaceIdArray); $request->setFeedType($this->feed->getType()); $request->setPurgeAndReplace(false); if ($stream = fopen($this->feed->getLocation(), 'r')) { $request->setContentMd5(base64_encode(md5(stream_get_contents($stream), true))); rewind($stream); $request->setFeedContent($stream); rewind($stream); } $response = $service->submitFeed($request); fclose($stream); $feedSubmissionId = $response->getSubmitFeedResult()->getFeedSubmissionInfo()->getFeedSubmissionId(); Mage::log('Feed #' . $feedSubmissionId . ' has been submitted to Amazon', null, 'amazon.log'); }
public function submitPendingFeeds($id_feedtype) { $sql = "select f.id_feed, sf.id_subfeed, ft.feed_name, ft.code, sf.feed_file from ps_affiliate_feed f inner join ps_affiliate_subfeed sf on f.id_feed = sf.id_feed and f.id_status in (" . MarketplaceWebService_DB::$STATUS_PREP_SUCCESS . "," . MarketplaceWebService_DB::$STATUS_PREP_PARTIAL_SUCCESS . ") and sf.id_status in (" . MarketplaceWebService_DB::$STATUS_PREP_SUCCESS . "," . MarketplaceWebService_DB::$STATUS_PREP_PARTIAL_SUCCESS . ") inner join ps_affiliate_feed_type ft on ft.id = sf.id_type and ft.id = {$id_feedtype}"; $feed = $this->db->getRow($sql); if (empty($feed)) { return "none"; } $service = new MarketplaceWebService_Client($this->mws_config['access_key'], $this->mws_config['secret_key'], $this->config, APPLICATION_NAME, APPLICATION_VERSION); $id_feed = $feed['id_feed']; $id_subfeed = $feed['id_subfeed']; $code = $feed['code']; $feed_file = PS_ADMIN_DIR . "/amazon/" . $feed['feed_file']; $feedstr = file_get_contents($feed_file); $feedHandle = @fopen('php://memory', 'rw+'); fwrite($feedHandle, $feedstr); rewind($feedHandle); $marketplaceIdArray = array("Id" => array($this->mws_config['marketplace_id'])); $request = new MarketplaceWebService_Model_SubmitFeedRequest(); $request->setMerchant($this->mws_config['merchant_id']); $request->setMarketplaceIdList($marketplaceIdArray); $request->setFeedType($code); $request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true))); rewind($feedHandle); $request->setPurgeAndReplace(false); $request->setFeedContent($feedHandle); //print_r( $request ); rewind($feedHandle); $feedSubmissionId = $this->invokeSubmitFeed($service, $request); @fclose($feedHandle); if ($feedSubmissionId === null) { return "wait"; } $sql = "update ps_affiliate_subfeed set feed_submission_id={$feedSubmissionId}, id_status = " . MarketplaceWebService_DB::$STATUS_AZN_SUBMITTED . " where id_subfeed = {$id_subfeed}"; $this->db->ExecuteS($sql); $sql = "select count(*) as count from ps_affiliate_subfeed where id_feed = {$id_feed} and id_status != " . MarketplaceWebService_DB::$STATUS_AZN_SUBMITTED; $cres = $this->db->getRow($sql); if ((int) $cres['count'] === 0) { $sql = "update ps_affiliate_feed set id_status = " . MarketplaceWebService_DB::$STATUS_AZN_SUBMITTED . " where id_feed = {$id_feed}"; $this->db->ExecuteS($sql); } return "success"; }
/** * @param \DOMDocument $feed * @param $marketPlaceId * @param $feedType * * @return \MarketplaceWebService_Model_SubmitFeedRequest */ private function getSubmitFeedRequest(\DOMDocument $feed, $marketPlaceId, $feedType) { file_put_contents('/tmp/mws', $feed->saveXML()); $feedHandle = fopen('/tmp/mws', 'r'); rewind($feedHandle); $merchantID = $this->config['merchant_id']; $request = new \MarketplaceWebService_Model_SubmitFeedRequest(); $request->setMerchant($merchantID); $request->setMarketplaceIdList(array('Id' => $marketPlaceId)); $request->setFeedType($feedType); $request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true))); $request->setPurgeAndReplace(false); rewind($feedHandle); $request->setFeedContent($feedHandle); return $request; }
function shipment_feed($param) { $config = array('ServiceURL' => $this->serviceUrl, 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3); $service = new MarketplaceWebService_Client(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, $config, APPLICATION_NAME, APPLICATION_VERSION); $feed = '<?xml version="1.0" encoding="UTF-8"?> <AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Header> <DocumentVersion>1.02</DocumentVersion> <MerchantIdentifier>' . MERCHANT_ID . '</MerchantIdentifier> </Header> <MessageType>OrderFulfillment</MessageType> <Message> <MessageID>1</MessageID> <OrderFulfillment> <AmazonOrderID>' . $param['AmazonOrderID'] . '</AmazonOrderID> <MerchantFulfillmentID>' . $param['MerchantOrderID'] . '</MerchantFulfillmentID> <FulfillmentDate>' . $param['FulfillmentDate'] . '</FulfillmentDate> <FulfillmentData> <CarrierName>' . $param['CarrierName'] . '</CarrierName> <ShippingMethod>' . $param['ShippingMethod'] . '</ShippingMethod> <ShipperTrackingNumber>' . $param['ShipperTrackingNumber'] . '</ShipperTrackingNumber> </FulfillmentData> </OrderFulfillment> </Message> </AmazonEnvelope>'; $marketplaceIdArray = array("Id" => array(MARKETPLACE_ID)); $feedHandle = @fopen('php://memory', 'rw+'); fwrite($feedHandle, $feed); rewind($feedHandle); $request = new MarketplaceWebService_Model_SubmitFeedRequest(); $request->setMerchant(MERCHANT_ID); $request->setMarketplaceIdList($marketplaceIdArray); $request->setFeedType('_POST_ORDER_FULFILLMENT_DATA_'); $request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true))); rewind($feedHandle); $request->setPurgeAndReplace(false); $request->setFeedContent($feedHandle); rewind($feedHandle); return $this->invokeSubmitFeed($service, $request); @fclose($feedHandle); }
public function submitFeed($FeedType, $FeedContent) { $this->initAPI(); // init stream ressource $feedHandle = @fopen('php://memory', 'rw+'); fwrite($feedHandle, $FeedContent); rewind($feedHandle); $marketplaceIdArray = array("Id" => array($this->MarketplaceId)); $request = new MarketplaceWebService_Model_SubmitFeedRequest(); $request->setSellerId($this->SellerId); $request->setMarketplaceIdList($marketplaceIdArray); $request->setPurgeAndReplace(false); $request->setFeedType($FeedType); $request->setFeedContent($feedHandle); rewind($feedHandle); $request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true))); rewind($feedHandle); $result = $this->invokeSubmitFeed($this->service, $request); @fclose($feedHandle); return $result; }
$marketplaceIdArray = array("Id" => array($_POST['marketplaceid'])); /************************************************************************ * Instantiate Implementation of MarketplaceWebService * * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants * are defined in the .config.inc.php located in the same * directory as this sample ***********************************************************************/ $service = new MarketplaceWebService_Client(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, $config, APPLICATION_NAME, APPLICATION_VERSION); $file = file_get_contents($_POST['content']); $feedHandle = @fopen('php://memory', 'rw+'); fwrite($feedHandle, $file); rewind($feedHandle); $request = new MarketplaceWebService_Model_SubmitFeedRequest(); $request->setMerchant(MERCHANT_ID); $request->setMarketplaceIdList($marketplaceIdArray); $request->setFeedType('_POST_FLAT_FILE_LISTINGS_DATA_'); $request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true))); rewind($feedHandle); $purge = false; if ($_POST['purgeremember'] == 'true') { $purge = true; } $request->setPurgeAndReplace($purge); $request->setFeedContent($feedHandle); rewind($feedHandle); invokeSubmitFeed($service, $request); @fclose($feedHandle); } } /**
protected function submitFeed($type, $feed) { Yii::log("Amazon Submission " . $type . " " . $feed, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__); $marketplaceIdArray = array("Id" => array($this->MarketplaceID)); $feedHandle = @fopen('php://memory', 'rw+'); fwrite($feedHandle, $feed); rewind($feedHandle); $request = new MarketplaceWebService_Model_SubmitFeedRequest(); $request->setMerchant($this->MerchantID); $request->setMarketplaceIdList($marketplaceIdArray); $request->setFeedType($type); $request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true))); rewind($feedHandle); $request->setPurgeAndReplace(false); $request->setFeedContent($feedHandle); rewind($feedHandle); /********* End Comment Block *********/ $response = $this->service->submitFeed($request); rewind($feedHandle); @fclose($feedHandle); //Actually submit to Amazon. We should get back an ID number that we need to follow //up on to confirm product was accepted $submitFeedResult = $response->getSubmitFeedResult(); if ($submitFeedResult->isSetFeedSubmissionInfo()) { $feedSubmissionInfo = $submitFeedResult->getFeedSubmissionInfo(); if ($feedSubmissionInfo->isSetFeedSubmissionId()) { $submission_id = $feedSubmissionInfo->getFeedSubmissionId(); return $submission_id; } } return false; }